knife-cosmic 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.rdoc +186 -0
  3. data/LICENSE +202 -0
  4. data/README.rdoc +427 -0
  5. data/lib/chef/knife/cosmic_aag_list.rb +58 -0
  6. data/lib/chef/knife/cosmic_account_list.rb +87 -0
  7. data/lib/chef/knife/cosmic_base.rb +108 -0
  8. data/lib/chef/knife/cosmic_baselist.rb +111 -0
  9. data/lib/chef/knife/cosmic_cluster_list.rb +60 -0
  10. data/lib/chef/knife/cosmic_config_list.rb +56 -0
  11. data/lib/chef/knife/cosmic_disk_list.rb +58 -0
  12. data/lib/chef/knife/cosmic_domain_list.rb +53 -0
  13. data/lib/chef/knife/cosmic_firewallrule_create.rb +138 -0
  14. data/lib/chef/knife/cosmic_firewallrule_list.rb +62 -0
  15. data/lib/chef/knife/cosmic_forwardrule_create.rb +145 -0
  16. data/lib/chef/knife/cosmic_host_list.rb +61 -0
  17. data/lib/chef/knife/cosmic_hosts.rb +58 -0
  18. data/lib/chef/knife/cosmic_iso_list.rb +89 -0
  19. data/lib/chef/knife/cosmic_keypair_create.rb +72 -0
  20. data/lib/chef/knife/cosmic_keypair_delete.rb +60 -0
  21. data/lib/chef/knife/cosmic_keypair_list.rb +44 -0
  22. data/lib/chef/knife/cosmic_network_list.rb +63 -0
  23. data/lib/chef/knife/cosmic_oscategory_list.rb +50 -0
  24. data/lib/chef/knife/cosmic_ostype_list.rb +52 -0
  25. data/lib/chef/knife/cosmic_pod_list.rb +60 -0
  26. data/lib/chef/knife/cosmic_project_list.rb +63 -0
  27. data/lib/chef/knife/cosmic_publicip_list.rb +55 -0
  28. data/lib/chef/knife/cosmic_router_list.rb +64 -0
  29. data/lib/chef/knife/cosmic_securitygroup_list.rb +59 -0
  30. data/lib/chef/knife/cosmic_server_add_nic.rb +109 -0
  31. data/lib/chef/knife/cosmic_server_create.rb +674 -0
  32. data/lib/chef/knife/cosmic_server_delete.rb +153 -0
  33. data/lib/chef/knife/cosmic_server_list.rb +167 -0
  34. data/lib/chef/knife/cosmic_server_passwordreset.rb +91 -0
  35. data/lib/chef/knife/cosmic_server_reboot.rb +99 -0
  36. data/lib/chef/knife/cosmic_server_remove_nic.rb +101 -0
  37. data/lib/chef/knife/cosmic_server_start.rb +104 -0
  38. data/lib/chef/knife/cosmic_server_stop.rb +118 -0
  39. data/lib/chef/knife/cosmic_server_update.rb +47 -0
  40. data/lib/chef/knife/cosmic_service_list.rb +74 -0
  41. data/lib/chef/knife/cosmic_stack_create.rb +298 -0
  42. data/lib/chef/knife/cosmic_stack_delete.rb +79 -0
  43. data/lib/chef/knife/cosmic_template_create.rb +129 -0
  44. data/lib/chef/knife/cosmic_template_extract.rb +104 -0
  45. data/lib/chef/knife/cosmic_template_list.rb +88 -0
  46. data/lib/chef/knife/cosmic_template_register.rb +187 -0
  47. data/lib/chef/knife/cosmic_user_list.rb +62 -0
  48. data/lib/chef/knife/cosmic_volume_attach.rb +70 -0
  49. data/lib/chef/knife/cosmic_volume_create.rb +108 -0
  50. data/lib/chef/knife/cosmic_volume_delete.rb +97 -0
  51. data/lib/chef/knife/cosmic_volume_detach.rb +61 -0
  52. data/lib/chef/knife/cosmic_volume_list.rb +77 -0
  53. data/lib/chef/knife/cosmic_zone_list.rb +53 -0
  54. data/lib/knife-cosmic/connection.rb +1046 -0
  55. metadata +127 -0
@@ -0,0 +1,153 @@
1
+ #
2
+ # Original knife-cloudstack author:: Ryan Holmes (<rholmes@edmunds.com>)
3
+ # Original knife-cloudstack author:: Sander Botman (<sbotman@schubergphilis.com>)
4
+ # Copyright:: Copyright (c) 2011 Edmunds, Inc.
5
+ # Copyright:: Copyright (c) 2013 Sander Botman.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'chef/knife/cosmic_base'
22
+
23
+ module Knifecosmic
24
+ class CosmicServerDelete < Chef::Knife
25
+
26
+ include Chef::Knife::KnifecosmicBase
27
+
28
+ deps do
29
+ require 'knife-cosmic/connection'
30
+ require 'chef/api_client'
31
+ require 'chef/knife'
32
+ Chef::Knife.load_deps
33
+ end
34
+
35
+ banner "knife cosmic server delete SERVER_NAME [SERVER_NAME ...] (options)"
36
+
37
+ option :chefserver,
38
+ :long => "--[no-]chefserver",
39
+ :description => "Skip Chef server node/client deletion",
40
+ :boolean => true,
41
+ :default => true
42
+
43
+ def run
44
+ validate_base_options
45
+
46
+ @name_args.each do |hostname|
47
+ server = connection.get_server(hostname)
48
+
49
+ if !server then
50
+ ui.error("Server '#{hostname}' not found")
51
+ next
52
+ end
53
+
54
+ if server['state'] == 'Destroyed' then
55
+ ui.warn("Server '#{hostname}' already destroyed")
56
+ connection.delete_server(hostname, true) if confirm_action("Server '#{hostname}' already destroyed, do you want to expunge it?")
57
+ next
58
+ end
59
+
60
+ rules = connection.list_port_forwarding_rules
61
+
62
+ show_object_details(server, connection, rules)
63
+
64
+ result = confirm_action("Do you really want to delete this server")
65
+ if result
66
+ print "#{ui.color("Waiting for deletion", :magenta)}"
67
+ disassociate_virtual_ip_address server
68
+ connection.delete_server(hostname, false)
69
+ puts "\n"
70
+ ui.msg("Deleted server #{hostname}")
71
+
72
+ # delete chef client and node
73
+ node_name = hostname # connection.get_server_fqdn server ## server create doesn't add fqdn!
74
+ delete_chef = locate_config_value(:chefserver) ? confirm_action("Do you want to delete the chef node and client '#{node_name}'") : false
75
+ if delete_chef
76
+ delete_node node_name
77
+ delete_client node_name
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+
84
+ def show_object_details(s, connection, rules)
85
+ return if locate_config_value(:yes)
86
+
87
+ object_fields = []
88
+ object_fields << ui.color("Name:", :cyan)
89
+ object_fields << s['name'].to_s
90
+ object_fields << ui.color("Public IP:", :cyan)
91
+ object_fields << (connection.get_server_public_ip(s, rules) || '')
92
+ object_fields << ui.color("Service:", :cyan)
93
+ object_fields << s['serviceofferingname'].to_s
94
+ object_fields << ui.color("Template:", :cyan)
95
+ object_fields << s['templatename']
96
+ object_fields << ui.color("Domain:", :cyan)
97
+ object_fields << s['domain']
98
+ object_fields << ui.color("Zone:", :cyan)
99
+ object_fields << s['zonename']
100
+ object_fields << ui.color("State:", :cyan)
101
+ object_fields << s['state']
102
+
103
+ puts "\n"
104
+ puts ui.list(object_fields, :uneven_columns_across, 2)
105
+ puts "\n"
106
+ end
107
+
108
+ def confirm_action(question)
109
+ return true if locate_config_value(:yes)
110
+ result = ui.ask_question(question, :default => "Y" )
111
+ if result == "Y" || result == "y" then
112
+ return true
113
+ else
114
+ return false
115
+ end
116
+ end
117
+
118
+ def disassociate_virtual_ip_address(server)
119
+ ip_addr = connection.get_server_public_ip(server)
120
+ return unless ip_addr
121
+ ip_addr_info = connection.get_public_ip_address(ip_addr)
122
+ #Check if Public IP has been allocated and is not Source NAT
123
+ if ip_addr_info
124
+ if not ip_addr_info['issourcenat']
125
+ connection.disassociate_ip_address(ip_addr_info['id'])
126
+ end
127
+ end
128
+ end
129
+
130
+ def delete_client(name)
131
+ begin
132
+ client = Chef::ApiClient.load(name)
133
+ rescue Net::HTTPServerException
134
+ return
135
+ end
136
+
137
+ client.destroy
138
+ ui.msg "Deleted client #{name}"
139
+ end
140
+
141
+ def delete_node(name)
142
+ begin
143
+ node = Chef::Node.load(name)
144
+ rescue Net::HTTPServerException
145
+ return
146
+ end
147
+
148
+ node.destroy
149
+ ui.msg "Deleted node #{name}"
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1,167 @@
1
+ #
2
+ # Original knife-cloudstack author:: Ryan Holmes (<rholmes@edmunds.com>)
3
+ # Original knife-cloudstack author:: Sander Botman (<sbotman@schubergphilis.com>)
4
+ # Copyright:: Copyright (c) 2011 Edmunds, Inc.
5
+ # Copyright:: Copyright (c) 2013 Sander Botman.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'chef/knife'
22
+ require 'chef/knife/cosmic_baselist'
23
+
24
+ module Knifecosmic
25
+ class CosmicServerList < Chef::Knife
26
+
27
+ include Chef::Knife::KnifecosmicBaseList
28
+
29
+ banner "knife cosmic server list (options)"
30
+
31
+ option :listall,
32
+ :long => "--listall",
33
+ :description => "List all the accounts",
34
+ :boolean => true
35
+
36
+ option :name,
37
+ :long => "--name NAME",
38
+ :description => "Specify hostname to list"
39
+
40
+ option :keyword,
41
+ :long => "--keyword NAME",
42
+ :description => "Specify part of instancename to list"
43
+
44
+ option :action,
45
+ :short => "-a ACTION",
46
+ :long => "--action ACTION",
47
+ :description => "start, stop or destroy the instances in your result"
48
+
49
+ option :expunge,
50
+ :long => "--expunge",
51
+ :description => "If used with --action destroy, will cause the server to be expunged"
52
+ option :public_ip,
53
+ :long => "--[no-]public-ip",
54
+ :description => "Show or don't show the public IP for server in your result",
55
+ :boolean => true,
56
+ :default => true
57
+
58
+ def run
59
+ validate_base_options
60
+
61
+ columns = [
62
+ 'Name :name',
63
+ 'Public IP :ipaddress',
64
+ 'Service :serviceofferingname',
65
+ 'Template :templatename',
66
+ 'State :state',
67
+ 'Instance :instancename',
68
+ 'Hypervisor :hostname'
69
+ ]
70
+
71
+ params = { 'command' => "listVirtualMachines" }
72
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
73
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
74
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
75
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
76
+ params['expunge'] = locate_config_value(:expunge) if locate_config_value(:expunge)
77
+ params['expunge'] = false if params['expunge'].nil?
78
+
79
+ ##
80
+ # Get the public IP address if possible, except when the option --no-public-ip is given.
81
+
82
+ rules = connection.list_port_forwarding_rules(nil, true)
83
+ public_list = connection.list_public_ip_addresses(true)
84
+ result = connection.list_object(params, "virtualmachine")
85
+ result.each do |n|
86
+ public_ip = connection.get_server_public_ip(n, rules, public_list) if locate_config_value(:public_ip)
87
+ private_ip = (n['nic'].select { |k| k['isdefault'] }).first
88
+ public_ip ? n['ipaddress'] = public_ip : n['ipaddress'] = private_ip['ipaddress'] || "N/A"
89
+ end
90
+
91
+ list_object(columns, result)
92
+
93
+ ##
94
+ # Executing actions against the list results that are returned.
95
+
96
+ if locate_config_value(:action)
97
+ result.each do |r|
98
+ hostname = r['name']
99
+ case locate_config_value(:action).downcase
100
+ when "start" then
101
+ show_object_details(r, connection, rules)
102
+ result = confirm_action("Do you really want to start this server ")
103
+ if result then
104
+ print "#{ui.color("Waiting for startup", :magenta)}"
105
+ connection.start_server(hostname)
106
+ puts "\n"
107
+ ui.msg("Started server #{hostname}")
108
+ end
109
+ when "stop" then
110
+ show_object_details(r, connection, rules)
111
+ result = confirm_action("Do you really want to stop this server ")
112
+ if result then
113
+ print "#{ui.color("Waiting for shutdown", :magenta)}"
114
+ connection.stop_server(hostname)
115
+ puts "\n"
116
+ ui.msg("Shutdown server #{hostname}")
117
+ end
118
+ when "destroy" then
119
+ show_object_details(r, connection, rules)
120
+ result = confirm_action("Do you really want to destroy this server ")
121
+ if result then
122
+ print "#{ui.color("Waiting for demolition", :magenta)}"
123
+ connection.delete_server(hostname, params['expunge'])
124
+ puts "\n"
125
+ ui.msg("Destroyed server #{hostname}")
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ def show_object_details(s, connection, rules)
133
+ return if locate_config_value(:yes)
134
+
135
+ object_fields = []
136
+ object_fields << ui.color("Name:", :cyan)
137
+ object_fields << s['name'].to_s
138
+ object_fields << ui.color("Public IP:", :cyan)
139
+ object_fields << (connection.get_server_public_ip(s, rules) || '')
140
+ object_fields << ui.color("Service:", :cyan)
141
+ object_fields << s['serviceofferingname'].to_s
142
+ object_fields << ui.color("Template:", :cyan)
143
+ object_fields << s['templatename']
144
+ object_fields << ui.color("Domain:", :cyan)
145
+ object_fields << s['domain']
146
+ object_fields << ui.color("Zone:", :cyan)
147
+ object_fields << s['zonename']
148
+ object_fields << ui.color("State:", :cyan)
149
+ object_fields << s['state']
150
+
151
+ puts "\n"
152
+ puts ui.list(object_fields, :uneven_columns_across, 2)
153
+ puts "\n"
154
+ end
155
+
156
+ def confirm_action(question)
157
+ return true if locate_config_value(:yes)
158
+ result = ui.ask_question(question, :default => "Y" )
159
+ if result == "Y" || result == "y" then
160
+ return true
161
+ else
162
+ return false
163
+ end
164
+ end
165
+
166
+ end
167
+ end
@@ -0,0 +1,91 @@
1
+ #
2
+ # knife-cosmic author:: Robbert-Jan Sperna Weiland (<rspernaweiland@schubergphilis.com>)
3
+ # Copyright:: Copyright (c) 2018 Robbert-Jan Sperna Weiland.
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/cosmic_base'
20
+
21
+ module Knifecosmic
22
+ class CosmicServerPasswordreset < Chef::Knife
23
+
24
+ include Chef::Knife::KnifecosmicBase
25
+
26
+ deps do
27
+ require 'knife-cosmic/connection'
28
+ require 'chef/api_client'
29
+ require 'chef/knife'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cosmic server passwordreset SERVER_NAME [SERVER_NAME ...] (options)"
34
+
35
+ def run
36
+ validate_base_options
37
+
38
+ @name_args.each do |hostname|
39
+ server = connection.get_server(hostname)
40
+
41
+ if !server then
42
+ ui.error("Server '#{hostname}' not found")
43
+ next
44
+ end
45
+
46
+ rules = connection.list_port_forwarding_rules
47
+
48
+ show_object_details(server, connection, rules)
49
+
50
+ server = connection.server_passwordreset(hostname)
51
+ password = server['password']
52
+ ui.msg("Password: #{password}")
53
+ end
54
+ end
55
+
56
+ def show_object_details(s, connection, rules)
57
+ return if locate_config_value(:yes)
58
+
59
+ object_fields = []
60
+ object_fields << ui.color("Name:", :cyan)
61
+ object_fields << s['name'].to_s
62
+ object_fields << ui.color("Public IP:", :cyan)
63
+ object_fields << (connection.get_server_public_ip(s, rules) || '')
64
+ object_fields << ui.color("Service:", :cyan)
65
+ object_fields << s['serviceofferingname'].to_s
66
+ object_fields << ui.color("Template:", :cyan)
67
+ object_fields << s['templatename']
68
+ object_fields << ui.color("Domain:", :cyan)
69
+ object_fields << s['domain']
70
+ object_fields << ui.color("Zone:", :cyan)
71
+ object_fields << s['zonename']
72
+ object_fields << ui.color("State:", :cyan)
73
+ object_fields << s['state']
74
+
75
+ puts "\n"
76
+ puts ui.list(object_fields, :uneven_columns_across, 2)
77
+ puts "\n"
78
+ end
79
+
80
+ def confirm_action(question)
81
+ return true if locate_config_value(:yes)
82
+ result = ui.ask_question(question, :default => "Y" )
83
+ if result == "Y" || result == "y" then
84
+ return true
85
+ else
86
+ return false
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Original knife-cloudstack author:: Ryan Holmes (<rholmes@edmunds.com>)
3
+ # Original knife-cloudstack author:: KC Braunschweig (<kcbraunschweig@gmail.com>)
4
+ # Original knife-cloudstack author:: Sander Botman (<sbotman@schubergphilis.com>)
5
+ # Copyright:: Copyright (c) 2011 Edmunds, Inc.
6
+ # Copyright:: Copyright (c) 2013 Sander Botman.
7
+ # License:: Apache License, Version 2.0
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ require 'chef/knife/cosmic_base'
23
+
24
+ module Knifecosmic
25
+ class CosmicServerReboot < Chef::Knife
26
+
27
+ include Chef::Knife::KnifecosmicBase
28
+
29
+ deps do
30
+ require 'knife-cosmic/connection'
31
+ require 'chef/api_client'
32
+ require 'chef/knife'
33
+ Chef::Knife.load_deps
34
+ end
35
+
36
+ banner "knife cosmic server reboot SERVER_NAME [SERVER_NAME ...] (options)"
37
+
38
+ def run
39
+ validate_base_options
40
+
41
+ @name_args.each do |hostname|
42
+ server = connection.get_server(hostname)
43
+
44
+ if !server then
45
+ ui.error("Server '#{hostname}' not found")
46
+ next
47
+ end
48
+
49
+ rules = connection.list_port_forwarding_rules
50
+
51
+ show_object_details(server, connection, rules)
52
+
53
+ result = confirm_action("Do you really want to reboot this server")
54
+
55
+ if result
56
+ print "#{ui.color("Rebooting", :magenta)}"
57
+ connection.reboot_server(hostname)
58
+ puts "\n"
59
+ ui.msg("Rebooted server #{hostname}")
60
+ end
61
+ end
62
+ end
63
+
64
+ def show_object_details(s, connection, rules)
65
+ return if locate_config_value(:yes)
66
+
67
+ object_fields = []
68
+ object_fields << ui.color("Name:", :cyan)
69
+ object_fields << s['name'].to_s
70
+ object_fields << ui.color("Public IP:", :cyan)
71
+ object_fields << (connection.get_server_public_ip(s, rules) || '')
72
+ object_fields << ui.color("Service:", :cyan)
73
+ object_fields << s['serviceofferingname'].to_s
74
+ object_fields << ui.color("Template:", :cyan)
75
+ object_fields << s['templatename']
76
+ object_fields << ui.color("Domain:", :cyan)
77
+ object_fields << s['domain']
78
+ object_fields << ui.color("Zone:", :cyan)
79
+ object_fields << s['zonename']
80
+ object_fields << ui.color("State:", :cyan)
81
+ object_fields << s['state']
82
+
83
+ puts "\n"
84
+ puts ui.list(object_fields, :uneven_columns_across, 2)
85
+ puts "\n"
86
+ end
87
+
88
+ def confirm_action(question)
89
+ return true if locate_config_value(:yes)
90
+ result = ui.ask_question(question, :default => "Y" )
91
+ if result == "Y" || result == "y" then
92
+ return true
93
+ else
94
+ return false
95
+ end
96
+ end
97
+
98
+ end
99
+ end