cloudstack_client 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cs-command-generator +5 -0
- data/cloudstack_client.gemspec +1 -0
- data/lib/cloudstack_client/client.rb +13 -8
- data/lib/cloudstack_client/command_generator.rb +75 -0
- data/lib/cloudstack_client/commands/server.rb +4 -4
- data/lib/cloudstack_client/version.rb +1 -1
- data/lib/connection_helper.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4ef1b1f29fe2b33c07e850d1c0c544342c39fd
|
4
|
+
data.tar.gz: 5b1b396af2c56a4cb2da5ce4c404c767b77d8019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c80db1a47d4922a35fe90c8cdde8e5588c08241b76353202a0bb1e17d986c11fe569387f44c2f830dd62e759ac6a97fe4a0baa1b82cb7fc02e96e52bef70a7bb
|
7
|
+
data.tar.gz: 83bf27b68b50687c04d09467041898a2bb4069268a136146ed6697bff0bfa05da5b5e1aa5b30a033f85e97ef0e8a42a7ad417c7c2cfdd0cd5b5254b74f8526b3
|
data/cloudstack_client.gemspec
CHANGED
@@ -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])
|
@@ -335,15 +336,14 @@ module CloudstackClient
|
|
335
336
|
# Destroy the server with the specified name.
|
336
337
|
#
|
337
338
|
|
338
|
-
def destroy_server(id,
|
339
|
+
def destroy_server(id, async = true)
|
339
340
|
params = {
|
340
341
|
'command' => 'destroyVirtualMachine',
|
341
342
|
'id' => id
|
342
343
|
}
|
343
|
-
params['
|
344
|
-
args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
|
344
|
+
async ? send_async_request(params)['virtualmachine'] : send_request(params)
|
345
345
|
end
|
346
346
|
|
347
347
|
end
|
348
348
|
|
349
|
-
end
|
349
|
+
end
|
data/lib/connection_helper.rb
CHANGED
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
|
+
version: 0.6.1
|
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-
|
11
|
+
date: 2014-05-07 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
|
@@ -110,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
126
|
version: '0'
|
111
127
|
requirements: []
|
112
128
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.0.3
|
114
130
|
signing_key:
|
115
131
|
specification_version: 4
|
116
132
|
summary: CloudStack API client written in Ruby
|