ucloudstack 0.0.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.
- data/CHANGES.rdoc +68 -0
- data/LICENSE +202 -0
- data/README.rdoc +215 -0
- data/lib/chef/knife/cs_hosts.rb +83 -0
- data/lib/chef/knife/cs_network_list.rb +84 -0
- data/lib/chef/knife/cs_product_list.rb +70 -0
- data/lib/chef/knife/cs_server_create.rb +321 -0
- data/lib/chef/knife/cs_server_delete.rb +157 -0
- data/lib/chef/knife/cs_server_list.rb +92 -0
- data/lib/chef/knife/cs_server_reboot.rb +103 -0
- data/lib/chef/knife/cs_server_start.rb +103 -0
- data/lib/chef/knife/cs_server_stop.rb +114 -0
- data/lib/chef/knife/cs_service_list.rb +93 -0
- data/lib/chef/knife/cs_stack_create.rb +325 -0
- data/lib/chef/knife/cs_stack_delete.rb +88 -0
- data/lib/chef/knife/cs_template_list.rb +100 -0
- data/lib/chef/knife/cs_zone_list.rb +78 -0
- data/lib/knife-cloudstack/connection.rb +633 -0
- metadata +90 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ryan Holmes (<rholmes@edmunds.com>)
|
3
|
+
# Author:: KC Braunschweig (<kbraunschweig@edmunds.com>)
|
4
|
+
# Copyright:: Copyright (c) 2011 Edmunds, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife'
|
21
|
+
|
22
|
+
module KnifeCloudstack
|
23
|
+
class CsServerReboot < Chef::Knife
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'knife-cloudstack/connection'
|
27
|
+
require 'chef/api_client'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife cs server reboot SERVER_NAME [SERVER_NAME ...] (options)"
|
31
|
+
|
32
|
+
option :cloudstack_url,
|
33
|
+
:short => "-U URL",
|
34
|
+
:long => "--cloudstack-url URL",
|
35
|
+
:description => "The CloudStack endpoint URL",
|
36
|
+
:proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
|
37
|
+
|
38
|
+
option :cloudstack_api_key,
|
39
|
+
:short => "-A KEY",
|
40
|
+
:long => "--cloudstack-api-key KEY",
|
41
|
+
:description => "Your CloudStack API key",
|
42
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
|
43
|
+
|
44
|
+
option :cloudstack_secret_key,
|
45
|
+
:short => "-K SECRET",
|
46
|
+
:long => "--cloudstack-secret-key SECRET",
|
47
|
+
:description => "Your CloudStack secret key",
|
48
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
|
49
|
+
|
50
|
+
def run
|
51
|
+
|
52
|
+
@name_args.each do |hostname|
|
53
|
+
server = connection.get_server(hostname)
|
54
|
+
|
55
|
+
if !server then
|
56
|
+
ui.error("Server '#{hostname}' not found")
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "\n"
|
61
|
+
msg("Name", server['name'])
|
62
|
+
msg("Public IP", connection.get_server_public_ip(server) || '?')
|
63
|
+
msg("Service", server['serviceofferingname'])
|
64
|
+
msg("Template", server['templatename'])
|
65
|
+
msg("Domain", server['domain'])
|
66
|
+
msg("Zone", server['zonename'])
|
67
|
+
msg("State", server['state'])
|
68
|
+
|
69
|
+
puts "\n"
|
70
|
+
ui.confirm("Do you really want to reboot this server")
|
71
|
+
print "#{ui.color("Rebooting", :magenta)}"
|
72
|
+
|
73
|
+
connection.reboot_server(hostname)
|
74
|
+
puts "\n"
|
75
|
+
ui.msg("Rebooted server #{hostname}")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def connection
|
81
|
+
unless @connection
|
82
|
+
@connection = CloudstackClient::Connection.new(
|
83
|
+
locate_config_value(:cloudstack_url),
|
84
|
+
locate_config_value(:cloudstack_api_key),
|
85
|
+
locate_config_value(:cloudstack_secret_key)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
@connection
|
89
|
+
end
|
90
|
+
|
91
|
+
def msg(label, value)
|
92
|
+
if value && !value.empty?
|
93
|
+
puts "#{ui.color(label, :cyan)}: #{value}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def locate_config_value(key)
|
98
|
+
key = key.to_sym
|
99
|
+
Chef::Config[:knife][key] || config[key]
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ryan Holmes (<rholmes@edmunds.com>)
|
3
|
+
# Author:: KC Braunschweig (<kbraunschweig@edmunds.com>)
|
4
|
+
# Copyright:: Copyright (c) 2011 Edmunds, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife'
|
21
|
+
|
22
|
+
module KnifeCloudstack
|
23
|
+
class CsServerStart < Chef::Knife
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'knife-cloudstack/connection'
|
27
|
+
require 'chef/api_client'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife cs server start SERVER_NAME [SERVER_NAME ...] (options)"
|
31
|
+
|
32
|
+
option :cloudstack_url,
|
33
|
+
:short => "-U URL",
|
34
|
+
:long => "--cloudstack-url URL",
|
35
|
+
:description => "The CloudStack endpoint URL",
|
36
|
+
:proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
|
37
|
+
|
38
|
+
option :cloudstack_api_key,
|
39
|
+
:short => "-A KEY",
|
40
|
+
:long => "--cloudstack-api-key KEY",
|
41
|
+
:description => "Your CloudStack API key",
|
42
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
|
43
|
+
|
44
|
+
option :cloudstack_secret_key,
|
45
|
+
:short => "-K SECRET",
|
46
|
+
:long => "--cloudstack-secret-key SECRET",
|
47
|
+
:description => "Your CloudStack secret key",
|
48
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
|
49
|
+
|
50
|
+
def run
|
51
|
+
|
52
|
+
@name_args.each do |hostname|
|
53
|
+
server = connection.get_server(hostname)
|
54
|
+
|
55
|
+
if !server then
|
56
|
+
ui.error("Server '#{hostname}' not found")
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "\n"
|
61
|
+
msg("Name", server['name'])
|
62
|
+
msg("Public IP", connection.get_server_public_ip(server) || '?')
|
63
|
+
msg("Service", server['serviceofferingname'])
|
64
|
+
msg("Template", server['templatename'])
|
65
|
+
msg("Domain", server['domain'])
|
66
|
+
msg("Zone", server['zonename'])
|
67
|
+
msg("State", server['state'])
|
68
|
+
|
69
|
+
puts "\n"
|
70
|
+
ui.confirm("Do you really want to start this server")
|
71
|
+
|
72
|
+
print "#{ui.color("Waiting for startup", :magenta)}"
|
73
|
+
connection.start_server(hostname)
|
74
|
+
puts "\n"
|
75
|
+
ui.msg("Started server #{hostname}")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def connection
|
81
|
+
unless @connection
|
82
|
+
@connection = CloudstackClient::Connection.new(
|
83
|
+
locate_config_value(:cloudstack_url),
|
84
|
+
locate_config_value(:cloudstack_api_key),
|
85
|
+
locate_config_value(:cloudstack_secret_key)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
@connection
|
89
|
+
end
|
90
|
+
|
91
|
+
def msg(label, value)
|
92
|
+
if value && !value.empty?
|
93
|
+
puts "#{ui.color(label, :cyan)}: #{value}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def locate_config_value(key)
|
98
|
+
key = key.to_sym
|
99
|
+
Chef::Config[:knife][key] || config[key]
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ryan Holmes (<rholmes@edmunds.com>)
|
3
|
+
# Author:: KC Braunschweig (<kbraunschweig@edmunds.com>)
|
4
|
+
# Copyright:: Copyright (c) 2011 Edmunds, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife'
|
21
|
+
|
22
|
+
module KnifeCloudstack
|
23
|
+
class CsServerStop < Chef::Knife
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'knife-cloudstack/connection'
|
27
|
+
require 'chef/api_client'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife cs server stop SERVER_NAME [SERVER_NAME ...] (options)"
|
31
|
+
|
32
|
+
option :cloudstack_url,
|
33
|
+
:short => "-U URL",
|
34
|
+
:long => "--cloudstack-url URL",
|
35
|
+
:description => "The CloudStack endpoint URL",
|
36
|
+
:proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
|
37
|
+
|
38
|
+
option :cloudstack_api_key,
|
39
|
+
:short => "-A KEY",
|
40
|
+
:long => "--cloudstack-api-key KEY",
|
41
|
+
:description => "Your CloudStack API key",
|
42
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
|
43
|
+
|
44
|
+
option :cloudstack_secret_key,
|
45
|
+
:short => "-K SECRET",
|
46
|
+
:long => "--cloudstack-secret-key SECRET",
|
47
|
+
:description => "Your CloudStack secret key",
|
48
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
|
49
|
+
|
50
|
+
option :cloudstack_force_stop,
|
51
|
+
:long => "--force",
|
52
|
+
:description => "Force stop the VM. The caller knows the VM is stopped.",
|
53
|
+
:boolean => true
|
54
|
+
|
55
|
+
def run
|
56
|
+
|
57
|
+
@name_args.each do |hostname|
|
58
|
+
server = connection.get_server(hostname)
|
59
|
+
|
60
|
+
if !server then
|
61
|
+
ui.error("Server '#{hostname}' not found")
|
62
|
+
next
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "\n"
|
66
|
+
msg("Name", server['name'])
|
67
|
+
msg("Public IP", connection.get_server_public_ip(server) || '?')
|
68
|
+
msg("Service", server['serviceofferingname'])
|
69
|
+
msg("Template", server['templatename'])
|
70
|
+
msg("Domain", server['domain'])
|
71
|
+
msg("Zone", server['zonename'])
|
72
|
+
msg("State", server['state'])
|
73
|
+
|
74
|
+
puts "\n"
|
75
|
+
if config[:cloudstack_force_stop]
|
76
|
+
ui.confirm("Do you really want to force stop this server")
|
77
|
+
print "#{ui.color("Forcefully stopping", :magenta)}"
|
78
|
+
connection.stop_server(hostname,config[:cloudstack_force_stop])
|
79
|
+
else
|
80
|
+
ui.confirm("Do you really want to stop this server")
|
81
|
+
print "#{ui.color("Stopping", :magenta)}"
|
82
|
+
connection.stop_server(hostname)
|
83
|
+
end
|
84
|
+
|
85
|
+
puts "\n"
|
86
|
+
ui.msg("Stopped server #{hostname}")
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def connection
|
92
|
+
unless @connection
|
93
|
+
@connection = CloudstackClient::Connection.new(
|
94
|
+
locate_config_value(:cloudstack_url),
|
95
|
+
locate_config_value(:cloudstack_api_key),
|
96
|
+
locate_config_value(:cloudstack_secret_key)
|
97
|
+
)
|
98
|
+
end
|
99
|
+
@connection
|
100
|
+
end
|
101
|
+
|
102
|
+
def msg(label, value)
|
103
|
+
if value && !value.empty?
|
104
|
+
puts "#{ui.color(label, :cyan)}: #{value}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def locate_config_value(key)
|
109
|
+
key = key.to_sym
|
110
|
+
Chef::Config[:knife][key] || config[key]
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ryan Holmes (<rholmes@edmunds.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Edmunds, Inc.
|
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
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
module KnifeCloudstack
|
22
|
+
class CsServiceList < Chef::Knife
|
23
|
+
|
24
|
+
MEGABYTES = 1024 * 1024
|
25
|
+
|
26
|
+
deps do
|
27
|
+
require 'knife-cloudstack/connection'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife cs service list (options)"
|
31
|
+
|
32
|
+
option :cloudstack_url,
|
33
|
+
:short => "-U URL",
|
34
|
+
:long => "--cloudstack-url URL",
|
35
|
+
:description => "The CloudStack endpoint URL",
|
36
|
+
:proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
|
37
|
+
|
38
|
+
option :cloudstack_api_key,
|
39
|
+
:short => "-A KEY",
|
40
|
+
:long => "--cloudstack-api-key KEY",
|
41
|
+
:description => "Your CloudStack API key",
|
42
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
|
43
|
+
|
44
|
+
option :cloudstack_secret_key,
|
45
|
+
:short => "-K SECRET",
|
46
|
+
:long => "--cloudstack-secret-key SECRET",
|
47
|
+
:description => "Your CloudStack secret key",
|
48
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
|
49
|
+
|
50
|
+
def run
|
51
|
+
|
52
|
+
connection = CloudstackClient::Connection.new(
|
53
|
+
locate_config_value(:cloudstack_url),
|
54
|
+
locate_config_value(:cloudstack_api_key),
|
55
|
+
locate_config_value(:cloudstack_secret_key)
|
56
|
+
)
|
57
|
+
|
58
|
+
service_list = [
|
59
|
+
ui.color('Name', :bold),
|
60
|
+
ui.color('Memory', :bold),
|
61
|
+
ui.color('CPUs', :bold),
|
62
|
+
ui.color('CPU Speed', :bold),
|
63
|
+
ui.color('Created', :bold)
|
64
|
+
]
|
65
|
+
|
66
|
+
services = connection.list_service_offerings
|
67
|
+
services.each do |s|
|
68
|
+
service_list << s['name']
|
69
|
+
service_list << (human_memory(s['memory']) || 'Unknown')
|
70
|
+
service_list << s['cpunumber'].to_s
|
71
|
+
service_list << s['cpuspeed'].to_s + ' Mhz'
|
72
|
+
service_list << s['created']
|
73
|
+
end
|
74
|
+
puts ui.list(service_list, :columns_across, 5)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def human_memory n
|
79
|
+
count = 0
|
80
|
+
while n >= 1024 and count < 2
|
81
|
+
n /= 1024.0
|
82
|
+
count += 1
|
83
|
+
end
|
84
|
+
format("%.2f", n) + %w(MB GB TB)[count]
|
85
|
+
end
|
86
|
+
|
87
|
+
def locate_config_value(key)
|
88
|
+
key = key.to_sym
|
89
|
+
Chef::Config[:knife][key] || config[key]
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|