cloudstack_client 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cloudstack_client.gemspec +0 -1
- data/lib/cloudstack_client/client.rb +8 -13
- data/lib/cloudstack_client/commands/server.rb +11 -13
- data/lib/cloudstack_client/commands/system_vm.rb +1 -1
- data/lib/cloudstack_client/version.rb +1 -1
- data/lib/connection_helper.rb +1 -1
- metadata +1 -17
- data/bin/cs-command-generator +0 -5
- data/lib/cloudstack_client/command_generator.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6572f2978a68ebcb38a986ac7488dc6ba8e59c
|
4
|
+
data.tar.gz: dd0d4dc3bc194ca89b6a40b664f3c3d404c5e72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3464332207e5b38f71113a0f733580125a4bf59c39a9a237e50a61b16ebdd9f7bc0d14015b7656a3e98bb4c5cb97d7cc2bafd4d014f10a5b1f1a3c6bd0eedfe6
|
7
|
+
data.tar.gz: 9189e7543dd3e651783c0cac743cb2e673e6ee2edb9f8d6474198fa9e5b68c7658809c4f6583008829b00a6688d10538bf36c6700a069a882499d8946d901a3d
|
data/cloudstack_client.gemspec
CHANGED
@@ -13,6 +13,13 @@ 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
|
+
|
16
23
|
attr_accessor :verbose
|
17
24
|
|
18
25
|
def initialize(api_url, api_key, secret_key, opts = {})
|
@@ -21,19 +28,6 @@ module CloudstackClient
|
|
21
28
|
@secret_key = secret_key
|
22
29
|
@verbose = opts[:quiet] ? false : true
|
23
30
|
@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
|
37
31
|
end
|
38
32
|
|
39
33
|
##
|
@@ -76,6 +70,7 @@ module CloudstackClient
|
|
76
70
|
exit 1
|
77
71
|
end
|
78
72
|
|
73
|
+
|
79
74
|
if response.is_a? Net::HTTPOK
|
80
75
|
begin
|
81
76
|
json = JSON.parse(response.body)
|
@@ -119,7 +119,6 @@ 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]
|
123
122
|
|
124
123
|
if args[:zone]
|
125
124
|
zone = get_zone(args[:zone])
|
@@ -190,9 +189,7 @@ module CloudstackClient
|
|
190
189
|
params['name'] = args[:name] if args[:name]
|
191
190
|
|
192
191
|
if args[:name]
|
193
|
-
server = params['projectid']
|
194
|
-
get_server(args[:name], project_id: params['projectid']) :
|
195
|
-
get_server(args[:name])
|
192
|
+
server = get_server(args[:name], project_id: params['projectid'])
|
196
193
|
if server
|
197
194
|
puts "Error: Server '#{args[:name]}' already exists."
|
198
195
|
exit 1
|
@@ -202,7 +199,7 @@ module CloudstackClient
|
|
202
199
|
networks = []
|
203
200
|
if args[:networks]
|
204
201
|
args[:networks].each do |name|
|
205
|
-
network =
|
202
|
+
network = get_network(name, params['projectid'])
|
206
203
|
if !network
|
207
204
|
puts "Error: Network '#{name}' not found"
|
208
205
|
exit 1
|
@@ -211,11 +208,11 @@ module CloudstackClient
|
|
211
208
|
end
|
212
209
|
end
|
213
210
|
if networks.empty?
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
211
|
+
unless default_network = get_default_network
|
212
|
+
puts "Error: No default network found"
|
213
|
+
exit 1
|
214
|
+
end
|
215
|
+
networks << default_network
|
219
216
|
end
|
220
217
|
network_ids = networks.map { |network|
|
221
218
|
network['id']
|
@@ -336,14 +333,15 @@ module CloudstackClient
|
|
336
333
|
# Destroy the server with the specified name.
|
337
334
|
#
|
338
335
|
|
339
|
-
def destroy_server(id,
|
336
|
+
def destroy_server(id, args = {})
|
340
337
|
params = {
|
341
338
|
'command' => 'destroyVirtualMachine',
|
342
339
|
'id' => id
|
343
340
|
}
|
344
|
-
|
341
|
+
params['expunge'] = true if args[:expunge]
|
342
|
+
args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
|
345
343
|
end
|
346
344
|
|
347
345
|
end
|
348
346
|
|
349
|
-
end
|
347
|
+
end
|
data/lib/connection_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nik Wolfgramm
|
@@ -44,20 +44,6 @@ 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'
|
61
47
|
description: CloudStack API client written in Ruby
|
62
48
|
email:
|
63
49
|
- nik.wolfgramm@gmail.com
|
@@ -70,11 +56,9 @@ files:
|
|
70
56
|
- LICENSE.txt
|
71
57
|
- README.md
|
72
58
|
- Rakefile
|
73
|
-
- bin/cs-command-generator
|
74
59
|
- cloudstack_client.gemspec
|
75
60
|
- lib/cloudstack_client.rb
|
76
61
|
- lib/cloudstack_client/client.rb
|
77
|
-
- lib/cloudstack_client/command_generator.rb
|
78
62
|
- lib/cloudstack_client/commands/account.rb
|
79
63
|
- lib/cloudstack_client/commands/affinity_group.rb
|
80
64
|
- lib/cloudstack_client/commands/capacity.rb
|
data/bin/cs-command-generator
DELETED
@@ -1,75 +0,0 @@
|
|
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
|