cloudstack_client 0.9.7 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -11
  3. data/bin/cloudstack_client +5 -0
  4. data/cloudstack_client.gemspec +2 -0
  5. data/config/4.2.json +1 -0
  6. data/lib/cloudstack_client/api.rb +29 -0
  7. data/lib/cloudstack_client/cli.rb +107 -0
  8. data/lib/cloudstack_client/client.rb +34 -127
  9. data/lib/cloudstack_client/connection.rb +131 -0
  10. data/lib/cloudstack_client/error.rb +9 -0
  11. data/lib/cloudstack_client/version.rb +1 -1
  12. data/lib/cloudstack_client.rb +0 -1
  13. metadata +38 -34
  14. data/lib/cloudstack_client/commands/account.rb +0 -38
  15. data/lib/cloudstack_client/commands/affinity_group.rb +0 -39
  16. data/lib/cloudstack_client/commands/capacity.rb +0 -30
  17. data/lib/cloudstack_client/commands/cluster.rb +0 -19
  18. data/lib/cloudstack_client/commands/configuration.rb +0 -42
  19. data/lib/cloudstack_client/commands/disk_offering.rb +0 -49
  20. data/lib/cloudstack_client/commands/domain.rb +0 -22
  21. data/lib/cloudstack_client/commands/host.rb +0 -28
  22. data/lib/cloudstack_client/commands/ip_address.rb +0 -83
  23. data/lib/cloudstack_client/commands/iso.rb +0 -76
  24. data/lib/cloudstack_client/commands/job.rb +0 -29
  25. data/lib/cloudstack_client/commands/load_balancer_rule.rb +0 -61
  26. data/lib/cloudstack_client/commands/network.rb +0 -130
  27. data/lib/cloudstack_client/commands/pod.rb +0 -20
  28. data/lib/cloudstack_client/commands/port_forwarding_rule.rb +0 -49
  29. data/lib/cloudstack_client/commands/project.rb +0 -32
  30. data/lib/cloudstack_client/commands/region.rb +0 -19
  31. data/lib/cloudstack_client/commands/resource_limit.rb +0 -125
  32. data/lib/cloudstack_client/commands/router.rb +0 -100
  33. data/lib/cloudstack_client/commands/server.rb +0 -350
  34. data/lib/cloudstack_client/commands/service_offering.rb +0 -98
  35. data/lib/cloudstack_client/commands/snapshot.rb +0 -51
  36. data/lib/cloudstack_client/commands/ssh_key_pair.rb +0 -137
  37. data/lib/cloudstack_client/commands/storage_pool.rb +0 -31
  38. data/lib/cloudstack_client/commands/system_vm.rb +0 -82
  39. data/lib/cloudstack_client/commands/template.rb +0 -60
  40. data/lib/cloudstack_client/commands/user.rb +0 -32
  41. data/lib/cloudstack_client/commands/volume.rb +0 -54
  42. data/lib/cloudstack_client/commands/zone.rb +0 -57
  43. data/lib/connection_helper.rb +0 -12
@@ -1,19 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Cluster
4
-
5
- ##
6
- # Lists clusters.
7
-
8
- def list_clusters(args = {})
9
- params = {
10
- 'command' => 'listClusters',
11
- }
12
-
13
- json = send_request(params)
14
- json['cluster'] || []
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,42 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Configuration
4
-
5
- ##
6
- # List configuration.
7
-
8
- def list_configurations(args = {})
9
- params = {
10
- 'command' => 'listConfigurations',
11
- }
12
-
13
- if args[:zone]
14
- zone = get_zone(args[:zone])
15
- unless zone
16
- puts "Error: Zone #{args[:zone]} not found"
17
- exit 1
18
- end
19
- params['zoneid'] = zone['id']
20
- end
21
-
22
- if args[:account]
23
- account = list_accounts({name: args[:account]}).first
24
- unless account
25
- puts "Error: Account #{args[:account]} not found."
26
- exit 1
27
- end
28
- params['domainid'] = account["domainid"]
29
- params['account'] = args[:account]
30
- end
31
-
32
- params['name'] = args[:name] if args[:name]
33
- params['keyword'] = args[:keyword] if args[:keyword]
34
- params['category'] = args[:category] if args[:category]
35
-
36
- json = send_request(params)
37
- json['configuration'] || []
38
- end
39
-
40
- end
41
-
42
- end
@@ -1,49 +0,0 @@
1
- module CloudstackClient
2
-
3
- module DiskOffering
4
-
5
- ##
6
- # Lists all available disk offerings.
7
-
8
- def list_disk_offerings(domain = nil)
9
- params = {
10
- 'command' => 'listDiskOfferings'
11
- }
12
-
13
- if domain
14
- params['domainid'] = list_domains(domain).first["id"]
15
- end
16
-
17
- json = send_request(params)
18
- json['diskoffering'] || []
19
- end
20
-
21
- ##
22
- # Get disk offering by name.
23
-
24
- def get_disk_offering(name)
25
-
26
- # TODO: use name parameter
27
- # listServiceOfferings in CloudStack 2.2 doesn't seem to work
28
- # when the name parameter is specified. When this is fixed,
29
- # the name parameter should be added to the request.
30
- params = {
31
- 'command' => 'listDiskOfferings'
32
- }
33
- json = send_request(params)
34
-
35
- services = json['diskoffering']
36
- return nil unless services
37
-
38
- services.each { |s|
39
- if s['name'] == name then
40
- return s
41
- end
42
- }
43
- nil
44
- end
45
-
46
-
47
- end
48
-
49
- end
@@ -1,22 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Domain
4
-
5
- ##
6
- # List domains.
7
-
8
- def list_domains(name = nil)
9
- params = {
10
- 'command' => 'listDomains',
11
- 'listall' => 'true',
12
- 'isrecursive' => 'true'
13
- }
14
- params['name'] = name if name
15
-
16
- json = send_request(params)
17
- json['domain'] || []
18
- end
19
-
20
- end
21
-
22
- end
@@ -1,28 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Host
4
-
5
- ##
6
- # Lists hosts.
7
-
8
- def list_hosts(args = {})
9
- params = {
10
- 'command' => 'listHosts'
11
- }
12
-
13
- if args[:zone]
14
- zone = get_zone(args[:zone])
15
- unless zone
16
- puts "Error: zone #{args[:project]} not found."
17
- exit 1
18
- end
19
- params['zoneid'] = zone['id']
20
- end
21
-
22
- json = send_request(params)
23
- json['host'] || []
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,83 +0,0 @@
1
- module CloudstackClient
2
-
3
- module IpAddress
4
-
5
- ##
6
- # Lists the public ip addresses.
7
-
8
- def list_public_ip_addresses(args = {})
9
- params = {
10
- 'command' => 'listPublicIpAddresses',
11
- 'isrecursive' => true
12
- }
13
- if args[:project]
14
- project = get_project(args[:project])
15
- unless project
16
- puts "Error: project #{args[:project]} not found."
17
- exit 1
18
- end
19
- params['projectid'] = project['id']
20
- end
21
- if args[:account]
22
- account = list_accounts({name: args[:account]}).first
23
- unless account
24
- puts "Error: Account #{args[:account]} not found."
25
- exit 1
26
- end
27
- params['domainid'] = account["domainid"]
28
- params['account'] = args[:account]
29
- end
30
- params['listall'] = args[:listall] if args[:listall]
31
-
32
- json = send_request(params)
33
- json['publicipaddress'] || []
34
- end
35
-
36
- ##
37
- # Finds the public ip address for a given ip address string.
38
-
39
- def get_public_ip_address(ip_address, project_id = nil)
40
- params = {
41
- 'command' => 'listPublicIpAddresses',
42
- 'ipaddress' => ip_address
43
- }
44
- params['projectid'] = project_id if project_id
45
- json = send_request(params)
46
- ip_address = json['publicipaddress']
47
-
48
- return nil unless ip_address
49
- ip_address.first
50
- end
51
-
52
-
53
- ##
54
- # Acquires and associates a public IP to an account.
55
-
56
- def associate_ip_address(network_id, project_id = nil)
57
- params = {
58
- 'command' => 'associateIpAddress',
59
- 'networkid' => network_id
60
- }
61
- params['projectid'] = project_id if project_id
62
-
63
- json = send_async_request(params)
64
- json['ipaddress']
65
- end
66
-
67
- ##
68
- # Disassociates an ip address from the account.
69
- #
70
- # Returns true if successful, false otherwise.
71
-
72
- def disassociate_ip_address(id)
73
- params = {
74
- 'command' => 'disassociateIpAddress',
75
- 'id' => id
76
- }
77
- json = send_async_request(params)
78
- json['success']
79
- end
80
-
81
- end
82
-
83
- end
@@ -1,76 +0,0 @@
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
- ##
63
- # Detaches any ISO file (if any) currently attached to a virtual machine.
64
-
65
- def detach_iso(vm_id, args = {})
66
- params = {
67
- 'command' => 'detachIso',
68
- 'virtualmachineid' => vm_id
69
- }
70
- json = send_request(params)
71
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,29 +0,0 @@
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
@@ -1,61 +0,0 @@
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
@@ -1,130 +0,0 @@
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
- }
73
-
74
- params['listall'] = true unless args[:isdefault]
75
- params['isDefault'] = true if args[:isdefault]
76
-
77
- params['projectid'] = args[:project_id] if args[:project_id]
78
- params['zoneid'] = args[:zone_id] if args[:zone_id]
79
- if args[:account]
80
- domain = list_accounts(name: args[:account])
81
- if domain.size > 0
82
- params['account'] = args[:account]
83
- params['domainid'] = domain.first["domainid"]
84
- else
85
- puts "Account #{args[:account]} not found."
86
- end
87
- end
88
- json = send_request(params)
89
- json['network'] || []
90
- end
91
-
92
- ##
93
- # Delete network.
94
-
95
- def delete_network(id)
96
- params = {
97
- 'command' => 'deleteNetwork',
98
- 'id' => id,
99
- }
100
- p json = send_async_request(params)
101
- json['network']
102
- end
103
-
104
- ##
105
- # Restart network.
106
-
107
- def restart_network(id, cleanup = false)
108
- params = {
109
- 'command' => 'restartNetwork',
110
- 'id' => id,
111
- 'cleanup' => cleanup,
112
- }
113
- p json = send_async_request(params)
114
- json['network']
115
- end
116
-
117
- ##
118
- # Lists all physical networks.
119
-
120
- def list_physical_networks
121
- params = {
122
- 'command' => 'listPhysicalNetworks',
123
- }
124
- json = send_request(params)
125
- json['physicalnetwork'] || []
126
- end
127
-
128
- end
129
-
130
- end
@@ -1,20 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Pod
4
-
5
- ##
6
- # Lists pods.
7
-
8
- def list_pods(args = {})
9
- params = {
10
- 'command' => 'listPods',
11
- }
12
- params['podid'] = args[:pod_id] if args[:pod_id]
13
-
14
- json = send_request(params)
15
- json['pod'] || []
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,49 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,19 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Region
4
-
5
- ##
6
- # List regions.
7
-
8
- def list_regions(args = {})
9
- params = {
10
- 'command' => 'listRegions',
11
- }
12
-
13
- json = send_request(params)
14
- json['region'] || []
15
- end
16
-
17
- end
18
-
19
- end