cloudstack_ruby_client 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/cloudstack_ruby_client/api/affinity_api.rb +11 -0
- data/lib/cloudstack_ruby_client/base_client.rb +2 -2
- data/lib/cloudstack_ruby_client/client.rb +30 -0
- data/lib/cloudstack_ruby_client/client_helper.rb +52 -39
- data/lib/cloudstack_ruby_client/version.rb +1 -1
- data/test/config.yml +3 -4
- data/test/unit/affinitygroup_test.rb +46 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGM0YWRiMDk2YWMyNmU5MTZmNDgyMjE1ZWU4Yzg3ZWY1Njk5MjA4Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWY4ODEzYjlkNTFjNmFlYWIyM2UwMDQyN2ViY2JkMGY4ZmQwYjZlZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWY5OWNmZWEwYmQ2MTFkNzI3MGZjYWU0MzBmMzIxNjM1ZDI5NWZiN2YwYWE2
|
10
|
+
YmM5NDk1ZDBlYzIwMGRiODBmMmE4NDM1MmFiMTE0YTU2OGEwMjY0ZmViMTBh
|
11
|
+
NmFhMzhhMmZiODFlZmJmZWM1MWQ0NDY3YjMxYWVlM2ZhY2Q5ODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmFhNDQ2MmE1NDQxZmNiZTkyNTNiMjI3OTVlODY2YWU2NWQ5YzM5YWM3MzE3
|
14
|
+
YTY2OTdhM2E1ZDA3NWVlMmNmOTNkMWNhZmI0MDJlOGI0ZTg2YzkxMzhhNjUz
|
15
|
+
NGMxMjU2YWE2MjRjMTA1ZWI4MTk2YTFiOGY1ODA0YmIyYjZmOTU=
|
@@ -20,8 +20,8 @@ class CloudstackRubyClient::BaseClient
|
|
20
20
|
url = "#{@api_url}?#{data}&signature=#{signature}"
|
21
21
|
uri = URI.parse(url)
|
22
22
|
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
-
|
24
|
-
|
23
|
+
http.use_ssl = @use_ssl
|
24
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
25
25
|
request = Net::HTTP::Get.new(uri.request_uri)
|
26
26
|
|
27
27
|
http.request(request)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
class CloudstackRubyClient::RequestError < RuntimeError
|
2
4
|
attr_reader :response, :json
|
3
5
|
|
@@ -34,6 +36,33 @@ class CloudstackRubyClient::Client < CloudstackRubyClient::BaseClient
|
|
34
36
|
def logout(params = {})
|
35
37
|
auth_request(params, "logout")
|
36
38
|
end
|
39
|
+
|
40
|
+
def wait_for_async_job(job, timeout=nil)
|
41
|
+
wait_time = 1
|
42
|
+
slept_time = 0
|
43
|
+
if job.has_key? 'jobid' then
|
44
|
+
job_id = job['jobid']
|
45
|
+
else
|
46
|
+
job_id = job
|
47
|
+
end
|
48
|
+
|
49
|
+
return Timeout::timeout(timeout) do
|
50
|
+
while true do
|
51
|
+
job_stat = self.query_async_job_result(:jobid => job_id)
|
52
|
+
if job_stat[:jobprocstatus] == 0 then #pending
|
53
|
+
sleep wait_time
|
54
|
+
slept_time += wait_time
|
55
|
+
if slept_time >= 30 then
|
56
|
+
wait_time = 5
|
57
|
+
elsif slept_time >= 10 then
|
58
|
+
wait_time = 2
|
59
|
+
end
|
60
|
+
else
|
61
|
+
return job_stat
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
37
66
|
|
38
67
|
protected
|
39
68
|
|
@@ -66,4 +95,5 @@ class CloudstackRubyClient::Client < CloudstackRubyClient::BaseClient
|
|
66
95
|
|
67
96
|
json[resp_title]
|
68
97
|
end
|
98
|
+
|
69
99
|
end
|
@@ -1,7 +1,36 @@
|
|
1
1
|
class Module
|
2
2
|
|
3
3
|
MALFORMED_CMDS = {
|
4
|
-
|
4
|
+
"getvmpassword" => 'getVMPassword',
|
5
|
+
"updatevmaffinitygroup" => "updateVMAffinityGroup",
|
6
|
+
"listneworkacls" => "listNetworkACLs",
|
7
|
+
"createneworkacl" => "createNetworkACL",
|
8
|
+
"deleteneworkacl" => "deleteNetworkACL",
|
9
|
+
"updateeneworkaclitem" => "updateNetworkACLItem",
|
10
|
+
"createnetworkacllist" => "createNetworkACLList",
|
11
|
+
"deleteNetworkacllist" => "deleteNetworkACLList",
|
12
|
+
"replacenetworkacllist" => "replaceNetworkACLList",
|
13
|
+
"listnetworkacllists" => "listNetworkACLLists",
|
14
|
+
"setsshkeyforvirtualmachine" => "setSSHKeyForVirtualMachine",
|
15
|
+
"registersshkeypair" => "registerSSHKeyPair",
|
16
|
+
"createsshkeypair" => "createSSHKeyPair",
|
17
|
+
"deletesshkeypair" => "deleteSSHKeyPair",
|
18
|
+
"listsshkeypairs" => "listSSHKeyPairs",
|
19
|
+
"createlbstickinesspolicy" => "createLBStickinessPolicy",
|
20
|
+
"deletelbstickinesspolicy" => "deleteLBStickinessPolicy",
|
21
|
+
"deletelbstickinesspolicy" => "deleteLBStickinessPolicy",
|
22
|
+
"listlbstickinesspolicies" => "listLBStickinessPolicies",
|
23
|
+
"listlbhealthcheckpolicies" => "listLBHealthCheckPolicies",
|
24
|
+
"createlbhealthcheckpolicy" => "createLBHealthCheckPolicy",
|
25
|
+
"deletelbhealthcheckpolicy" => "deleteLBHealthCheckPolicy",
|
26
|
+
"createvpc" => "createVPC",
|
27
|
+
"listvpcsdeletevpc" => "listVPCsdeleteVPC",
|
28
|
+
"updatevpc" => "updateVPC",
|
29
|
+
"restartvpc" => "restartVPC",
|
30
|
+
"createvpcoffering" => "createVPCOffering",
|
31
|
+
"updatevpcoffering" => "updateVPCOffering",
|
32
|
+
"deletevpcoffering" => "deleteVPCOffering",
|
33
|
+
"listvpcofferings" => "listVPCOfferings"
|
5
34
|
}
|
6
35
|
|
7
36
|
#
|
@@ -27,7 +56,8 @@ class Module
|
|
27
56
|
/copyiso/i => 'copytemplateresponse',
|
28
57
|
/deleteiso/i => 'deleteisosresponse',
|
29
58
|
/listisopermissions/i => 'listtemplatepermissionsresponse',
|
30
|
-
/addiptonic/i => 'addiptovmnicresponse'
|
59
|
+
/addiptonic/i => 'addiptovmnicresponse',
|
60
|
+
/updatevmaffinitygroup/i => 'updatevirtualmachineresponse'
|
31
61
|
}
|
32
62
|
|
33
63
|
def cmd_processor(*args)
|
@@ -36,61 +66,44 @@ class Module
|
|
36
66
|
meta_method = %Q{
|
37
67
|
def #{arg}(args={});
|
38
68
|
|
39
|
-
command = "#{
|
69
|
+
command = MALFORMED_CMDS.has_key?('#{arga.join('')}') ? MALFORMED_CMDS['#{arga.join('')}'] : "#{
|
40
70
|
arga.each_with_index.map {|x, i|
|
41
71
|
i==0 ? x : x.capitalize
|
42
72
|
}.join('')
|
43
|
-
}"
|
73
|
+
}";
|
44
74
|
|
45
|
-
resp_title = "#{arga.join('')}response"
|
75
|
+
resp_title = "#{arga.join('')}response";
|
46
76
|
} +
|
47
77
|
|
48
78
|
#
|
49
|
-
# The following code block is dealing with malformed
|
79
|
+
# The following code block is dealing with malformed response
|
50
80
|
#
|
51
81
|
|
52
82
|
%Q{
|
53
|
-
MALFORMED_RESPONSES.each do |k, v|
|
54
|
-
if k =~ command
|
55
|
-
resp_title = v
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
MALFORMED_CMDS.each do |k, v|
|
60
|
-
if k =~ command
|
61
|
-
command = v
|
62
|
-
end
|
63
|
-
end
|
64
83
|
|
65
|
-
|
66
|
-
command
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
command.gsub!(/ssh/i, 'SSH')
|
71
|
-
end
|
84
|
+
MALFORMED_RESPONSES.each do |k, v|;
|
85
|
+
if k =~ command;
|
86
|
+
resp_title = v;
|
87
|
+
end;
|
88
|
+
end;
|
72
89
|
|
73
|
-
if /(list|create|delete)lbstickinesspolic.*/i =~ command
|
74
|
-
command.gsub!(/lb/i, 'LB')
|
75
|
-
end
|
76
|
-
|
77
|
-
if /.*vpc.*/i =~ command
|
78
|
-
command.gsub!(/vpc/i, 'VPC')
|
79
|
-
end
|
80
90
|
} +
|
91
|
+
|
81
92
|
%Q{
|
82
|
-
params = {'command' => command}
|
83
|
-
params.merge!(args) unless args.empty
|
93
|
+
params = {'command' => command};
|
94
|
+
params.merge!(args) unless args.empty?;
|
84
95
|
|
85
|
-
response = request(params)
|
86
|
-
json = JSON.parse(response.body)
|
96
|
+
response = request(params);
|
97
|
+
json = JSON.parse(response.body);
|
87
98
|
|
88
99
|
if !response.is_a?(Net::HTTPOK)
|
89
|
-
if ["431","530"].include?(response.code) and
|
90
|
-
|
91
|
-
|
100
|
+
if ["431","530"].include?(response.code) and
|
101
|
+
["9999","4350"].include?(json[resp_title]['cserrorcode'].to_s);
|
102
|
+
|
103
|
+
raise ArgumentError, json[resp_title]['errortext'];
|
104
|
+
end;
|
92
105
|
|
93
|
-
raise RuntimeError, json['errorresponse']['errortext'] if response.code == "432"
|
106
|
+
raise RuntimeError, json['errorresponse']['errortext'] if response.code.to_s == "432"
|
94
107
|
|
95
108
|
raise CloudstackRubyClient::RequestError.new(response, json)
|
96
109
|
end
|
data/test/config.yml
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
cloudstack:
|
2
|
-
host: '10.1.192.
|
3
|
-
# host: 'localhost'
|
2
|
+
host: '10.1.192.54'
|
4
3
|
port: '8080'
|
5
4
|
admin_port: '8096'
|
6
|
-
api_key: '
|
7
|
-
secret_key: '
|
5
|
+
api_key: 'j88bUHw6zqG9Ch1RygIsqrwb4vs3PTBM3g-H7mxuY-Lk51cMHxM2c8PyaQELYbvnLqJg1uDeWABKPiPLAgG03g'
|
6
|
+
secret_key: 'TdMoVDOHsWofNjpmh4BacktKbRPn8CnjtG6cQLJ6B2ACD1-NXL6fK__yg2d2IAHwm___ogwc7nY2fbr-55fVDQ'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative '../../lib/cloudstack_ruby_client'
|
4
|
+
|
5
|
+
class AffinityGroupTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
config = YAML.load_file("test/config.yml")
|
8
|
+
_host = config['cloudstack']['host']
|
9
|
+
_port = config['cloudstack']['port']
|
10
|
+
_admin_port = config['cloudstack']['admin_port']
|
11
|
+
_api_key = config['cloudstack']['api_key']
|
12
|
+
_secret_key = config['cloudstack']['secret_key']
|
13
|
+
@client = CloudstackRubyClient::Client.new\
|
14
|
+
"http://#{_host}:#{_port}/client/api",
|
15
|
+
"#{_api_key}",
|
16
|
+
"#{_secret_key}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
# Do nothing here!
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_list_affinity_groups
|
24
|
+
@client.list_affinity_groups
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_list_affinity_group_types
|
28
|
+
@client.list_affinity_group_types
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_affinity_group
|
32
|
+
assert_raise(ArgumentError) do
|
33
|
+
@client.create_affinity_group
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_update_vm_affinity_group
|
38
|
+
assert_raise(ArgumentError) do
|
39
|
+
@client.update_vm_affinity_group
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_delete_affinity_group
|
44
|
+
@client.delete_affinity_group
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack_ruby_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chip Childers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby client for CloudStack's API, including a simple CLI.
|
14
14
|
email:
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/cloudstack_ruby_client.rb
|
30
30
|
- lib/cloudstack_ruby_client/api/accounts_api.rb
|
31
31
|
- lib/cloudstack_ruby_client/api/address_api.rb
|
32
|
+
- lib/cloudstack_ruby_client/api/affinity_api.rb
|
32
33
|
- lib/cloudstack_ruby_client/api/alert_api.rb
|
33
34
|
- lib/cloudstack_ruby_client/api/apidiscovery_api.rb
|
34
35
|
- lib/cloudstack_ruby_client/api/asyncjob_api.rb
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- test/config.yml
|
68
69
|
- test/integration/client_test.rb
|
69
70
|
- test/unit/accounts_test.rb
|
71
|
+
- test/unit/affinitygroup_test.rb
|
70
72
|
- test/unit/asyncjob_test.rb
|
71
73
|
- test/unit/autoscale_test.rb
|
72
74
|
- test/unit/configuration_test.rb
|
@@ -101,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version: '0'
|
102
104
|
requirements: []
|
103
105
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.2.2
|
105
107
|
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: A Ruby client for CloudStack's API.
|
@@ -109,6 +111,7 @@ test_files:
|
|
109
111
|
- test/config.yml
|
110
112
|
- test/integration/client_test.rb
|
111
113
|
- test/unit/accounts_test.rb
|
114
|
+
- test/unit/affinitygroup_test.rb
|
112
115
|
- test/unit/asyncjob_test.rb
|
113
116
|
- test/unit/autoscale_test.rb
|
114
117
|
- test/unit/configuration_test.rb
|