Skip to content

Commit

Permalink
Add affinity group commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Chiang committed Nov 19, 2013
1 parent 38ce0d0 commit ca057ab
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 19 deletions.
11 changes: 11 additions & 0 deletions lib/cloudstack_ruby_client/api/affinity_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module CloudstackRubyClient
module Api
module AffinityGroup
cmd_processor :list_affinity_groups,
:list_affinity_group_types,
:create_affinity_group,
:delete_affinity_group,
:update_vm_affinity_group
end
end
end
32 changes: 17 additions & 15 deletions lib/cloudstack_ruby_client/client_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Module

MALFORMED_CMDS = {
/getvmpassword/i => 'getVMPassword'
"getvmpassword" => 'getVMPassword',
"updatevmaffinitygroup" => "updateVMAffinityGroup"
}

#
Expand All @@ -27,7 +28,8 @@ class Module
/copyiso/i => 'copytemplateresponse',
/deleteiso/i => 'deleteisosresponse',
/listisopermissions/i => 'listtemplatepermissionsresponse',
/addiptonic/i => 'addiptovmnicresponse'
/addiptonic/i => 'addiptovmnicresponse',
/updatevmaffinitygroup/i => 'updatevirtualmachineresponse'
}

def cmd_processor(*args)
Expand Down Expand Up @@ -56,11 +58,9 @@ def #{arg}(args={});
end
end
MALFORMED_CMDS.each do |k, v|
if k =~ command
command = v
end
end
if MALFORMED_CMDS.has_key?(command.downcase);
command = MALFORMED_CMDS[command.downcase];
end;
if /(list|create|delete)networkacl.*/i =~ command
command.gsub!(/acl/i, 'ACL')
Expand All @@ -79,18 +79,20 @@ def #{arg}(args={});
end
} +
%Q{
params = {'command' => command}
params.merge!(args) unless args.empty?
params = {'command' => command};
params.merge!(args) unless args.empty?;
response = request(params)
json = JSON.parse(response.body)
response = request(params);
json = JSON.parse(response.body);
if !response.is_a?(Net::HTTPOK)
if ["431","530"].include?(response.code) and ["9999","4350"].include?(json[resp_title]['cserrorcode'])
raise ArgumentError, json[resp_title]['errortext']
end
if ["431","530"].include?(response.code) and
["9999","4350"].include?(json[resp_title]['cserrorcode'].to_s);
raise ArgumentError, json[resp_title]['errortext'];
end;
raise RuntimeError, json['errorresponse']['errortext'] if response.code == "432"
raise RuntimeError, json['errorresponse']['errortext'] if response.code.to_s == "432"
raise CloudstackRubyClient::RequestError.new(response, json)
end
Expand Down
7 changes: 3 additions & 4 deletions test/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cloudstack:
host: '10.1.192.92'
# host: 'localhost'
host: '10.1.192.54'
port: '8080'
admin_port: '8096'
api_key: 'd460dbswlC6ApcirESZJOh-JDCFxCtwtmoRd_FHC9QYwHNkeHi1BjdDrvnfQQ0vwDOC9t4yPF46o5Kfpn5eFVg'
secret_key: 'sZchCmafeZU4ZKM2HkX5DzcoWFWAYp3eGIpYFdgsCoYtZiTIuXIgv48Ja5vD1sdkf_gFFbh534hepPayEfcfNQ'
api_key: 'j88bUHw6zqG9Ch1RygIsqrwb4vs3PTBM3g-H7mxuY-Lk51cMHxM2c8PyaQELYbvnLqJg1uDeWABKPiPLAgG03g'
secret_key: 'TdMoVDOHsWofNjpmh4BacktKbRPn8CnjtG6cQLJ6B2ACD1-NXL6fK__yg2d2IAHwm___ogwc7nY2fbr-55fVDQ'
46 changes: 46 additions & 0 deletions test/unit/affinitygroup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'test/unit'
require 'yaml'
require_relative '../../lib/cloudstack_ruby_client'

class AffinityGroupTest < Test::Unit::TestCase
def setup
config = YAML.load_file("test/config.yml")
_host = config['cloudstack']['host']
_port = config['cloudstack']['port']
_admin_port = config['cloudstack']['admin_port']
_api_key = config['cloudstack']['api_key']
_secret_key = config['cloudstack']['secret_key']
@client = CloudstackRubyClient::Client.new\
"http://#{_host}:#{_port}/client/api",
"#{_api_key}",
"#{_secret_key}"
end

def teardown
# Do nothing here!
end

def test_list_affinity_groups
@client.list_affinity_groups
end

def test_list_affinity_group_types
@client.list_affinity_group_types
end

def test_create_affinity_group
assert_raise(ArgumentError) do
@client.create_affinity_group
end
end

def test_update_vm_affinity_group
assert_raise(ArgumentError) do
@client.update_vm_affinity_group
end
end

def test_delete_affinity_group
@client.delete_affinity_group
end
end

0 comments on commit ca057ab

Please sign in to comment.