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,61 @@
1
+ #
2
+ # Original knife-cloudstack author:: Sander Botman (<sbotman@schubergphilis.com>)
3
+ # Copyright:: Copyright (c) 2013 Sander Botman.
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
+ require 'chef/knife/cosmic_baselist'
21
+
22
+ module Knifecosmic
23
+ class CosmicHostList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifecosmicBaseList
26
+
27
+ banner "knife cosmic host list (options)"
28
+
29
+ option :name,
30
+ :long => "--name NAME",
31
+ :description => "Specify hostname to list"
32
+
33
+ option :keyword,
34
+ :long => "--service NAME",
35
+ :description => "Specify part of hostname to list"
36
+
37
+ def run
38
+ validate_base_options
39
+
40
+ columns = [
41
+ 'Name :name',
42
+ 'Address :ipaddress',
43
+ 'State :state',
44
+ 'Type :type',
45
+ 'Cluster :clustername',
46
+ 'Pod :podname',
47
+ 'Zone :zonename',
48
+ 'Resource :resourcestate'
49
+ ]
50
+
51
+ params = { 'command' => "listHosts" }
52
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
53
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
54
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
55
+
56
+ result = connection.list_object(params, "host")
57
+ list_object(columns, result)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Original knife-cloudstack author:: Ryan Holmes (<rholmes@edmunds.com>)
3
+ # Original knife-cloudstack author:: KC Braunschweig (<kcbraunschweig@gmail.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/cosmic_base'
21
+ require 'chef/knife/cosmic_baselist'
22
+
23
+ module Knifecosmic
24
+ class CosmicHosts < Chef::Knife
25
+
26
+ MEGABYTES = 1024 * 1024
27
+
28
+ include Chef::Knife::KnifecosmicBase
29
+ include Chef::Knife::KnifecosmicBaseList
30
+
31
+ deps do
32
+ require 'knife-cosmic/connection'
33
+ Chef::Knife.load_deps
34
+ end
35
+
36
+ banner "knife cosmic hosts"
37
+
38
+ def run
39
+ validate_base_options
40
+
41
+ host_list = [
42
+ ui.color('#Public IP', :bold),
43
+ ui.color('Host', :bold),
44
+ ui.color('FQDN', :bold)
45
+ ]
46
+
47
+ servers = connection.list_servers
48
+ pf_rules = connection.list_port_forwarding_rules
49
+ servers.each do |s|
50
+ host_list << (connection.get_server_public_ip(s, pf_rules) || '#')
51
+ host_list << (s['name'] || '')
52
+ host_list << (connection.get_server_fqdn(s) || '')
53
+ end
54
+ puts ui.list(host_list, :columns_across, 3)
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Original knife-cloudstack author:: Sander Botman (<sbotman@schubergphilis.com>)
3
+ # Copyright:: Copyright (c) 2013 Sander Botman.
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
+ require 'chef/knife/cosmic_baselist'
21
+
22
+ module Knifecosmic
23
+ class CosmicIsoList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifecosmicBaseList
26
+
27
+ banner "knife cosmic iso list (options)"
28
+
29
+ option :listall,
30
+ :long => "--listall",
31
+ :description => "List all iso's",
32
+ :boolean => true
33
+
34
+ option :name,
35
+ :long => "--name NAME",
36
+ :description => "Specify iso name to list"
37
+
38
+ option :keyword,
39
+ :long => "--keyword KEY",
40
+ :description => "List by keyword"
41
+
42
+ option :isofilter,
43
+ :long => "--isofilter FILTER",
44
+ :description => "Default: 'featured'. Options: 'self','selfexecutable','sharedexecutable','executable','community'",
45
+ :default => "featured"
46
+
47
+ def run
48
+ validate_base_options
49
+
50
+ columns = [
51
+ 'Name :name',
52
+ 'Account :account',
53
+ 'Domain :domain',
54
+ 'Public :ispublic',
55
+ 'Size :size',
56
+ 'OS :ostypename'
57
+ ]
58
+
59
+ params = { 'command' => "listIsos" }
60
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
61
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
62
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
63
+ params['name'] = locate_config_value(:name) if locate_config_value(:name)
64
+
65
+ if ['all','featured','self','selfexecutable','sharedexecutable','executable','community'].include?(locate_config_value(:templatefilter))
66
+ params['isofilter'] = locate_config_value(:isofilter)
67
+ else
68
+ params['isofilter'] = 'featured'
69
+ end
70
+
71
+ result = connection.list_object(params, "iso")
72
+ result.each do |r|
73
+ r['size'] = human_file_size(r['size']) if r['size']
74
+ end
75
+
76
+ list_object(columns, result)
77
+ end
78
+
79
+ def human_file_size n
80
+ count = 0
81
+ while n >= 1024 and count < 4
82
+ n /= 1024.0
83
+ count += 1
84
+ end
85
+ format("%.0f", n) + %w(B KB MB GB TB)[count]
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright:: Copyright (c) 2013
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/knife/cosmic_base'
18
+
19
+ module Knifecosmic
20
+ class CosmicKeypairCreate < Chef::Knife
21
+
22
+ include Chef::Knife::KnifecosmicBase
23
+
24
+ deps do
25
+ require 'knife-cosmic/connection'
26
+ Chef::Knife.load_deps
27
+ end
28
+
29
+ banner "knife cosmic keypair create KEY_NAME (options)"
30
+
31
+ option :name,
32
+ :long => "--name NAME",
33
+ :description => "Specify the ssh keypair name"
34
+
35
+ option :noheader,
36
+ :long => "--noheader",
37
+ :description => "Removes header from output",
38
+ :boolean => true
39
+
40
+ def run
41
+ validate_base_options
42
+
43
+ Chef::Log.debug("Validate keypair name")
44
+ keypairname = locate_config_value(:name) || @name_args.first
45
+ unless /^[a-zA-Z0-9][a-zA-Z0-9\-\_]*$/.match(keypairname) then
46
+ ui.error "Invalid keypairname. Please specify a short name for the keypair"
47
+ exit 1
48
+ end
49
+
50
+ ui.info("#{ui.color("Creating SSH Keypair: #{keypairname}", :magenta)}") unless locate_config_value(:noheader)
51
+
52
+ params = {
53
+ 'command' => 'createSSHKeyPair',
54
+ 'name' => keypairname,
55
+ }
56
+
57
+ json = connection.send_request(params)
58
+
59
+ unless json then
60
+ ui.error("Unable to create SSH Keypair")
61
+ exit 1
62
+ end
63
+
64
+ fingerprint = json['keypair']['fingerprint']
65
+ privatekey = json['keypair']['privatekey']
66
+ ui.info("Fingerprint: #{fingerprint}") unless locate_config_value(:noheader)
67
+ ui.info(privatekey)
68
+ puts "\n" unless locate_config_value(:noheader)
69
+ end
70
+
71
+ end # class
72
+ end
@@ -0,0 +1,60 @@
1
+ # Copyright:: Copyright (c) 2013
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/knife/cosmic_base'
18
+
19
+ module Knifecosmic
20
+ class CosmicKeypairDelete < Chef::Knife
21
+
22
+ include Chef::Knife::KnifecosmicBase
23
+
24
+ deps do
25
+ require 'knife-cosmic/connection'
26
+ Chef::Knife.load_deps
27
+ end
28
+
29
+ banner "knife cosmic keypair delete KEY_NAME (options)"
30
+
31
+ option :name,
32
+ :long => "--name NAME",
33
+ :description => "Specify the ssh keypair name"
34
+
35
+ def run
36
+ validate_base_options
37
+
38
+ Chef::Log.debug("Validate keypair name")
39
+ keypairname = locate_config_value(:name) || @name_args.first
40
+ unless /^[a-zA-Z0-9][a-zA-Z0-9\-\_]*$/.match(keypairname) then
41
+ ui.error "Invalid keypairname. Please specify a short name for the keypair"
42
+ exit 1
43
+ end
44
+
45
+ params = {
46
+ 'command' => 'deleteSSHKeyPair',
47
+ 'name' => keypairname,
48
+ }
49
+
50
+ json = connection.send_request(params)
51
+
52
+ unless json['success'] == 'true' then
53
+ ui.error("Unable to delete SSH Keypair")
54
+ exit 1
55
+ end
56
+ print "#{ui.color("Deleted the SSH Keypair: #{keypairname}", :magenta)}\n"
57
+ end
58
+
59
+ end # class
60
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2011 Edmunds, Inc.
3
+ # Copyright:: Copyright (c) 2013 Sander Botman.
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
+ require 'chef/knife/cosmic_baselist'
21
+
22
+ module Knifecosmic
23
+ class CosmicKeypairList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifecosmicBaseList
26
+
27
+ banner "knife cosmic keypair list (options)"
28
+
29
+ def run
30
+ validate_base_options
31
+
32
+ columns = [
33
+ 'Name :name',
34
+ 'Fingerprint :fingerprint'
35
+ ]
36
+
37
+ params = { 'command' => "listSSHKeyPairs" }
38
+
39
+ result = connection.list_object(params, "sshkeypair")
40
+ list_object(columns, result)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,63 @@
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 CosmicNetworkList < Chef::Knife
26
+
27
+ include Chef::Knife::KnifecosmicBaseList
28
+
29
+ banner "knife cosmic network list (options)"
30
+
31
+ option :listall,
32
+ :long => "--listall",
33
+ :description => "List all networks",
34
+ :boolean => true
35
+
36
+ option :keyword,
37
+ :long => "--keyword KEY",
38
+ :description => "List by keyword"
39
+
40
+ def run
41
+ validate_base_options
42
+
43
+ columns = [
44
+ 'Name :name',
45
+ 'Type :type',
46
+ 'Default :default',
47
+ 'Shared :shared',
48
+ 'Gateway :gateway',
49
+ 'Netmask :netmask',
50
+ 'Account :account',
51
+ 'Domain :domain'
52
+ ]
53
+
54
+ params = { 'command' => "listNetworks" }
55
+ params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
56
+ params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
57
+ params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
58
+
59
+ result = connection.list_object(params, "network")
60
+ list_object(columns, result)
61
+ end
62
+ end
63
+ end