knife-cloudstack-fog 0.5.0 → 0.5.1

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.
@@ -1,75 +1,78 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2012 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackServerStart < Knife
24
-
25
- include Knife::CloudstackBase
26
- banner "knife cloudstack server start INSTANCE_ID"
27
-
28
- def run
29
-
30
- if @name_args.nil? || @name_args.empty?
31
- puts "#{ui.color("Please provide an Instance ID.", :red)}"
32
- end
33
-
34
- jobs = {}
35
-
36
- @name_args.each do |instance_id|
37
- response = connection.list_virtual_machines('name' => instance_id)
38
- instance_name = response['listvirtualmachinesresponse']['virtualmachine'].first['name']
39
- instance_ip = response['listvirtualmachinesresponse']['virtualmachine'].first['nic'].first['ipaddress']
40
- real_instance_id = response['listvirtualmachinesresponse']['virtualmachine'].first['id']
41
- puts "#{ui.color("Name", :green)}: #{instance_name}"
42
- puts "#{ui.color("Public IP", :green)}: #{instance_ip}"
43
- puts "\n"
44
- confirm("#{ui.color("Do you really want to start this server", :green)}")
45
-
46
-
47
- if locate_config_value(:force)
48
- server = connection.start_virtual_machine('id' => real_instance_id, 'forced' => true)
49
- else
50
- server = connection.start_virtual_machine('id' => real_instance_id)
51
- end
52
- jobid = server['startvirtualmachineresponse'].fetch('jobid')
53
-
54
- jobs[instance_id] = jobid
55
- end
56
-
57
- print "#{ui.color("Waiting for servers", :magenta)}"
58
- until jobs.empty?
59
- jobs.each do |instance_id, jobid|
60
- server_start = connection.query_async_job_result('jobid'=>jobid)
61
- if server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 1
62
- jobs.delete(instance_id)
63
-
64
- puts "\n\n"
65
- ui.warn("Started server #{instance_id}")
66
- else
67
- print "#{ui.color(".", :magenta)}"
68
- sleep(1)
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackServerStart < Knife
24
+
25
+ include Knife::CloudstackBase
26
+ banner "knife cloudstack server start INSTANCE_ID"
27
+
28
+ def run
29
+
30
+ if @name_args.nil? || @name_args.empty?
31
+ puts "#{ui.color("Please provide an Instance ID.", :red)}"
32
+ end
33
+
34
+ jobs = {}
35
+ batch_size = 5
36
+
37
+ @name_args.each_slice(batch_size) do |batch|
38
+ batch.each do |instance_id|
39
+ response = connection.list_virtual_machines('name' => instance_id)
40
+ instance_name = response['listvirtualmachinesresponse']['virtualmachine'].first['name']
41
+ instance_ip = response['listvirtualmachinesresponse']['virtualmachine'].first['nic'].first['ipaddress']
42
+ real_instance_id = response['listvirtualmachinesresponse']['virtualmachine'].first['id']
43
+ puts "#{ui.color("Name", :green)}: #{instance_name}"
44
+ puts "#{ui.color("Public IP", :green)}: #{instance_ip}"
45
+ puts "\n"
46
+ confirm("#{ui.color("Do you really want to start this server", :green)}")
47
+
48
+
49
+ if locate_config_value(:force)
50
+ server = connection.start_virtual_machine('id' => real_instance_id, 'forced' => true)
51
+ else
52
+ server = connection.start_virtual_machine('id' => real_instance_id)
53
+ end
54
+ jobid = server['startvirtualmachineresponse'].fetch('jobid')
55
+
56
+ jobs[instance_id] = jobid
57
+ end
58
+
59
+ print "#{ui.color("Waiting for servers", :magenta)}"
60
+ until jobs.empty?
61
+ jobs.each do |instance_id, jobid|
62
+ server_start = connection.query_async_job_result('jobid'=>jobid)
63
+ if server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 1
64
+ jobs.delete(instance_id)
65
+
66
+ puts "\n\n"
67
+ ui.warn("Started server #{instance_id}")
68
+ else
69
+ print "#{ui.color(".", :magenta)}"
70
+ sleep(1)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,78 +1,83 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2012 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackServerStop < Knife
24
-
25
- include Knife::CloudstackBase
26
- banner "knife cloudstack server stop INSTANCE_ID (options)"
27
- option :forced,
28
- :short => "-f",
29
- :description => "Issue this as a forced stop command."
30
-
31
- def run
32
-
33
- if @name_args.nil? || @name_args.empty?
34
- puts "#{ui.color("Please provide an Instance ID.", :red)}"
35
- end
36
-
37
- jobs = {}
38
-
39
- @name_args.each do |instance_id|
40
- response = connection.list_virtual_machines('name' => instance_id)
41
- instance_name = response['listvirtualmachinesresponse']['virtualmachine'].first['name']
42
- instance_ip = response['listvirtualmachinesresponse']['virtualmachine'].first['nic'].first['ipaddress']
43
- real_instance_id = response['listvirtualmachinesresponse']['virtualmachine'].first['id']
44
- puts "#{ui.color("Name", :red)}: #{instance_name}"
45
- puts "#{ui.color("Public IP", :red)}: #{instance_ip}"
46
- puts "\n"
47
- confirm("#{ui.color("Do you really want to stop this server", :red)}")
48
-
49
-
50
- if locate_config_value(:force)
51
- server = connection.stop_virtual_machine('id' => real_instance_id, 'forced' => true)
52
- else
53
- server = connection.stop_virtual_machine('id' => real_instance_id)
54
- end
55
- jobid = server['stopvirtualmachineresponse'].fetch('jobid')
56
-
57
- jobs[instance_id] = jobid
58
- end
59
-
60
- print "#{ui.color("Waiting for servers", :magenta)}"
61
- until jobs.empty?
62
- jobs.each do |instance_id, jobid|
63
- server_stop = connection.query_async_job_result('jobid'=>jobid)
64
- if server_stop['queryasyncjobresultresponse'].fetch('jobstatus') == 1
65
- jobs.delete(instance_id)
66
-
67
- puts "\n\n"
68
- ui.warn("Stopped server #{instance_id}")
69
- else
70
- print "#{ui.color(".", :magenta)}"
71
- sleep(1)
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackServerStop < Knife
24
+
25
+ include Knife::CloudstackBase
26
+ banner "knife cloudstack server stop INSTANCE_ID (options)"
27
+ option :forced,
28
+ :short => "-f",
29
+ :description => "Issue this as a forced stop command."
30
+
31
+ def run
32
+
33
+ if @name_args.nil? || @name_args.empty?
34
+ puts "#{ui.color("Please provide an Instance ID.", :red)}"
35
+ end
36
+
37
+ jobs = {}
38
+ batch_size = 5
39
+
40
+ @name_args.each_slice(batch_size) do |batch|
41
+ batch.each do |instance_id|
42
+ response = connection.list_virtual_machines('name' => instance_id)
43
+ instance_name = response['listvirtualmachinesresponse']['virtualmachine'].first['name']
44
+ instance_ip = response['listvirtualmachinesresponse']['virtualmachine'].first['nic'].first['ipaddress']
45
+ real_instance_id = response['listvirtualmachinesresponse']['virtualmachine'].first['id']
46
+ puts "#{ui.color("Name", :red)}: #{instance_name}"
47
+ puts "#{ui.color("Public IP", :red)}: #{instance_ip}"
48
+ puts "\n"
49
+ confirm("#{ui.color("Do you really want to stop this server", :red)}")
50
+
51
+
52
+ if locate_config_value(:force)
53
+ server = connection.stop_virtual_machine('id' => real_instance_id, 'forced' => true)
54
+ else
55
+ server = connection.stop_virtual_machine('id' => real_instance_id)
56
+ end
57
+ jobid = server['stopvirtualmachineresponse'].fetch('jobid')
58
+
59
+ jobs[instance_id] = jobid
60
+ end
61
+
62
+
63
+ print "#{ui.color("Waiting for servers", :magenta)}"
64
+ until jobs.empty?
65
+ jobs.each do |instance_id, jobid|
66
+ server_stop = connection.query_async_job_result('jobid'=>jobid)
67
+
68
+ if server_stop['queryasyncjobresultresponse'].fetch('jobstatus') == 1
69
+ jobs.delete(instance_id)
70
+
71
+ puts "\n\n"
72
+ ui.warn("Stopped server #{instance_id}")
73
+ else
74
+ print "#{ui.color(".", :magenta)}"
75
+ sleep(1)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,61 +1,61 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2012 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackServiceofferingList < Knife
24
-
25
- include Knife::CloudstackBase
26
-
27
- banner "knife cloudstack serviceoffering list"
28
-
29
- def run
30
- $stdout.sync = true
31
-
32
- validate!
33
-
34
- serviceoffering_list = [
35
- ui.color('ID', :bold),
36
- ui.color('Name', :bold),
37
- ui.color('Description', :bold),
38
- ui.color('Number of CPUs', :bold),
39
- ui.color('CPU Speed', :bold),
40
- ui.color('Memory (in MB)', :bold),
41
- ui.color('Network Speed', :bold)
42
- ]
43
- response = connection.list_service_offerings['listserviceofferingsresponse']
44
- if serviceofferings = response['serviceoffering']
45
- serviceofferings.each do |serviceoffering|
46
- serviceoffering_list << serviceoffering['id'].to_s
47
- serviceoffering_list << serviceoffering['name'].to_s
48
- serviceoffering_list << serviceoffering['displaytext'].to_s
49
- serviceoffering_list << serviceoffering['cpunumber'].to_s
50
- serviceoffering_list << serviceoffering['cpuspeed'].to_s
51
- serviceoffering_list << serviceoffering['memory'].to_s
52
- serviceoffering_list << serviceoffering['networkrate'].to_s
53
- end
54
- end
55
- puts ui.list(serviceoffering_list, :uneven_columns_across, 7)
56
-
57
- end
58
-
59
- end
60
- end
61
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackServiceofferingList < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack serviceoffering list"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ serviceoffering_list = [
35
+ ui.color('ID', :bold),
36
+ ui.color('Name', :bold),
37
+ ui.color('Description', :bold),
38
+ ui.color('Number of CPUs', :bold),
39
+ ui.color('CPU Speed', :bold),
40
+ ui.color('Memory (in MB)', :bold),
41
+ ui.color('Network Speed', :bold)
42
+ ]
43
+ response = connection.list_service_offerings['listserviceofferingsresponse']
44
+ if serviceofferings = response['serviceoffering']
45
+ serviceofferings.each do |serviceoffering|
46
+ serviceoffering_list << serviceoffering['id'].to_s
47
+ serviceoffering_list << serviceoffering['name'].to_s
48
+ serviceoffering_list << serviceoffering['displaytext'].to_s
49
+ serviceoffering_list << serviceoffering['cpunumber'].to_s
50
+ serviceoffering_list << serviceoffering['cpuspeed'].to_s
51
+ serviceoffering_list << serviceoffering['memory'].to_s
52
+ serviceoffering_list << serviceoffering['networkrate'].to_s
53
+ end
54
+ end
55
+ puts ui.list(serviceoffering_list, :uneven_columns_across, 7)
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -1,127 +1,127 @@
1
- # Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>), dfuentes77
2
- # Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
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
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackTemplateList < Knife
24
-
25
- include Knife::CloudstackBase
26
-
27
- banner "knife cloudstack template list (options)"
28
- option :filter,
29
- :short => "-L FILTER",
30
- :long => "--filter FILTER",
31
- :description => "The template search filter. Default is 'featured.' Other options are 'self,' 'self-executable,' 'executable,' and 'community.'",
32
- :default => "featured"
33
- option :zone,
34
- :short => "-Z ZONE",
35
- :long => "--zone ZONE",
36
- :description => "Limit responses to templates only located in a specific zone. Default provides templates from all zones.",
37
- :default => "all"
38
- option :hypervisor,
39
- :short => "-H HYPERVISOR",
40
- :long => "--hypervisor HYPERVISOR",
41
- :description => "Limit responses to templates only running on a specific hypervisor. Default provides templates from all hypervisors.",
42
- :default => "all"
43
- option :zoneid,
44
- :short => "-z ZONEID",
45
- :long => "--zoneid ZONEID",
46
- :description => "Limit responses to templates only running in a specific zone (specified by ID #). Default provides templates from all zones.",
47
- :default => "all"
48
- option :templateid,
49
- :short => "-T TEMPLATEID",
50
- :long => "--templateid TEMPLATEID",
51
- :description => "Limit responses to a single template ID. Default provides all templates.",
52
- :default => "all"
53
-
54
-
55
- def print_templates(template_list,templates,options={})
56
- temp = templates
57
-
58
- if templateid = options[:templateid]
59
- temp.reject!{|t| t['id'] != templateid}
60
- end
61
- if zoneid = options[:zoneid]
62
- temp.reject!{|t| t['zoneid'] != zoneid}
63
- end
64
- if zone = options[:zone]
65
- temp.reject!{|t| t['zonename'] != zone}
66
- end
67
- if hypervisor = options[:hypervisor]
68
- temp.reject!{|t| t['hypervisor'] != hypervisor}
69
- end
70
-
71
- # Sorting to group by zone ID first, then ID
72
-
73
- sort1 = temp.sort_by { |hsh| hsh["id"] }
74
- sorted = sort1.sort_by { |hsh| hsh["zoneid"] }
75
-
76
- sorted.each do |template|
77
- template_list << template['id'].to_s
78
- template['hypervisor'] = ' ' if template['hypervisor'].nil?
79
- template_list << template['hypervisor']
80
-
81
- template_size = template['size']
82
- template_size = (template_size/1024/1024/1024)
83
- template_list << template_size.to_s
84
-
85
- template_list << template['zonename']
86
- template_list << template['zoneid'].to_s
87
- template_list << template['name']
88
- end
89
- end
90
-
91
- def run
92
- validate!
93
-
94
- template_list = [
95
- ui.color('ID', :bold),
96
- ui.color('Hypervisor', :bold),
97
- ui.color('Size (in GB)', :bold),
98
- ui.color('Zone Name', :bold),
99
- ui.color('Zone ID', :bold),
100
- ui.color('Name', :bold)
101
- ]
102
-
103
- filter = locate_config_value(:filter)
104
- zone = locate_config_value(:zone)
105
- zoneid = locate_config_value(:zoneid)
106
- hypervisor = locate_config_value(:hypervisor)
107
- templateid = locate_config_value(:templateid)
108
-
109
- settings = connection.list_templates('templatefilter' => filter)
110
- if response = settings['listtemplatesresponse']
111
- Chef::Log.debug("Response: #{response}")
112
- if templates = response['template']
113
- filters = {}
114
- filters[:hypervisor] = hypervisor unless hypervisor == 'all'
115
- filters[:zone] = zone unless zone == 'all'
116
- filters[:zoneid] = zoneid unless zoneid == 'all'
117
- filters[:templateid] = templateid unless templateid == 'all'
118
-
119
- print_templates(template_list,templates,filters)
120
- end
121
- puts ui.list(template_list, :uneven_columns_across, 6)
122
- end
123
-
124
- end
125
- end
126
- end
127
- end
1
+ # Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>), dfuentes77
2
+ # Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
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
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackTemplateList < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack template list (options)"
28
+ option :filter,
29
+ :short => "-L FILTER",
30
+ :long => "--filter FILTER",
31
+ :description => "The template search filter. Default is 'featured.' Other options are 'self,' 'self-executable,' 'executable,' and 'community.'",
32
+ :default => "featured"
33
+ option :zone,
34
+ :short => "-Z ZONE",
35
+ :long => "--zone ZONE",
36
+ :description => "Limit responses to templates only located in a specific zone. Default provides templates from all zones.",
37
+ :default => "all"
38
+ option :hypervisor,
39
+ :short => "-H HYPERVISOR",
40
+ :long => "--hypervisor HYPERVISOR",
41
+ :description => "Limit responses to templates only running on a specific hypervisor. Default provides templates from all hypervisors.",
42
+ :default => "all"
43
+ option :zoneid,
44
+ :short => "-z ZONEID",
45
+ :long => "--zoneid ZONEID",
46
+ :description => "Limit responses to templates only running in a specific zone (specified by ID #). Default provides templates from all zones.",
47
+ :default => "all"
48
+ option :templateid,
49
+ :short => "-T TEMPLATEID",
50
+ :long => "--templateid TEMPLATEID",
51
+ :description => "Limit responses to a single template ID. Default provides all templates.",
52
+ :default => "all"
53
+
54
+
55
+ def print_templates(template_list,templates,options={})
56
+ temp = templates
57
+
58
+ if templateid = options[:templateid]
59
+ temp.reject!{|t| t['id'] != templateid}
60
+ end
61
+ if zoneid = options[:zoneid]
62
+ temp.reject!{|t| t['zoneid'] != zoneid}
63
+ end
64
+ if zone = options[:zone]
65
+ temp.reject!{|t| t['zonename'] != zone}
66
+ end
67
+ if hypervisor = options[:hypervisor]
68
+ temp.reject!{|t| t['hypervisor'] != hypervisor}
69
+ end
70
+
71
+ # Sorting to group by zone ID first, then ID
72
+
73
+ sort1 = temp.sort_by { |hsh| hsh["id"] }
74
+ sorted = sort1.sort_by { |hsh| hsh["zoneid"] }
75
+
76
+ sorted.each do |template|
77
+ template_list << template['id'].to_s
78
+ template['hypervisor'] = ' ' if template['hypervisor'].nil?
79
+ template_list << template['hypervisor']
80
+
81
+ template_size = template['size']
82
+ template_size = (template_size/1024/1024/1024)
83
+ template_list << template_size.to_s
84
+
85
+ template_list << template['zonename']
86
+ template_list << template['zoneid'].to_s
87
+ template_list << template['name']
88
+ end
89
+ end
90
+
91
+ def run
92
+ validate!
93
+
94
+ template_list = [
95
+ ui.color('ID', :bold),
96
+ ui.color('Hypervisor', :bold),
97
+ ui.color('Size (in GB)', :bold),
98
+ ui.color('Zone Name', :bold),
99
+ ui.color('Zone ID', :bold),
100
+ ui.color('Name', :bold)
101
+ ]
102
+
103
+ filter = locate_config_value(:filter)
104
+ zone = locate_config_value(:zone)
105
+ zoneid = locate_config_value(:zoneid)
106
+ hypervisor = locate_config_value(:hypervisor)
107
+ templateid = locate_config_value(:templateid)
108
+
109
+ settings = connection.list_templates('templatefilter' => filter)
110
+ if response = settings['listtemplatesresponse']
111
+ Chef::Log.debug("Response: #{response}")
112
+ if templates = response['template']
113
+ filters = {}
114
+ filters[:hypervisor] = hypervisor unless hypervisor == 'all'
115
+ filters[:zone] = zone unless zone == 'all'
116
+ filters[:zoneid] = zoneid unless zoneid == 'all'
117
+ filters[:templateid] = templateid unless templateid == 'all'
118
+
119
+ print_templates(template_list,templates,filters)
120
+ end
121
+ puts ui.list(template_list, :uneven_columns_across, 6)
122
+ end
123
+
124
+ end
125
+ end
126
+ end
127
+ end