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
@@ -103,6 +103,10 @@ module KnifeCloudstack
103
103
  :boolean => true,
104
104
  :default => true
105
105
 
106
+ option :ik_private_ip,
107
+ :long => "--private-ip PRIVATE_IPV4_ADDRESS",
108
+ :description => "Pass a certain private ipv4 address to cloudstack when deploying (only supported on isolated networks)"
109
+
106
110
  option :chef_node_name,
107
111
  :short => "-N NAME",
108
112
  :long => "--node-name NAME",
@@ -128,6 +132,14 @@ module KnifeCloudstack
128
132
  :long => "--identity-file IDENTITY_FILE",
129
133
  :description => "The SSH identity file used for authentication"
130
134
 
135
+ option :secret_file,
136
+ :long => "--secret-file SECRET_FILE",
137
+ :description => "The path to the file that contains the encryption key."
138
+
139
+ option :secret,
140
+ :long => "--secret SECRET",
141
+ :description => "The encryption key that is used for values contained within a data bag item."
142
+
131
143
  option :prerelease,
132
144
  :long => "--prerelease",
133
145
  :description => "Install the pre-release chef gems"
@@ -257,6 +269,7 @@ module KnifeCloudstack
257
269
 
258
270
  params['keypair'] = locate_config_value :keypair if locate_config_value :keypair
259
271
  params['displayname'] = if locate_config_value :set_display_name and locate_config_value :chef_node_name then locate_config_value :chef_node_name else hostname end
272
+ params['ipaddress'] = locate_config_value(:ik_private_ip) if locate_config_value(:ik_private_ip)
260
273
 
261
274
  server = connection.create_server(
262
275
  hostname,
@@ -268,6 +281,10 @@ module KnifeCloudstack
268
281
  params
269
282
  )
270
283
 
284
+ zone_name = locate_config_value(:cloudstack_zone)
285
+ zone = zone_name ? connection.get_zone(zone_name) : connection.get_default_zone
286
+
287
+ config[:public_ip] = false if zone['networktype'] == 'Basic'
271
288
  public_ip = find_or_create_public_ip(server, connection)
272
289
 
273
290
  object_fields = []
@@ -326,9 +343,11 @@ module KnifeCloudstack
326
343
  end
327
344
 
328
345
  def is_image_windows?
329
- template = connection.get_template(locate_config_value(:cloudstack_template),locate_config_value(:cloudstack_zone))
346
+ template_name = locate_config_value(:cloudstack_template)
347
+ template = connection.get_template(template_name, locate_config_value(:cloudstack_zone))
348
+ template = connection.get_iso(template_name, locate_config_value(:cloudstack_zone)) unless template
330
349
  if !template
331
- ui.error("Template: #{template} does not exist")
350
+ ui.error("Template: #{template_name} does not exist!")
332
351
  exit 1
333
352
  end
334
353
  return template['ostypename'].scan('Windows').length > 0
@@ -376,7 +395,6 @@ module KnifeCloudstack
376
395
 
377
396
  def find_or_create_public_ip(server, connection)
378
397
  nic = connection.get_server_default_nic(server) || {}
379
- #puts "#{ui.color("Not allocating public IP for server", :red)}" unless config[:public_ip]
380
398
  if (config[:public_ip] == false)
381
399
  nic['ipaddress']
382
400
  else
@@ -398,7 +416,7 @@ module KnifeCloudstack
398
416
 
399
417
  def create_port_forwarding_rules(ip_address, server_id, connection)
400
418
  Chef::Log.debug("Creating IP Forwarding Rule")
401
- rules = locate_config_value(:port_rules)
419
+ rules = locate_config_value(:port_rules) || []
402
420
  if config[:bootstrap]
403
421
  if @bootstrap_protocol == 'ssh'
404
422
  rules += ["#{locate_config_value(:ssh_port)}"] #SSH Port
@@ -409,7 +427,7 @@ module KnifeCloudstack
409
427
  exit 1
410
428
  end
411
429
  end
412
- return unless rules
430
+ return if rules.empty?
413
431
  rules.each do |rule|
414
432
  args = rule.split(':')
415
433
  public_port = args[0]
@@ -595,6 +613,8 @@ module KnifeCloudstack
595
613
  locate_config_value(:cloudstack_password) ? bootstrap.config[:ssh_password] = server['password'] : bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
596
614
  bootstrap.config[:ssh_port] = locate_config_value(:ssh_port) || 22
597
615
  bootstrap.config[:identity_file] = locate_config_value(:identity_file)
616
+ bootstrap.config[:secret_file] = locate_config_value(:secret_file)
617
+ bootstrap.config[:secret] = locate_config_value(:secret)
598
618
  bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server["name"]
599
619
  bootstrap.config[:use_sudo] = true unless locate_config_value(:ssh_user) == 'root'
600
620
 
@@ -18,21 +18,14 @@
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 CsServerList < Chef::Knife
26
26
 
27
- include Chef::Knife::KnifeCloudstackBase
28
27
  include Chef::Knife::KnifeCloudstackBaseList
29
28
 
30
- deps do
31
- require 'chef/knife'
32
- require 'knife-cloudstack/connection'
33
- Chef::Knife.load_deps
34
- end
35
-
36
29
  banner "knife cs server list (options)"
37
30
 
38
31
  option :listall,
@@ -52,66 +45,46 @@ module KnifeCloudstack
52
45
  :short => "-a ACTION",
53
46
  :long => "--action ACTION",
54
47
  :description => "start, stop or destroy the instances in your result"
48
+
49
+ option :public_ip,
50
+ :long => "--[no-]public-ip",
51
+ :description => "Show or don't show the public IP for server in your result",
52
+ :boolean => true,
53
+ :default => true
55
54
 
56
55
  def run
57
56
  validate_base_options
58
-
59
- if locate_config_value(:fields)
60
- object_list = []
61
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
62
- else
63
- object_list = [
64
- ui.color('Name', :bold),
65
- ui.color('Public IP', :bold),
66
- ui.color('Service', :bold),
67
- ui.color('Template', :bold),
68
- ui.color('State', :bold),
69
- ui.color('Instance', :bold),
70
- ui.color('Hypervisor', :bold)
71
- ]
72
- end
73
-
74
- columns = object_list.count
75
- object_list = [] if locate_config_value(:noheader)
76
-
77
- connection_result = connection.list_object(
78
- "listVirtualMachines",
79
- "virtualmachine",
80
- locate_config_value(:filter),
81
- locate_config_value(:listall),
82
- locate_config_value(:keyword),
83
- locate_config_value(:name)
84
- )
85
-
86
- output_format(connection_result)
87
-
88
- rules = connection.list_port_forwarding_rules(nil, true)
57
+
58
+ columns = [
59
+ 'Name :name',
60
+ 'Public IP :ipaddress',
61
+ 'Service :serviceofferingname',
62
+ 'Template :templatename',
63
+ 'State :state',
64
+ 'Instance :instancename',
65
+ 'Hypervisor :hostname'
66
+ ]
67
+
68
+ params = { 'command' => "listVirtualMachines" }
69
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
70
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
71
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
72
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
73
+
74
+ ##
75
+ # Get the public IP address if possible, except when the option --no-public-ip is given.
76
+
77
+ rules = connection.list_port_forwarding_rules(nil, true)
89
78
  public_list = connection.list_public_ip_addresses(true)
90
-
91
-
92
- connection_result.each do |r|
93
- name = r['name']
94
- display_name = r['displayname']
95
- if display_name && !display_name.empty? && display_name != name
96
- name << " (#{display_name})"
97
- end
98
-
99
- if locate_config_value(:fields)
100
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
101
- else
102
- object_list << r['name']
103
- r['nic'].empty? ? object_list << "N/A" : object_list << (connection.get_server_public_ip(r, rules, public_list) || '')
104
- object_list << r['serviceofferingname']
105
- object_list << r['templatename']
106
- object_list << r['state']
107
- object_list << (r['instancename'] || 'N/A')
108
- object_list << (r['hostname'] || 'N/A')
109
- end
79
+ result = connection.list_object(params, "virtualmachine")
80
+ result.each do |n|
81
+ public_ip = connection.get_server_public_ip(n, rules, public_list) if locate_config_value(:public_ip)
82
+ private_ip = (n['nic'].select { |k| k['isdefault'] }).first
83
+ public_ip ? n['ipaddress'] = public_ip : n['ipaddress'] = private_ip['ipaddress'] || "N/A"
110
84
  end
111
85
 
112
- puts ui.list(object_list, :uneven_columns_across, columns)
113
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
114
-
86
+ list_object(columns, result)
87
+
115
88
  ##
116
89
  # Executing actions against the list results that are returned.
117
90
 
@@ -0,0 +1,101 @@
1
+ #
2
+ # Author:: John E. Vincent (<lusis.org+github.com@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013 John E. Vincent
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'chef/knife/cs_base'
19
+ require 'chef/knife/cs_baselist'
20
+
21
+ module KnifeCloudstack
22
+ class CsServerRemoveNic < Chef::Knife
23
+
24
+ include Chef::Knife::KnifeCloudstackBase
25
+ include Chef::Knife::KnifeCloudstackBaseList
26
+
27
+ deps do
28
+ require 'knife-cloudstack/connection'
29
+ require 'chef/knife'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cs server remove nic SERVERID NICID"
34
+
35
+
36
+ def run
37
+ validate_base_options
38
+
39
+ @server_id, @nic_id = name_args
40
+
41
+ if @server_id.nil? || @nic_id.nil?
42
+ show_usage
43
+ ui.fatal("You must provide both a nic id and a server id")
44
+ exit(1)
45
+ end
46
+
47
+
48
+ object_list = []
49
+ if locate_config_value(:fields)
50
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
51
+ else
52
+ object_list << ui.color('Server', :bold)
53
+ object_list << ui.color('Network', :bold)
54
+ object_list << ui.color('Type', :bold)
55
+ object_list << ui.color('Default', :bold)
56
+ object_list << ui.color('Address', :bold)
57
+ object_list << ui.color('Gateway', :bold)
58
+ object_list << ui.color('Netmask', :bold)
59
+ object_list << ui.color('ID', :bold)
60
+ end
61
+
62
+ columns = object_list.count
63
+
64
+ connection_result = connection.remove_nic_from_vm(
65
+ @nic_id,
66
+ @server_id
67
+ )
68
+
69
+ output_format(connection_result)
70
+
71
+ object_list << connection_result['name']
72
+ object_list << ''
73
+ object_list << ''
74
+ object_list << ''
75
+ object_list << ''
76
+ object_list << ''
77
+ object_list << ''
78
+ object_list << ''
79
+ if connection_result['nic']
80
+ connection_result['nic'].each do |r|
81
+ if locate_config_value(:fields)
82
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
83
+ else
84
+ object_list << ''
85
+ object_list << r['networkname'].to_s
86
+ object_list << r['type'].to_s
87
+ object_list << (r['isdefault'] ? r['isdefault'].to_s : 'false')
88
+ object_list << (r['ipaddress'] || '')
89
+ object_list << (r['gateway'] || '')
90
+ object_list << (r['netmask'] || '')
91
+ object_list << (r['networkid'] || '')
92
+ end
93
+ end
94
+ puts ui.list(object_list, :uneven_columns_across, columns)
95
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
96
+ else
97
+ ui.error("No nics returned in response")
98
+ end
99
+ end
100
+ end
101
+ end
@@ -18,21 +18,14 @@
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 CsServiceList < Chef::Knife
26
26
 
27
- include Chef::Knife::KnifeCloudstackBase
28
27
  include Chef::Knife::KnifeCloudstackBaseList
29
28
 
30
- deps do
31
- require 'chef/knife'
32
- require 'knife-cloudstack/connection'
33
- Chef::Knife.load_deps
34
- end
35
-
36
29
  banner "knife cs service list (options)"
37
30
 
38
31
  option :name,
@@ -43,62 +36,29 @@ module KnifeCloudstack
43
36
  :long => "--keyword NAME",
44
37
  :description => "Specify part of servicename to list"
45
38
 
46
- option :index,
47
- :long => "--index",
48
- :description => "Add index numbers to the output",
49
- :boolean => true
50
-
51
39
  def run
52
40
  validate_base_options
53
-
54
- object_list = []
55
- object_list << ui.color('Index', :bold) if locate_config_value(:index)
56
41
 
57
- if locate_config_value(:fields)
58
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
59
- else
60
- [
61
- ui.color('Name', :bold),
62
- ui.color('Memory', :bold),
63
- ui.color('CPUs', :bold),
64
- ui.color('CPU Speed', :bold),
65
- ui.color('Created', :bold)
66
- ].each { |field| object_list << field }
42
+ columns = [
43
+ 'Name :name',
44
+ 'Memory :memory',
45
+ 'CPUs :cpunumber',
46
+ 'CPU Speed :cpuspeed',
47
+ 'Created :created'
48
+ ]
49
+
50
+ params = { 'command' => "listServiceOfferings" }
51
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
52
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
53
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
54
+
55
+ result = connection.list_object(params, "serviceoffering")
56
+
57
+ result.each do |r|
58
+ r['memory'] = human_memory(r['memory']) if r['memory']
67
59
  end
68
60
 
69
- columns = object_list.count
70
- object_list = [] if locate_config_value(:noheader)
71
-
72
- connection_result = connection.list_object(
73
- "listServiceOfferings",
74
- "serviceoffering",
75
- locate_config_value(:filter),
76
- false,
77
- locate_config_value(:keyword),
78
- locate_config_value(:name)
79
- )
80
-
81
- output_format(connection_result)
82
-
83
- index_num = 0
84
- connection_result.each do |r|
85
- if locate_config_value(:index)
86
- index_num += 1
87
- object_list << index_num.to_s
88
- end
89
-
90
- if locate_config_value(:fields)
91
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
92
- else
93
- object_list << r['name'].to_s
94
- object_list << (r['memory'] ? human_memory(r['memory']) : 'Unknown')
95
- object_list << r['cpunumber'].to_s
96
- object_list << r['cpuspeed'].to_s + ' Mhz'
97
- object_list << r['created']
98
- end
99
- end
100
- puts ui.list(object_list, :uneven_columns_across, columns)
101
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
61
+ list_object(columns, result)
102
62
  end
103
63
 
104
64
  def human_memory n
@@ -102,10 +102,12 @@ module KnifeCloudstack
102
102
  cmd.config[:ssh_password] = config[:ssh_password]
103
103
  cmd.config[:ssh_port] = config[:ssh_port] || "22" # Chef::Config[:knife][:ssh_port]
104
104
  cmd.config[:identity_file] = config[:identity_file]
105
+ cmd.config[:keypair] = server[:keypair]
105
106
  cmd.config[:cloudstack_template] = server[:template] if server[:template]
106
107
  cmd.config[:cloudstack_service] = server[:service] if server[:service]
107
108
  cmd.config[:cloudstack_zone] = server[:zone] if server[:zone]
108
109
  server.has_key?(:public_ip) ? cmd.config[:public_ip] = server[:public_ip] : cmd.config[:no_public_ip] = true
110
+ cmd.config[:ik_private_ip] = server[:private_ip] if server[:private_ip]
109
111
  cmd.config[:bootstrap] = server[:bootstrap] if server.has_key?(:bootstrap)
110
112
  cmd.config[:bootstrap_protocol] = server[:bootstrap_protocol] || "ssh"
111
113
  cmd.config[:distro] = server[:distro] || "chef-full"
@@ -18,21 +18,14 @@
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 CsTemplateList < 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 template list (options)"
37
30
 
38
31
  option :listall,
@@ -47,61 +40,39 @@ module KnifeCloudstack
47
40
 
48
41
  option :templatefilter,
49
42
  :long => "--templatefilter FILTER",
50
- :description => "Default: 'featured'. Options: 'self','self-executable','executable','community'",
43
+ :description => "Default: 'featured'. Options: 'self','selfexecutable','sharedexecutable','executable','community'",
51
44
  :default => "featured"
52
45
 
53
46
  def run
54
47
  validate_base_options
55
48
 
56
- object_list = []
57
- object_list << ui.color('Index', :bold) if locate_config_value(:index)
58
-
59
- if locate_config_value(:fields)
60
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
49
+ columns = [
50
+ 'Name :name',
51
+ 'Size :size',
52
+ 'Zone :zonename',
53
+ 'Public :ispublic',
54
+ 'Created :created'
55
+ ]
56
+
57
+ params = { 'command' => "listTemplates" }
58
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
59
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
60
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
61
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
62
+
63
+ if ['all','featured','self','selfexecutable','sharedexecutable','executable','community'].include?(locate_config_value(:templatefilter))
64
+ params['templatefilter'] = locate_config_value(:templatefilter)
61
65
  else
62
- [
63
- ui.color('Name', :bold),
64
- ui.color('Size', :bold),
65
- ui.color('Zone', :bold),
66
- ui.color('Public', :bold),
67
- ui.color('Created', :bold)
68
- ].each { |field| object_list << field }
69
- end
66
+ params['templatefilter'] = 'featured'
67
+ end
68
+
69
+ result = connection.list_object(params, "template")
70
70
 
71
- columns = object_list.count
72
- object_list = [] if locate_config_value(:noheader)
73
-
74
- connection_result = connection.list_object(
75
- "listTemplates",
76
- "template",
77
- locate_config_value(:filter),
78
- locate_config_value(:listall),
79
- nil,
80
- nil,
81
- params = { 'templatefilter' => locate_config_value(:templatefilter) }
82
- )
83
-
84
- output_format(connection_result)
85
-
86
- index_num = 0
87
- connection_result.each do |r|
88
- if locate_config_value(:index)
89
- index_num += 1
90
- object_list << index_num.to_s
91
- end
92
-
93
- if locate_config_value(:fields)
94
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
95
- else
96
- object_list << r['name'].to_s
97
- object_list << (r['size'] ? human_file_size(r['size']) : 'Unknown')
98
- object_list << r['zonename'].to_s
99
- object_list << r['ispublic'].to_s
100
- object_list << r['created']
101
- end
71
+ result.each do |r|
72
+ r['size'] = human_file_size(r['size']) if r['size']
102
73
  end
103
- puts ui.list(object_list, :uneven_columns_across, columns)
104
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
74
+
75
+ list_object(columns, result)
105
76
  end
106
77
 
107
78
  def human_file_size n
@@ -67,9 +67,9 @@ module KnifeCloudstack
67
67
  :description => "32 or 64 bits support, defaults to 64",
68
68
  :default => 64
69
69
 
70
- option :extractable,
71
- :long => "--[no-]extractable",
72
- :description => "Is the template extracable. Default: NO",
70
+ option :isextractable,
71
+ :long => "--[no-]isextractable",
72
+ :description => "Is the template extractable. Default: NO",
73
73
  :boolean => true,
74
74
  :default => false
75
75
 
@@ -159,7 +159,7 @@ module KnifeCloudstack
159
159
  'zoneid' => zoneid,
160
160
  'bits' => locate_config_value(:bits),
161
161
  }
162
- params['extracable'] = locate_config_value(:extractable) if locate_config_value(:extractable)
162
+ params['isextractable'] = locate_config_value(:isextractable) if locate_config_value(:isextractable)
163
163
  params['ispublic'] = locate_config_value(:public) if locate_config_value(:public)
164
164
  params['isfeatured'] = locate_config_value(:featured) if locate_config_value(:featured)
165
165
  params['passwordenabled'] = locate_config_value(:passwordenabled) if locate_config_value(:passwordenabled)
@@ -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 CsUserList < 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 user list (options)"
34
28
 
35
29
  option :listall,
@@ -44,49 +38,24 @@ module KnifeCloudstack
44
38
  def run
45
39
  validate_base_options
46
40
 
47
- if locate_config_value(:fields)
48
- object_list = []
49
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
50
- else
51
- object_list = [
52
- ui.color('Account', :bold),
53
- ui.color('Type', :bold),
54
- ui.color('State', :bold),
55
- ui.color('Domain', :bold),
56
- ui.color('Username', :bold),
57
- ui.color('First', :bold),
58
- ui.color('Last', :bold)
59
- ]
60
- end
61
-
62
- columns = object_list.count
63
- object_list = [] if locate_config_value(:noheader)
64
-
65
- connection_result = connection.list_object(
66
- "listUsers",
67
- "user",
68
- locate_config_value(:filter),
69
- locate_config_value(:listall),
70
- locate_config_value(:keyword)
71
- )
72
-
73
- output_format(connection_result)
74
-
75
- connection_result.each do |r|
76
- if locate_config_value(:fields)
77
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
78
- else
79
- object_list << r['account'].to_s
80
- object_list << r['accounttype'].to_s
81
- object_list << r['state'].to_s
82
- object_list << r['domain'].to_s
83
- object_list << r['username'].to_s
84
- object_list << r['firstname'].to_s
85
- object_list << r['lastname'].to_s
86
- end
87
- end
88
- puts ui.list(object_list, :uneven_columns_across, columns)
89
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
41
+ columns = [
42
+ 'Account :account',
43
+ 'Type :accounttype',
44
+ 'State :state',
45
+ 'Domain :domain',
46
+ 'Username :username',
47
+ 'First :firstname',
48
+ 'Last :lastname'
49
+ ]
50
+
51
+ params = { 'command' => "listUsers" }
52
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
53
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
54
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
55
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
56
+
57
+ result = connection.list_object(params, "user")
58
+ list_object(columns, result)
90
59
  end
91
60
 
92
61
  end