cloudstack_client 0.2.10
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +26 -0
- data/cloudstack_client.gemspec +24 -0
- data/lib/cloudstack_client.rb +2 -0
- data/lib/cloudstack_client/client.rb +136 -0
- data/lib/cloudstack_client/commands/account.rb +22 -0
- data/lib/cloudstack_client/commands/capacity.rb +19 -0
- data/lib/cloudstack_client/commands/cluster.rb +19 -0
- data/lib/cloudstack_client/commands/disk_offering.rb +49 -0
- data/lib/cloudstack_client/commands/domain.rb +22 -0
- data/lib/cloudstack_client/commands/host.rb +28 -0
- data/lib/cloudstack_client/commands/ip_address.rb +82 -0
- data/lib/cloudstack_client/commands/iso.rb +64 -0
- data/lib/cloudstack_client/commands/job.rb +29 -0
- data/lib/cloudstack_client/commands/load_balancer_rule.rb +61 -0
- data/lib/cloudstack_client/commands/network.rb +128 -0
- data/lib/cloudstack_client/commands/pod.rb +19 -0
- data/lib/cloudstack_client/commands/port_forwarding_rule.rb +49 -0
- data/lib/cloudstack_client/commands/project.rb +32 -0
- data/lib/cloudstack_client/commands/router.rb +89 -0
- data/lib/cloudstack_client/commands/server.rb +311 -0
- data/lib/cloudstack_client/commands/service_offering.rb +98 -0
- data/lib/cloudstack_client/commands/snapshot.rb +40 -0
- data/lib/cloudstack_client/commands/ssh_key_pair.rb +106 -0
- data/lib/cloudstack_client/commands/template.rb +60 -0
- data/lib/cloudstack_client/commands/user.rb +32 -0
- data/lib/cloudstack_client/commands/volume.rb +20 -0
- data/lib/cloudstack_client/commands/zone.rb +57 -0
- data/lib/cloudstack_client/version.rb +3 -0
- data/lib/connection_helper.rb +12 -0
- metadata +106 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Iso
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lists all isos that match the specified filter.
|
7
|
+
#
|
8
|
+
# Allowable filter values are:
|
9
|
+
#
|
10
|
+
# * featured - isos that are featured and are public
|
11
|
+
# * self - isos that have been registered/created by the owner
|
12
|
+
# * self-executable - isos that have been registered/created by the owner that can be used to deploy a new VM
|
13
|
+
# * executable - all isos that can be used to deploy a new VM
|
14
|
+
# * community - isos that are public
|
15
|
+
|
16
|
+
def list_isos(args = {})
|
17
|
+
filter = args[:filter] || 'featured'
|
18
|
+
params = {
|
19
|
+
'command' => 'listIsos',
|
20
|
+
'isofilter' => filter
|
21
|
+
}
|
22
|
+
params['projectid'] = args[:project_id] if args[:project_id]
|
23
|
+
params['zoneid'] = args[:zone_id] if args[:zone_id]
|
24
|
+
if args[:listall]
|
25
|
+
params['listall'] = true
|
26
|
+
params['isrecursive'] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
json = send_request(params)
|
30
|
+
json['iso'] || []
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Finds the template with the specified name.
|
35
|
+
|
36
|
+
def get_iso(name)
|
37
|
+
|
38
|
+
# TODO: use name parameter
|
39
|
+
# listIsos in CloudStack 2.2 doesn't seem to work
|
40
|
+
# when the name parameter is specified. When this is fixed,
|
41
|
+
# the name parameter should be added to the request.
|
42
|
+
params = {
|
43
|
+
'command' => 'listIsos',
|
44
|
+
'isoFilter' => 'executable'
|
45
|
+
}
|
46
|
+
json = send_request(params)
|
47
|
+
|
48
|
+
isos = json['iso']
|
49
|
+
if !isos then
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
isos.each { |t|
|
54
|
+
if t['name'] == name then
|
55
|
+
return t
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Job
|
4
|
+
|
5
|
+
##
|
6
|
+
# Retrieves the current status of asynchronous job.
|
7
|
+
|
8
|
+
def query_job(id)
|
9
|
+
params = {
|
10
|
+
'command' => 'queryAsyncJobResult',
|
11
|
+
'jobid' => id,
|
12
|
+
}
|
13
|
+
send_request(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Lists all pending asynchronous jobs for the account.
|
18
|
+
|
19
|
+
def list_jobs(opts = {})
|
20
|
+
params = {
|
21
|
+
'command' => 'listAsyncJobs'
|
22
|
+
}
|
23
|
+
params['listall'] = true if opts[:listall]
|
24
|
+
send_request(params)['asyncjobs']
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module LoadBalancerRule
|
4
|
+
|
5
|
+
##
|
6
|
+
# List loadbalancer rules
|
7
|
+
|
8
|
+
def list_load_balancer_rules(options = {})
|
9
|
+
params = {
|
10
|
+
'command' => 'listLoadBalancerRules',
|
11
|
+
}
|
12
|
+
params['name'] = options[:name] if options[:name]
|
13
|
+
|
14
|
+
if options[:project_name]
|
15
|
+
project = get_project(options[:project_name])
|
16
|
+
params['projectid'] = project['id']
|
17
|
+
end
|
18
|
+
|
19
|
+
json = send_request(params)
|
20
|
+
json['loadbalancerrule'] || []
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates a load balancing rule.
|
25
|
+
|
26
|
+
def create_load_balancer_rule(name, publicip, private_port, public_port, options = {})
|
27
|
+
params = {
|
28
|
+
'command' => 'createLoadBalancerRule',
|
29
|
+
'name' => name,
|
30
|
+
'privateport' => private_port,
|
31
|
+
'publicport' => public_port,
|
32
|
+
'publicipid' => get_public_ip_address(publicip)['id']
|
33
|
+
}
|
34
|
+
params['algorithm'] = options[:algorithm] || 'roundrobin'
|
35
|
+
params['openfirewall'] = options[:openfirewall] || true
|
36
|
+
|
37
|
+
json = send_async_request(params)
|
38
|
+
json['LoadBalancerRule']
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Assigns virtual machine or a list of virtual machines to a load balancer rule.
|
43
|
+
|
44
|
+
def assign_to_load_balancer_rule(name, vm_names)
|
45
|
+
id = list_load_balancer_rules(name).first['id']
|
46
|
+
|
47
|
+
vm_ids = vm_names.map do |vm|
|
48
|
+
get_server(vm)['id']
|
49
|
+
end
|
50
|
+
|
51
|
+
params = {
|
52
|
+
'command' => 'assignToLoadBalancerRule',
|
53
|
+
'id' => id,
|
54
|
+
'virtualmachineids' => vm_ids.join(',')
|
55
|
+
}
|
56
|
+
json = send_async_request(params)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Network
|
4
|
+
|
5
|
+
##
|
6
|
+
# Finds the network with the specified name.
|
7
|
+
|
8
|
+
def networkid_to_name(id, project_id=nil)
|
9
|
+
params = {
|
10
|
+
'command' => 'listNetworks',
|
11
|
+
'id' => id
|
12
|
+
}
|
13
|
+
params['projectid'] = project_id if project_id
|
14
|
+
json = send_request(params)
|
15
|
+
|
16
|
+
json['network'] ? json['network'].first['name'] : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Finds the network with the specified name.
|
21
|
+
|
22
|
+
def get_network(name, project_id = nil)
|
23
|
+
params = {
|
24
|
+
'command' => 'listNetworks',
|
25
|
+
'listall' => true
|
26
|
+
}
|
27
|
+
params['projectid'] = project_id if project_id
|
28
|
+
json = send_request(params)
|
29
|
+
|
30
|
+
networks = json['network']
|
31
|
+
return nil unless networks
|
32
|
+
|
33
|
+
networks.each { |n|
|
34
|
+
if n['name'] == name then
|
35
|
+
return n
|
36
|
+
end
|
37
|
+
}
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Finds the default network.
|
43
|
+
|
44
|
+
def get_default_network(zone = nil)
|
45
|
+
params = {
|
46
|
+
'command' => 'listNetworks',
|
47
|
+
'isDefault' => true
|
48
|
+
}
|
49
|
+
if zone
|
50
|
+
params['zoneid'] = get_zone(zone)['id']
|
51
|
+
end
|
52
|
+
json = send_request(params)
|
53
|
+
|
54
|
+
networks = json['network']
|
55
|
+
return nil if !networks || networks.empty?
|
56
|
+
return networks.first if networks.length == 1
|
57
|
+
|
58
|
+
networks.each { |n|
|
59
|
+
if n['type'] == 'Direct' then
|
60
|
+
return n
|
61
|
+
end
|
62
|
+
}
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Lists all available networks.
|
68
|
+
|
69
|
+
def list_networks(args = {})
|
70
|
+
params = {
|
71
|
+
'command' => 'listNetworks',
|
72
|
+
'listall' => true,
|
73
|
+
}
|
74
|
+
params['projectid'] = args[:project_id] if args[:project_id]
|
75
|
+
params['zoneid'] = args[:zone_id] if args[:zone_id]
|
76
|
+
params['isDefault'] = true if args[:isdefault]
|
77
|
+
if args[:account]
|
78
|
+
domain = list_accounts(name: args[:account])
|
79
|
+
if domain.size > 0
|
80
|
+
params['account'] = args[:account]
|
81
|
+
params['domainid'] = domain.first["domainid"]
|
82
|
+
else
|
83
|
+
puts "Account #{args[:account]} not found."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
json = send_request(params)
|
87
|
+
json['network'] || []
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Delete network.
|
92
|
+
|
93
|
+
def delete_network(id)
|
94
|
+
params = {
|
95
|
+
'command' => 'deleteNetwork',
|
96
|
+
'id' => id,
|
97
|
+
}
|
98
|
+
p json = send_async_request(params)
|
99
|
+
json['network']
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Restart network.
|
104
|
+
|
105
|
+
def restart_network(id, cleanup = false)
|
106
|
+
params = {
|
107
|
+
'command' => 'restartNetwork',
|
108
|
+
'id' => id,
|
109
|
+
'cleanup' => cleanup,
|
110
|
+
}
|
111
|
+
p json = send_async_request(params)
|
112
|
+
json['network']
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Lists all physical networks.
|
117
|
+
|
118
|
+
def list_physical_networks
|
119
|
+
params = {
|
120
|
+
'command' => 'listPhysicalNetworks',
|
121
|
+
}
|
122
|
+
json = send_request(params)
|
123
|
+
json['physicalnetwork'] || []
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module PortForwardingRule
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lists all port forwarding rules.
|
7
|
+
|
8
|
+
def list_port_forwarding_rules(ip_address_id=nil, project_id)
|
9
|
+
params = {
|
10
|
+
'command' => 'listPortForwardingRules',
|
11
|
+
'listall' => true,
|
12
|
+
'isrecursive' => true
|
13
|
+
}
|
14
|
+
params['ipAddressId'] = ip_address_id if ip_address_id
|
15
|
+
params['projectid'] = project_id if project_id
|
16
|
+
json = send_request(params)
|
17
|
+
json['portforwardingrule'] || []
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Gets the SSH port forwarding rule for the specified server.
|
22
|
+
|
23
|
+
def get_ssh_port_forwarding_rule(server, cached_rules=nil)
|
24
|
+
rules = cached_rules || list_port_forwarding_rules || []
|
25
|
+
rules.find_all { |r|
|
26
|
+
r['virtualmachineid'] == server['id'] &&
|
27
|
+
r['privateport'] == '22'&&
|
28
|
+
r['publicport'] == '22'
|
29
|
+
}.first
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Creates a port forwarding rule.
|
34
|
+
|
35
|
+
def create_port_forwarding_rule(ip_address_id, private_port, protocol, public_port, virtual_machine_id, async = true)
|
36
|
+
params = {
|
37
|
+
'command' => 'createPortForwardingRule',
|
38
|
+
'ipAddressId' => ip_address_id,
|
39
|
+
'privatePort' => private_port,
|
40
|
+
'protocol' => protocol,
|
41
|
+
'publicPort' => public_port,
|
42
|
+
'virtualMachineId' => virtual_machine_id
|
43
|
+
}
|
44
|
+
async ? send_async_request(params)['portforwardingrule'] : send_request(params)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Project
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get project by name.
|
7
|
+
|
8
|
+
def get_project(name)
|
9
|
+
params = {
|
10
|
+
'command' => 'listProjects',
|
11
|
+
'name' => name,
|
12
|
+
'listall' => true,
|
13
|
+
}
|
14
|
+
json = send_request(params)
|
15
|
+
json['project'] ? json['project'].first : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Lists projects.
|
20
|
+
|
21
|
+
def list_projects
|
22
|
+
params = {
|
23
|
+
'command' => 'listProjects',
|
24
|
+
'listall' => true,
|
25
|
+
}
|
26
|
+
json = send_request(params)
|
27
|
+
json['project'] || []
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Router
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get a router with a given name.
|
7
|
+
|
8
|
+
def get_router(name, project_id = nil)
|
9
|
+
params = {
|
10
|
+
'command' => 'listRouters',
|
11
|
+
'listall' => 'true',
|
12
|
+
'name' => name
|
13
|
+
}
|
14
|
+
params['projectid'] = project_id if project_id
|
15
|
+
|
16
|
+
json = send_request(params)
|
17
|
+
json['router'] ? json['router'].first : nil
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Lists all virtual routers.
|
22
|
+
|
23
|
+
def list_routers(args = {:account => nil, :zone => nil, :projectid => nil, :status => nil, :name => nil})
|
24
|
+
params = {
|
25
|
+
'command' => 'listRouters',
|
26
|
+
'listall' => 'true',
|
27
|
+
'isrecursive' => 'true'
|
28
|
+
}
|
29
|
+
if args[:zone]
|
30
|
+
zone = get_zone(args[:zone])
|
31
|
+
unless zone
|
32
|
+
puts "Error: Zone #{args[:zone]} not found"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
params['zoneid'] = zone['id']
|
36
|
+
end
|
37
|
+
params['projectid'] = args[:projectid] if args[:projectid]
|
38
|
+
params['state'] = args[:status] if args[:status]
|
39
|
+
params['name'] = args[:name] if args[:name]
|
40
|
+
if args[:account]
|
41
|
+
account = list_accounts({name: args[:account]}).first
|
42
|
+
unless account
|
43
|
+
puts "Error: Account #{args[:account]} not found."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
params['domainid'] = account["domainid"]
|
47
|
+
params['account'] = args[:account]
|
48
|
+
end
|
49
|
+
|
50
|
+
json = send_request(params)
|
51
|
+
json['router'] || []
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Destroy virtual router.
|
56
|
+
|
57
|
+
def destroy_router(id, opts = {async: true})
|
58
|
+
params = {
|
59
|
+
'command' => 'destroyRouter',
|
60
|
+
'id' => id
|
61
|
+
}
|
62
|
+
opts[:async] ? send_async_request(params)['router'] : send_request(params)
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Start virtual router.
|
67
|
+
|
68
|
+
def start_router(id, opts = {async: true})
|
69
|
+
params = {
|
70
|
+
'command' => 'startRouter',
|
71
|
+
'id' => id
|
72
|
+
}
|
73
|
+
opts[:async] ? send_async_request(params)['router'] : send_request(params)
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Stop virtual router.
|
78
|
+
|
79
|
+
def stop_router(id, opts = {async: true})
|
80
|
+
params = {
|
81
|
+
'command' => 'stopRouter',
|
82
|
+
'id' => id
|
83
|
+
}
|
84
|
+
opts[:async] ? send_async_request(params)['router'] : send_request(params)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|