knife-cloudstack 0.0.13 → 0.0.14

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.
Files changed (38) hide show
  1. data/CHANGES.rdoc +50 -0
  2. data/README.rdoc +221 -42
  3. data/lib/chef/knife/cs_account_list.rb +130 -0
  4. data/lib/chef/knife/cs_base.rb +98 -0
  5. data/lib/chef/knife/cs_baselist.rb +81 -0
  6. data/lib/chef/knife/cs_cluster_list.rb +93 -0
  7. data/lib/chef/knife/cs_config_list.rb +85 -0
  8. data/lib/chef/knife/cs_disk_list.rb +89 -0
  9. data/lib/chef/knife/cs_domain_list.rb +83 -0
  10. data/lib/chef/knife/cs_firewallrule_list.rb +95 -0
  11. data/lib/chef/knife/cs_host_list.rb +95 -0
  12. data/lib/chef/knife/cs_hosts.rb +2 -2
  13. data/lib/chef/knife/cs_iso_list.rb +103 -0
  14. data/lib/chef/knife/cs_network_list.rb +56 -46
  15. data/lib/chef/knife/cs_oscategory_list.rb +78 -0
  16. data/lib/chef/knife/cs_ostype_list.rb +80 -0
  17. data/lib/chef/knife/cs_pod_list.rb +93 -0
  18. data/lib/chef/knife/cs_project_list.rb +92 -0
  19. data/lib/chef/knife/cs_router_list.rb +94 -0
  20. data/lib/chef/knife/cs_server_create.rb +185 -144
  21. data/lib/chef/knife/cs_server_delete.rb +62 -79
  22. data/lib/chef/knife/cs_server_list.rb +136 -57
  23. data/lib/chef/knife/cs_server_reboot.rb +50 -54
  24. data/lib/chef/knife/cs_server_start.rb +48 -52
  25. data/lib/chef/knife/cs_server_stop.rb +54 -55
  26. data/lib/chef/knife/cs_service_list.rb +62 -41
  27. data/lib/chef/knife/cs_stack_create.rb +2 -2
  28. data/lib/chef/knife/cs_stack_delete.rb +2 -2
  29. data/lib/chef/knife/cs_template_create.rb +121 -0
  30. data/lib/chef/knife/cs_template_extract.rb +104 -0
  31. data/lib/chef/knife/cs_template_list.rb +65 -63
  32. data/lib/chef/knife/cs_template_register.rb +180 -0
  33. data/lib/chef/knife/cs_user_list.rb +93 -0
  34. data/lib/chef/knife/cs_volume_list.rb +94 -0
  35. data/lib/chef/knife/cs_zone_list.rb +55 -36
  36. data/lib/knife-cloudstack/connection.rb +75 -22
  37. data/lib/knife-cloudstack/string_to_regexp.rb +32 -0
  38. metadata +93 -61
@@ -0,0 +1,83 @@
1
+ #
2
+ # 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/cs_base'
20
+ require 'chef/knife/cs_baselist'
21
+
22
+ module KnifeCloudstack
23
+ class CsDomainList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifeCloudstackBase
26
+ include Chef::Knife::KnifeCloudstackBaseList
27
+
28
+ deps do
29
+ require 'knife-cloudstack/connection'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cs domain list (options)"
34
+
35
+ option :listall,
36
+ :long => "--listall",
37
+ :description => "List all the domains",
38
+ :boolean => true
39
+
40
+ def run
41
+ validate_base_options
42
+
43
+ if locate_config_value(:fields)
44
+ object_list = []
45
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
46
+ else
47
+ object_list = [
48
+ ui.color('Name', :bold),
49
+ ui.color('ID', :bold),
50
+ ui.color('Level', :bold),
51
+ ui.color('Path', :bold)
52
+ ]
53
+ end
54
+
55
+ columns = object_list.count
56
+ object_list = [] if locate_config_value(:noheader)
57
+
58
+ connection_result = connection.list_object(
59
+ "listDomains",
60
+ "domain",
61
+ locate_config_value(:filter),
62
+ locate_config_value(:listall)
63
+ )
64
+
65
+ output_format(connection_result)
66
+
67
+ connection_result.each do |r|
68
+
69
+ if locate_config_value(:fields)
70
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
71
+ else
72
+ object_list << r['name'].to_s
73
+ object_list << r['id'].to_s
74
+ object_list << r['level'].to_s
75
+ object_list << r['path'].to_s
76
+ end
77
+ end
78
+ puts ui.list(object_list, :uneven_columns_across, columns)
79
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,95 @@
1
+ #
2
+ # 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/cs_base'
20
+ require 'chef/knife/cs_baselist'
21
+
22
+ module KnifeCloudstack
23
+ class CsFirewallruleList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifeCloudstackBase
26
+ include Chef::Knife::KnifeCloudstackBaseList
27
+
28
+ deps do
29
+ require 'knife-cloudstack/connection'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cs firewallrule list (options)"
34
+
35
+ option :listall,
36
+ :long => "--listall",
37
+ :description => "List all firewall rules",
38
+ :boolean => true
39
+
40
+ option :keyword,
41
+ :long => "--keyword KEY",
42
+ :description => "List by keyword"
43
+
44
+ def run
45
+ validate_base_options
46
+
47
+ if locate_config_value(:fields)
48
+ object_list = []
49
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
50
+ else
51
+ object_list = [
52
+ ui.color('ID', :bold),
53
+ ui.color('Protocol', :bold),
54
+ ui.color('Start Port', :bold),
55
+ ui.color('End Port', :bold),
56
+ ui.color('IP AddressID', :bold),
57
+ ui.color('IP Address', :bold),
58
+ ui.color('State', :bold),
59
+ ui.color('CIDR List', :bold)
60
+ ]
61
+ end
62
+
63
+ columns = object_list.count
64
+ object_list = [] if locate_config_value(:noheader)
65
+
66
+ connection_result = connection.list_object(
67
+ "listFirewallRules",
68
+ "firewallrule",
69
+ locate_config_value(:filter),
70
+ locate_config_value(:listall),
71
+ locate_config_value(:keyword)
72
+ )
73
+
74
+ output_format(connection_result)
75
+
76
+ connection_result.each do |r|
77
+ if locate_config_value(:fields)
78
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
79
+ else
80
+ object_list << r['id'].to_s
81
+ object_list << r['protocol'].to_s
82
+ object_list << r['startport'].to_s
83
+ object_list << r['endport'].to_s
84
+ object_list << r['ipaddressid'].to_s
85
+ object_list << r['ipaddress'].to_s
86
+ object_list << r['state'].to_s
87
+ object_list << r['cidrlist'].to_s
88
+ end
89
+ end
90
+ puts ui.list(object_list, :uneven_columns_across, columns)
91
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,95 @@
1
+ #
2
+ # 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/cs_base'
20
+ require 'chef/knife/cs_baselist'
21
+
22
+ module KnifeCloudstack
23
+ class CsHostList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifeCloudstackBase
26
+ include Chef::Knife::KnifeCloudstackBaseList
27
+
28
+ deps do
29
+ require 'knife-cloudstack/connection'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cs host list (options)"
34
+
35
+ option :name,
36
+ :long => "--name NAME",
37
+ :description => "Specify hostname to list"
38
+
39
+ option :keyword,
40
+ :long => "--service NAME",
41
+ :description => "Specify part of hostname to list"
42
+
43
+ def run
44
+ validate_base_options
45
+
46
+ if locate_config_value(:fields)
47
+ object_list = []
48
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
49
+ else
50
+ object_list = [
51
+ ui.color('Name', :bold),
52
+ ui.color('Address', :bold),
53
+ ui.color('State', :bold),
54
+ ui.color('Type', :bold),
55
+ ui.color('Cluster', :bold),
56
+ ui.color('Pod', :bold),
57
+ ui.color('Zone', :bold),
58
+ ui.color('Resource', :bold)
59
+ ]
60
+ end
61
+
62
+ columns = object_list.count
63
+ object_list = [] if locate_config_value(:noheader)
64
+
65
+ connection_result = connection.list_object(
66
+ "listHosts",
67
+ "host",
68
+ locate_config_value(:filter),
69
+ false,
70
+ locate_config_value(:keyword),
71
+ locate_config_value(:name)
72
+ )
73
+
74
+ output_format(connection_result)
75
+
76
+ connection_result.each do |r|
77
+ if locate_config_value(:fields)
78
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
79
+ else
80
+ object_list << r['name'].to_s
81
+ object_list << r['ipaddress'].to_s
82
+ object_list << r['state'].to_s
83
+ object_list << r['type'].to_s
84
+ object_list << r['clustername'].to_s
85
+ object_list << r['podname'].to_s
86
+ object_list << r['zonename'].to_s
87
+ object_list << r['resourcestate'].to_s
88
+ end
89
+ end
90
+ puts ui.list(object_list, :uneven_columns_across, columns)
91
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
92
+ end
93
+
94
+ end
95
+ end
@@ -17,8 +17,6 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife'
21
-
22
20
  module KnifeCloudstack
23
21
  class CsHosts < Chef::Knife
24
22
 
@@ -26,6 +24,8 @@ module KnifeCloudstack
26
24
 
27
25
  deps do
28
26
  require 'knife-cloudstack/connection'
27
+ require 'chef/knife'
28
+ Chef::Knife.load_deps
29
29
  end
30
30
 
31
31
  banner "knife cs hosts"
@@ -0,0 +1,103 @@
1
+ #
2
+ # 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/cs_base'
20
+ require 'chef/knife/cs_baselist'
21
+
22
+ module KnifeCloudstack
23
+ class CsIsoList < Chef::Knife
24
+
25
+ include Chef::Knife::KnifeCloudstackBase
26
+ include Chef::Knife::KnifeCloudstackBaseList
27
+
28
+ deps do
29
+ require 'knife-cloudstack/connection'
30
+ Chef::Knife.load_deps
31
+ end
32
+
33
+ banner "knife cs iso list (options)"
34
+
35
+ option :listall,
36
+ :long => "--listall",
37
+ :description => "List all iso's",
38
+ :boolean => true
39
+
40
+ option :name,
41
+ :long => "--name NAME",
42
+ :description => "Specify iso name to list"
43
+
44
+ option :keyword,
45
+ :long => "--keyword KEY",
46
+ :description => "List by keyword"
47
+
48
+ def run
49
+ validate_base_options
50
+
51
+ object_list = []
52
+ if locate_config_value(:fields)
53
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
54
+ else
55
+ object_list << ui.color('Name', :bold)
56
+ object_list << ui.color('Account', :bold) unless locate_config_value(:cloudstack_project)
57
+ object_list << ui.color('Domain', :bold)
58
+ object_list << ui.color('Public', :bold)
59
+ object_list << ui.color('Size', :bold)
60
+ object_list << ui.color('OS', :bold)
61
+ end
62
+
63
+ columns = object_list.count
64
+ object_list = [] if locate_config_value(:noheader)
65
+
66
+ connection_result = connection.list_object(
67
+ "listIsos",
68
+ "iso",
69
+ locate_config_value(:filter),
70
+ locate_config_value(:listall),
71
+ locate_config_value(:keyword),
72
+ locate_config_value(:name)
73
+ )
74
+
75
+ output_format(connection_result)
76
+
77
+ connection_result.each do |r|
78
+ if locate_config_value(:fields)
79
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
80
+ else
81
+ object_list << r['name'].to_s
82
+ object_list << (r['account'] ? r['account'].to_s : 'N/A') unless locate_config_value(:cloudstack_project)
83
+ object_list << r['domain'].to_s
84
+ object_list << r['ispublic'].to_s
85
+ object_list << (r['size'] ? human_file_size(r['size']) : 'Unknown')
86
+ object_list << (r['ostypename'] ? r['ostypename'].to_s : 'N/A')
87
+ end
88
+ end
89
+ puts ui.list(object_list, :uneven_columns_across, columns)
90
+ connection.show_object_fields(connection_result) if locate_config_value(:fieldlist)
91
+ end
92
+
93
+ def human_file_size n
94
+ count = 0
95
+ while n >= 1024 and count < 4
96
+ n /= 1024.0
97
+ count += 1
98
+ end
99
+ format("%.0f", n) + %w(B KB MB GB TB)[count]
100
+ end
101
+
102
+ end
103
+ end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # Author:: Ryan Holmes (<rholmes@edmunds.com>)
3
+ # Author:: Sander Botman (<sbotman@schubergphilis.com>)
3
4
  # Copyright:: Copyright (c) 2011 Edmunds, Inc.
5
+ # Copyright:: Copyright (c) 2013 Sander Botman.
4
6
  # License:: Apache License, Version 2.0
5
7
  #
6
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,70 +17,78 @@
15
17
  # See the License for the specific language governing permissions and
16
18
  # limitations under the License.
17
19
  #
18
-
19
- require 'chef/knife'
20
+ require 'chef/knife/cs_base'
21
+ require 'chef/knife/cs_baselist'
20
22
 
21
23
  module KnifeCloudstack
22
24
  class CsNetworkList < Chef::Knife
23
25
 
26
+ include Chef::Knife::KnifeCloudstackBase
27
+ include Chef::Knife::KnifeCloudstackBaseList
28
+
24
29
  deps do
25
30
  require 'knife-cloudstack/connection'
31
+ require 'chef/knife'
32
+ Chef::Knife.load_deps
26
33
  end
27
34
 
28
35
  banner "knife cs network list (options)"
29
36
 
30
- option :cloudstack_url,
31
- :short => "-U URL",
32
- :long => "--cloudstack-url URL",
33
- :description => "The CloudStack endpoint URL",
34
- :proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
35
-
36
- option :cloudstack_api_key,
37
- :short => "-A KEY",
38
- :long => "--cloudstack-api-key KEY",
39
- :description => "Your CloudStack API key",
40
- :proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
37
+ option :listall,
38
+ :long => "--listall",
39
+ :description => "List all networks",
40
+ :boolean => true
41
41
 
42
- option :cloudstack_secret_key,
43
- :short => "-K SECRET",
44
- :long => "--cloudstack-secret-key SECRET",
45
- :description => "Your CloudStack secret key",
46
- :proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
42
+ option :keyword,
43
+ :long => "--keyword KEY",
44
+ :description => "List by keyword"
47
45
 
48
46
  def run
47
+ validate_base_options
49
48
 
50
- connection = CloudstackClient::Connection.new(
51
- locate_config_value(:cloudstack_url),
52
- locate_config_value(:cloudstack_api_key),
53
- locate_config_value(:cloudstack_secret_key)
54
- )
49
+ object_list = []
50
+ if locate_config_value(:fields)
51
+ locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
52
+ else
53
+ object_list << ui.color('Name', :bold)
54
+ object_list << ui.color('Type', :bold)
55
+ object_list << ui.color('Default', :bold)
56
+ object_list << ui.color('Shared', :bold)
57
+ object_list << ui.color('Gateway', :bold)
58
+ object_list << ui.color('Netmask', :bold)
59
+ object_list << ui.color('Account', :bold) unless locate_config_value(:cloudstack_project)
60
+ object_list << ui.color('Domain', :bold)
61
+ end
55
62
 
56
- network_list = [
57
- ui.color('Name', :bold),
58
- ui.color('Type', :bold),
59
- ui.color('Default', :bold),
60
- ui.color('Shared', :bold),
61
- ui.color('Gateway', :bold),
62
- ui.color('Netmask', :bold)
63
- ]
63
+ columns = object_list.count
64
+ object_list = [] if locate_config_value(:noheader)
64
65
 
65
- networks = connection.list_networks
66
- networks.each do |n|
67
- network_list << n['name']
68
- network_list << n['type']
69
- network_list << n['isdefault'].to_s
70
- network_list << n['isshared'].to_s
71
- network_list << (n['gateway'] || '')
72
- network_list << (n['netmask'] || '')
73
- end
74
- puts ui.list(network_list, :columns_across, 6)
66
+ connection_result = connection.list_object(
67
+ "listNetworks",
68
+ "network",
69
+ locate_config_value(:filter),
70
+ locate_config_value(:listall),
71
+ locate_config_value(:keyword)
72
+ )
75
73
 
76
- end
74
+ output_format(connection_result)
77
75
 
78
- def locate_config_value(key)
79
- key = key.to_sym
80
- Chef::Config[:knife][key] || config[key]
76
+ connection_result.each do |r|
77
+ if locate_config_value(:fields)
78
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
79
+ else
80
+ object_list << r['name'].to_s
81
+ object_list << r['type'].to_s
82
+ object_list << (r['isdefault'] ? r['isdefault'].to_s : 'false')
83
+ object_list << (r['isshared'] ? r['isshared'].to_s : 'false')
84
+ object_list << (r['gateway'] || '')
85
+ object_list << (r['netmask'] || '')
86
+ object_list << (r['account'] || '') unless locate_config_value(:cloudstack_project)
87
+ object_list << (r['domain'] || '')
88
+ end
89
+ end
90
+ puts ui.list(object_list, :uneven_columns_across, columns)
91
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
81
92
  end
82
-
83
93
  end
84
94
  end