knife-cloudstack 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/CHANGES.rdoc +15 -0
  2. data/README.rdoc +18 -0
  3. data/lib/chef/knife/cs_aag_list.rb +58 -0
  4. data/lib/chef/knife/cs_account_list.rb +32 -75
  5. data/lib/chef/knife/cs_base.rb +2 -5
  6. data/lib/chef/knife/cs_baselist.rb +37 -7
  7. data/lib/chef/knife/cs_cluster_list.rb +18 -51
  8. data/lib/chef/knife/cs_config_list.rb +14 -43
  9. data/lib/chef/knife/cs_disk_list.rb +16 -47
  10. data/lib/chef/knife/cs_domain_list.rb +15 -45
  11. data/lib/chef/knife/cs_firewallrule_list.rb +19 -52
  12. data/lib/chef/knife/cs_host_list.rb +19 -53
  13. data/lib/chef/knife/cs_iso_list.rb +30 -44
  14. data/lib/chef/knife/cs_keypair_list.rb +12 -51
  15. data/lib/chef/knife/cs_network_list.rb +20 -51
  16. data/lib/chef/knife/cs_oscategory_list.rb +12 -40
  17. data/lib/chef/knife/cs_ostype_list.rb +15 -43
  18. data/lib/chef/knife/cs_pod_list.rb +18 -51
  19. data/lib/chef/knife/cs_project_list.rb +16 -45
  20. data/lib/chef/knife/cs_publicip_list.rb +16 -49
  21. data/lib/chef/knife/cs_router_list.rb +16 -46
  22. data/lib/chef/knife/cs_securitygroup_list.rb +14 -89
  23. data/lib/chef/knife/cs_server_add_nic.rb +109 -0
  24. data/lib/chef/knife/cs_server_create.rb +25 -5
  25. data/lib/chef/knife/cs_server_list.rb +35 -62
  26. data/lib/chef/knife/cs_server_remove_nic.rb +101 -0
  27. data/lib/chef/knife/cs_service_list.rb +19 -59
  28. data/lib/chef/knife/cs_stack_create.rb +2 -0
  29. data/lib/chef/knife/cs_template_list.rb +26 -55
  30. data/lib/chef/knife/cs_template_register.rb +4 -4
  31. data/lib/chef/knife/cs_user_list.rb +19 -50
  32. data/lib/chef/knife/cs_volume_list.rb +17 -46
  33. data/lib/chef/knife/cs_zone_list.rb +13 -57
  34. data/lib/knife-cloudstack/connection.rb +60 -9
  35. metadata +5 -3
@@ -16,20 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife/cs_base'
19
+ require 'chef/knife'
20
20
  require 'chef/knife/cs_baselist'
21
21
 
22
22
  module KnifeCloudstack
23
23
  class CsVolumeList < Chef::Knife
24
24
 
25
- include Chef::Knife::KnifeCloudstackBase
26
25
  include Chef::Knife::KnifeCloudstackBaseList
27
26
 
28
- deps do
29
- require 'knife-cloudstack/connection'
30
- Chef::Knife.load_deps
31
- end
32
-
33
27
  banner "knife cs volume list (options)"
34
28
 
35
29
  option :listall,
@@ -48,46 +42,23 @@ module KnifeCloudstack
48
42
  def run
49
43
  validate_base_options
50
44
 
51
- object_list = []
52
- if locate_config_value(:fields)
53
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
54
- else
55
- object_list << ui.color('Name', :bold)
56
- object_list << ui.color('Account', :bold) unless locate_config_value(:cloudstack_project)
57
- object_list << ui.color('Domain', :bold)
58
- object_list << ui.color('State', :bold)
59
- object_list << ui.color('VMName', :bold)
60
- object_list << ui.color('VMState', :bold)
61
- end
62
-
63
- columns = object_list.count
64
- object_list = [] if locate_config_value(:noheader)
65
-
66
- connection_result = connection.list_object(
67
- "listVolumes",
68
- "volume",
69
- locate_config_value(:filter),
70
- locate_config_value(:listall),
71
- locate_config_value(:keyword),
72
- locate_config_value(:name)
73
- )
74
-
75
- output_format(connection_result)
45
+ columns = [
46
+ 'Name :name',
47
+ 'Account :account',
48
+ 'Domain :domain',
49
+ 'State :state',
50
+ 'VMName :vmname',
51
+ 'VMState :vmstate'
52
+ ]
76
53
 
77
- connection_result.each do |r|
78
- if locate_config_value(:fields)
79
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
80
- else
81
- object_list << r['name'].to_s
82
- object_list << r['account'].to_s unless locate_config_value(:cloudstack_project)
83
- object_list << r['domain'].to_s
84
- object_list << r['state'].to_s
85
- object_list << r['vmname'].to_s
86
- object_list << r['vmstate'].to_s
87
- end
88
- end
89
- puts ui.list(object_list, :uneven_columns_across, columns)
90
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
54
+ params = { 'command' => "listVolumes" }
55
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
56
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
57
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
58
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
59
+
60
+ result = connection.list_object(params, "volume")
61
+ list_object(columns, result)
91
62
  end
92
63
 
93
64
  end
@@ -18,79 +18,35 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife/cs_base'
21
+ require 'chef/knife'
22
22
  require 'chef/knife/cs_baselist'
23
23
 
24
24
  module KnifeCloudstack
25
25
  class CsZoneList < Chef::Knife
26
26
 
27
- include Chef::Knife::KnifeCloudstackBase
28
27
  include Chef::Knife::KnifeCloudstackBaseList
29
28
 
30
- deps do
31
- require 'knife-cloudstack/connection'
32
- require 'chef/knife'
33
- Chef::Knife.load_deps
34
- end
35
-
36
29
  banner "knife cs zone list (options)"
37
30
 
38
31
  option :keyword,
39
32
  :long => "--keyword KEY",
40
33
  :description => "List by keyword"
41
34
 
42
- option :index,
43
- :long => "--index",
44
- :description => "Add index numbers to the output",
45
- :boolean => true
46
-
47
35
  def run
48
36
  validate_base_options
49
37
 
50
- object_list = []
51
- object_list << ui.color('Index', :bold) if locate_config_value(:index)
52
-
53
- if locate_config_value(:fields)
54
- object_list = []
55
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
56
- else
57
- [
58
- ui.color('Name', :bold),
59
- ui.color('Network Type', :bold),
60
- ui.color('Security Groups', :bold)
61
- ].each { |field| object_list << field }
62
- end
63
-
64
- columns = object_list.count
65
- object_list = [] if locate_config_value(:noheader)
66
-
67
- connection_result = connection.list_object(
68
- "listZones",
69
- "zone",
70
- locate_config_value(:filter),
71
- false,
72
- locate_config_value(:keyword)
73
- )
74
-
75
- output_format(connection_result)
76
-
77
- index_num = 0
78
- connection_result.each do |r|
79
- if locate_config_value(:index)
80
- index_num += 1
81
- object_list << index_num.to_s
82
- end
83
-
84
- if locate_config_value(:fields)
85
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
86
- else
87
- object_list << r['name'].to_s
88
- object_list << r['networktype'].to_s
89
- object_list << r['securitygroupsenabled'].to_s
90
- end
91
- end
92
- puts ui.list(object_list, :uneven_columns_across, columns)
93
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
38
+ columns = [
39
+ 'Name :name',
40
+ 'Network Type :networktype',
41
+ 'Security Groups :securitygroupsenabled'
42
+ ]
43
+
44
+ params = { 'command' => "listZones" }
45
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
46
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
47
+
48
+ result = connection.list_object(params, "zone")
49
+ list_object(columns, result)
94
50
  end
95
51
 
96
52
  end
@@ -147,17 +147,12 @@ module CloudstackClient
147
147
  ##
148
148
  # List all the objects based on the command that is specified.
149
149
 
150
- def list_object(command, json_result, filter=nil, listall=nil, keyword=nil, name=nil, params={})
151
- params['command'] = command
152
- params['listall'] = true if listall || name || keyword unless listall == false
153
- params['keyword'] = keyword if keyword
154
- params['name'] = name if name
155
-
150
+ def list_object(params, json_result)
156
151
  json = send_request(params)
157
152
  Chef::Log.debug("JSON (list_object) result: #{json}")
158
153
 
159
154
  result = json["#{json_result}"] || []
160
- result = data_filter(result, filter) if filter
155
+ result = data_filter(result, params['filter']) if params['filter']
161
156
  result
162
157
  end
163
158
 
@@ -191,8 +186,10 @@ module CloudstackClient
191
186
  end
192
187
 
193
188
  template = get_template(template_name, zone_name)
189
+ template = get_iso(template_name, zone_name) unless template
190
+
194
191
  if !template then
195
- puts "Error: Template '#{template_name}' is invalid"
192
+ puts "Error: Template / ISO name: '#{template_name}' is invalid"
196
193
  exit 1
197
194
  end
198
195
 
@@ -246,7 +243,7 @@ module CloudstackClient
246
243
  'networkids' => network_ids.join(',')
247
244
  }
248
245
 
249
- elsif
246
+ else
250
247
 
251
248
  params = {
252
249
  'command' => 'deployVirtualMachine',
@@ -427,6 +424,34 @@ module CloudstackClient
427
424
  nil
428
425
  end
429
426
 
427
+ ##
428
+ # Finds the iso with the specified name.
429
+
430
+ def get_iso(name, zone_name=nil)
431
+ zone = zone_name ? get_zone(zone_name) : get_default_zone
432
+
433
+ params = {
434
+ 'command' => 'listIsos',
435
+ 'isoFilter' => 'executable',
436
+ }
437
+ params['zoneid'] = zone['id'] if zone
438
+
439
+ json = send_request(params)
440
+ iso = json['iso']
441
+ return nil unless iso
442
+
443
+ iso.each { |i|
444
+ if name.is_uuid? then
445
+ return i if i['id'] == name
446
+ else
447
+ return i if i['name'] == name
448
+ end
449
+ }
450
+ nil
451
+ end
452
+
453
+
454
+
430
455
  ##
431
456
  # Finds the disk offering with the specified name.
432
457
 
@@ -587,6 +612,32 @@ module CloudstackClient
587
612
  nil
588
613
  end
589
614
 
615
+ def add_nic_to_vm(network_id, server_id, ipaddr=nil)
616
+ params = {
617
+ 'command' => 'addNicToVirtualMachine',
618
+ 'networkid' => network_id,
619
+ 'virtualmachineid' => server_id,
620
+ }
621
+
622
+ unless ipaddr.nil?
623
+ params['ipaddress'] = ipaddr
624
+ end
625
+
626
+ json = send_async_request(params)
627
+ json['virtualmachine']
628
+ end
629
+
630
+ def remove_nic_from_vm(nic_id, server_id)
631
+ params = {
632
+ 'command' => 'removeNicFromVirtualMachine',
633
+ 'nicid' => nic_id,
634
+ 'virtualmachineid' => server_id,
635
+ }
636
+
637
+ json = send_async_request(params)
638
+ json['virtualmachine']
639
+ end
640
+
590
641
  ##
591
642
  # Finds the default zone for your account.
592
643
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-cloudstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-11-04 00:00:00.000000000 Z
16
+ date: 2014-02-12 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: chef
@@ -83,6 +83,7 @@ files:
83
83
  - lib/chef/knife/cs_server_stop.rb
84
84
  - lib/chef/knife/cs_publicip_list.rb
85
85
  - lib/chef/knife/cs_pod_list.rb
86
+ - lib/chef/knife/cs_aag_list.rb
86
87
  - lib/chef/knife/cs_cluster_list.rb
87
88
  - lib/chef/knife/cs_server_reboot.rb
88
89
  - lib/chef/knife/cs_base.rb
@@ -100,8 +101,10 @@ files:
100
101
  - lib/chef/knife/cs_server_list.rb
101
102
  - lib/chef/knife/cs_stack_delete.rb
102
103
  - lib/chef/knife/cs_account_list.rb
104
+ - lib/chef/knife/cs_server_remove_nic.rb
103
105
  - lib/chef/knife/cs_server_delete.rb
104
106
  - lib/chef/knife/cs_domain_list.rb
107
+ - lib/chef/knife/cs_server_add_nic.rb
105
108
  - lib/chef/knife/cs_keypair_list.rb
106
109
  - lib/chef/knife/cs_project_list.rb
107
110
  - lib/chef/knife/cs_ostype_list.rb
@@ -131,4 +134,3 @@ signing_key:
131
134
  specification_version: 3
132
135
  summary: A knife plugin for the CloudStack API
133
136
  test_files: []
134
- has_rdoc: true