cloudstack_client 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea9000179c05b3b2b5b8a874b69584b77eb7177
4
- data.tar.gz: c891843c2401add5d1a51f2d667426d4eb5785c0
3
+ metadata.gz: 3620aef025ca6411c6be895ed5db20685c82a468
4
+ data.tar.gz: a88760e188e72a8baf9f896a8e2089ff0cc34520
5
5
  SHA512:
6
- metadata.gz: 92c715f4af3ea491f448176f6c26eb72ac3132ce01bdf6c7f8e16a4f95bb872c707a3f6b0a84f10512d4bbb168467faed26d10bb0c345c7a2dcc956cb0b2150f
7
- data.tar.gz: d0682349d967f461cdfa5380a7e135702d87f532563fcd942f10e4a4ec43a82000025e228049d19cc099753bf18955aad1a771b5e3010369ac64e04544ec7739
6
+ metadata.gz: 5c036f121986e4e52d57d0208ea4714d3a367addcfe50787afb2b733b9b53e436b2b208efca346d7f84f2c428c0a72a705a9fe60cf3fc605a3a98758cb031783
7
+ data.tar.gz: 43cee73391258a369a9f10e0b26f4f7ed19d6db5f04a3eea38e714e37c94c5603ab3fbc36d129d5e8719ea3755fb017540a114779feb3aaa9653bf6f1e1c242b
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cloudstack_client/command_generator'
4
+
5
+ CloudstackClient::CommandGenerator.start
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency('rdoc')
23
23
  gem.add_development_dependency('rake', '~> 10.0', '>= 10.0.4')
24
+ gem.add_development_dependency('thor')
24
25
  end
@@ -13,13 +13,6 @@ module CloudstackClient
13
13
  @@async_poll_interval = 2.0
14
14
  @@async_timeout = 400
15
15
 
16
- # include all commands
17
- Dir.glob(File.dirname(__FILE__) + "/commands/*.rb").each do |file|
18
- require file
19
- module_name = File.basename(file, '.rb').split('_').map{|f| f.capitalize}.join
20
- include Object.const_get("CloudstackClient").const_get(module_name)
21
- end
22
-
23
16
  attr_accessor :verbose
24
17
 
25
18
  def initialize(api_url, api_key, secret_key, opts = {})
@@ -28,6 +21,19 @@ module CloudstackClient
28
21
  @secret_key = secret_key
29
22
  @verbose = opts[:quiet] ? false : true
30
23
  @debug = opts[:debug] ? true : false
24
+ CloudstackClient::Connection.include_commands unless opts[:no_commands]
25
+ end
26
+
27
+ ##
28
+ # Loads all commands from the commands subdirectory and includes them
29
+ #
30
+
31
+ def self.include_commands
32
+ Dir.glob(File.dirname(__FILE__) + "/commands/*.rb").each do |file|
33
+ require file
34
+ module_name = File.basename(file, '.rb').split('_').map{|f| f.capitalize}.join
35
+ include Object.const_get("CloudstackClient").const_get(module_name)
36
+ end
31
37
  end
32
38
 
33
39
  ##
@@ -70,7 +76,6 @@ module CloudstackClient
70
76
  exit 1
71
77
  end
72
78
 
73
-
74
79
  if response.is_a? Net::HTTPOK
75
80
  begin
76
81
  json = JSON.parse(response.body)
@@ -0,0 +1,75 @@
1
+ require 'cloudstack_client/client'
2
+ require 'connection_helper'
3
+ require 'thor'
4
+ require 'yaml'
5
+
6
+ module CloudstackClient
7
+ class CommandGenerator < Thor
8
+ include Thor::Actions
9
+
10
+ class_option :config_file,
11
+ default: File.join(Dir.home, '.cloudstack-cli.yml'),
12
+ aliases: '-c',
13
+ desc: 'location of your cloudstack-cli configuration file'
14
+
15
+ class_option :env,
16
+ aliases: '-e',
17
+ desc: 'environment to use'
18
+
19
+ class_option :debug,
20
+ desc: 'enable debug output',
21
+ type: :boolean
22
+
23
+ desc "generate", "generate api commands using the Cloudstack API Discovery service"
24
+ def generate
25
+ json = client.send_request('command' => 'listApis')
26
+ commands = json['api'] || []
27
+ commands.each do |command|
28
+ puts "#{command['name']} : #{command['related']}"
29
+ end
30
+ end
31
+
32
+ no_commands do
33
+ def client(opts = {})
34
+ @config ||= load_configuration
35
+ @client ||= CloudstackClient::Connection.new(
36
+ @config[:url],
37
+ @config[:api_key],
38
+ @config[:secret_key],
39
+ {no_commands: true}
40
+ )
41
+ end
42
+
43
+ def load_configuration(config_file = options[:config_file], env = options[:env])
44
+ unless File.exists?(config_file)
45
+ say "Configuration file #{config_file} not found.", :red
46
+ say "Please run \'cs environment add\' to create one."
47
+ exit 1
48
+ end
49
+
50
+ begin
51
+ config = YAML::load(IO.read(config_file))
52
+ rescue
53
+ say "Can't load configuration from file #{config_file}.", :red
54
+ exit 1
55
+ end
56
+
57
+ env ||= config[:default]
58
+ if env
59
+ unless config = config[env]
60
+ say "Can't find environment #{env}.", :red
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ unless config.key?(:url) && config.key?(:api_key) && config.key?(:secret_key)
66
+ say "The environment #{env || '\'-\''} contains no valid data.", :red
67
+ exit 1
68
+ end
69
+ config
70
+ end
71
+
72
+ end # no_commands
73
+
74
+ end # class
75
+ end # module
@@ -119,6 +119,7 @@ module CloudstackClient
119
119
  params['state'] = args[:state] if args[:state]
120
120
  params['state'] = args[:status] if args[:status]
121
121
  params['groupid'] = args[:group_id] if args[:group_id]
122
+ params['keyword'] = args[:keyword] if args[:keyword]
122
123
 
123
124
  if args[:zone]
124
125
  zone = get_zone(args[:zone])
@@ -189,7 +190,9 @@ module CloudstackClient
189
190
  params['name'] = args[:name] if args[:name]
190
191
 
191
192
  if args[:name]
192
- server = get_server(args[:name], project_id: params['projectid'])
193
+ server = params['projectid'] ?
194
+ get_server(args[:name], project_id: params['projectid']) :
195
+ get_server(args[:name])
193
196
  if server
194
197
  puts "Error: Server '#{args[:name]}' already exists."
195
198
  exit 1
@@ -199,7 +202,7 @@ module CloudstackClient
199
202
  networks = []
200
203
  if args[:networks]
201
204
  args[:networks].each do |name|
202
- network = get_network(name, params['projectid'])
205
+ network = defined?(project) ? get_network(name, project['id']) : get_network(name)
203
206
  if !network
204
207
  puts "Error: Network '#{name}' not found"
205
208
  exit 1
@@ -208,11 +211,11 @@ module CloudstackClient
208
211
  end
209
212
  end
210
213
  if networks.empty?
211
- unless default_network = get_default_network
212
- puts "Error: No default network found"
213
- exit 1
214
- end
215
- networks << default_network
214
+ networks << get_default_network
215
+ end
216
+ if networks.empty?
217
+ puts "No default network found"
218
+ exit 1
216
219
  end
217
220
  network_ids = networks.map { |network|
218
221
  network['id']
@@ -333,15 +336,14 @@ module CloudstackClient
333
336
  # Destroy the server with the specified name.
334
337
  #
335
338
 
336
- def destroy_server(id, args = {})
339
+ def destroy_server(id, async = true)
337
340
  params = {
338
341
  'command' => 'destroyVirtualMachine',
339
342
  'id' => id
340
343
  }
341
- params['expunge'] = true if args[:expunge]
342
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
344
+ async ? send_async_request(params)['virtualmachine'] : send_request(params)
343
345
  end
344
346
 
345
347
  end
346
348
 
347
- end
349
+ end
@@ -0,0 +1,31 @@
1
+ module CloudstackClient
2
+
3
+ module SystemVm
4
+
5
+ ##
6
+ # List system virtual machines.
7
+
8
+ def list_system_vms(args = {})
9
+ params = {
10
+ 'command' => 'listSystemVms'
11
+ }
12
+
13
+ if args[:zone]
14
+ zone = get_zone(args[:zone])
15
+ unless zone
16
+ puts "Error: zone #{args[:project]} not found."
17
+ exit 1
18
+ end
19
+ params['zoneid'] = zone['id']
20
+ end
21
+
22
+ params['state'] = args[:state] if args[:state]
23
+ params['podid'] = args[:podid] if args[:podid]
24
+
25
+ json = send_request(params)
26
+ json['system_vm'] || []
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "0.6.4"
3
- end
2
+ VERSION = "0.7.0"
3
+ end
@@ -3,7 +3,7 @@ module CloudstackClient
3
3
  def self.load_configuration(config_file)
4
4
  begin
5
5
  return YAML::load(IO.read(config_file))
6
- rescue Exception => e
6
+ rescue => e
7
7
  puts "Unable to load '#{config_file}' : #{e}"
8
8
  exit
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-29 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 10.0.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: thor
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  description: CloudStack API client written in Ruby
48
62
  email:
49
63
  - nik.wolfgramm@gmail.com
@@ -56,9 +70,11 @@ files:
56
70
  - LICENSE.txt
57
71
  - README.md
58
72
  - Rakefile
73
+ - bin/cs-command-generator
59
74
  - cloudstack_client.gemspec
60
75
  - lib/cloudstack_client.rb
61
76
  - lib/cloudstack_client/client.rb
77
+ - lib/cloudstack_client/command_generator.rb
62
78
  - lib/cloudstack_client/commands/account.rb
63
79
  - lib/cloudstack_client/commands/affinity_group.rb
64
80
  - lib/cloudstack_client/commands/capacity.rb
@@ -82,6 +98,7 @@ files:
82
98
  - lib/cloudstack_client/commands/snapshot.rb
83
99
  - lib/cloudstack_client/commands/ssh_key_pair.rb
84
100
  - lib/cloudstack_client/commands/storage_pool.rb
101
+ - lib/cloudstack_client/commands/system_vm.rb
85
102
  - lib/cloudstack_client/commands/template.rb
86
103
  - lib/cloudstack_client/commands/user.rb
87
104
  - lib/cloudstack_client/commands/volume.rb
@@ -110,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
127
  version: '0'
111
128
  requirements: []
112
129
  rubyforge_project:
113
- rubygems_version: 2.2.0
130
+ rubygems_version: 2.0.3
114
131
  signing_key:
115
132
  specification_version: 4
116
133
  summary: CloudStack API client written in Ruby