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.
- data/CHANGES.rdoc +15 -0
- data/README.rdoc +18 -0
- data/lib/chef/knife/cs_aag_list.rb +58 -0
- data/lib/chef/knife/cs_account_list.rb +32 -75
- data/lib/chef/knife/cs_base.rb +2 -5
- data/lib/chef/knife/cs_baselist.rb +37 -7
- data/lib/chef/knife/cs_cluster_list.rb +18 -51
- data/lib/chef/knife/cs_config_list.rb +14 -43
- data/lib/chef/knife/cs_disk_list.rb +16 -47
- data/lib/chef/knife/cs_domain_list.rb +15 -45
- data/lib/chef/knife/cs_firewallrule_list.rb +19 -52
- data/lib/chef/knife/cs_host_list.rb +19 -53
- data/lib/chef/knife/cs_iso_list.rb +30 -44
- data/lib/chef/knife/cs_keypair_list.rb +12 -51
- data/lib/chef/knife/cs_network_list.rb +20 -51
- data/lib/chef/knife/cs_oscategory_list.rb +12 -40
- data/lib/chef/knife/cs_ostype_list.rb +15 -43
- data/lib/chef/knife/cs_pod_list.rb +18 -51
- data/lib/chef/knife/cs_project_list.rb +16 -45
- data/lib/chef/knife/cs_publicip_list.rb +16 -49
- data/lib/chef/knife/cs_router_list.rb +16 -46
- data/lib/chef/knife/cs_securitygroup_list.rb +14 -89
- data/lib/chef/knife/cs_server_add_nic.rb +109 -0
- data/lib/chef/knife/cs_server_create.rb +25 -5
- data/lib/chef/knife/cs_server_list.rb +35 -62
- data/lib/chef/knife/cs_server_remove_nic.rb +101 -0
- data/lib/chef/knife/cs_service_list.rb +19 -59
- data/lib/chef/knife/cs_stack_create.rb +2 -0
- data/lib/chef/knife/cs_template_list.rb +26 -55
- data/lib/chef/knife/cs_template_register.rb +4 -4
- data/lib/chef/knife/cs_user_list.rb +19 -50
- data/lib/chef/knife/cs_volume_list.rb +17 -46
- data/lib/chef/knife/cs_zone_list.rb +13 -57
- data/lib/knife-cloudstack/connection.rb +60 -9
- 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
|
-
|
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: #{
|
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
|
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
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
113
|
-
|
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
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
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
|
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','
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
72
|
-
|
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
|
-
|
104
|
-
|
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 :
|
71
|
-
:long => "--[no-]
|
72
|
-
:description => "Is the template
|
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['
|
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
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|