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,98 @@
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'
20
+
21
+ class Chef
22
+ class Knife
23
+ module KnifeCloudstackBase
24
+
25
+ def self.included(includer)
26
+ includer.class_eval do
27
+
28
+ deps do
29
+ require 'readline'
30
+ require 'chef/json_compat'
31
+ end
32
+
33
+ option :cloudstack_url,
34
+ :short => "-U URL",
35
+ :long => "--cloudstack-url URL",
36
+ :description => "The CloudStack endpoint URL",
37
+ :proc => Proc.new { |url| Chef::Config[:knife][:cloudstack_url] = url }
38
+
39
+ option :cloudstack_api_key,
40
+ :short => "-A KEY",
41
+ :long => "--cloudstack-api-key KEY",
42
+ :description => "Your CloudStack API key",
43
+ :proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_api_key] = key }
44
+
45
+ option :cloudstack_secret_key,
46
+ :short => "-K SECRET",
47
+ :long => "--cloudstack-secret-key SECRET",
48
+ :description => "Your CloudStack secret key",
49
+ :proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
50
+
51
+ option :cloudstack_project,
52
+ :short => "-P PROJECT_NAME",
53
+ :long => '--cloudstack-project PROJECT_NAME',
54
+ :description => "Cloudstack Project in which to create server",
55
+ :proc => Proc.new { |v| Chef::Config[:knife][:cloudstack_project] = v },
56
+ :default => nil
57
+
58
+ option :use_http_ssl,
59
+ :long => '--[no-]use-http-ssl',
60
+ :description => 'Turn HTTPS support On/Off. Default is On',
61
+ :boolean => true,
62
+ :default => true
63
+
64
+ def validate_base_options
65
+ unless locate_config_value :cloudstack_url
66
+ ui.error "Cloudstack URL not specified"
67
+ exit 1
68
+ end
69
+ unless locate_config_value :cloudstack_api_key
70
+ ui.error "Cloudstack API key not specified"
71
+ exit 1
72
+ end
73
+ unless locate_config_value :cloudstack_secret_key
74
+ ui.error "Cloudstack Secret key not specified"
75
+ exit 1
76
+ end
77
+ end
78
+
79
+ def connection
80
+ @connection ||= CloudstackClient::Connection.new(
81
+ locate_config_value(:cloudstack_url),
82
+ locate_config_value(:cloudstack_api_key),
83
+ locate_config_value(:cloudstack_secret_key),
84
+ locate_config_value(:cloudstack_project),
85
+ locate_config_value(:use_http_ssl)
86
+ )
87
+ end
88
+
89
+ def locate_config_value(key)
90
+ key = key.to_sym
91
+ Chef::Config[:knife][key] || config[key]
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,81 @@
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 'json'
20
+ require 'chef/knife'
21
+
22
+ class Chef
23
+ class Knife
24
+ module KnifeCloudstackBaseList
25
+
26
+ def self.included(includer)
27
+ includer.class_eval do
28
+
29
+ option :filter,
30
+ :long => "--filter 'FIELD:NAME'",
31
+ :description => "Specify field and part of name to list"
32
+
33
+ option :fields,
34
+ :long => "--fields 'NAME, NAME'",
35
+ :description => "The fields to output, comma-separated"
36
+
37
+ option :fieldlist,
38
+ :long => "--fieldlist",
39
+ :description => "The available fields to output/filter",
40
+ :boolean => true
41
+
42
+ option :noheader,
43
+ :long => "--noheader",
44
+ :description => "Removes header from output",
45
+ :boolean => true
46
+ end
47
+ end
48
+
49
+ def output_format(json)
50
+ if locate_config_value(:format) =~ /json/i
51
+ json_hash = {};
52
+ json.each { |k| json_hash.merge!( k['id'] => k) }
53
+ puts JSON.pretty_generate(json_hash)
54
+ exit 0
55
+ end
56
+ end
57
+
58
+ def list_object_fields(object)
59
+ exit 1 if object.nil? || object.empty?
60
+ object_fields = [
61
+ ui.color('Key', :bold),
62
+ ui.color('Type', :bold),
63
+ ui.color('Value', :bold)
64
+ ]
65
+
66
+ object.first.sort.each do |k,v|
67
+ object_fields << ui.color(k, :yellow, :bold)
68
+ object_fields << v.class.to_s
69
+ if v.kind_of?(Array)
70
+ object_fields << '<Array>'
71
+ else
72
+ object_fields << ("#{v}").strip.to_s
73
+ end
74
+ end
75
+ puts "\n"
76
+ puts ui.list(object_fields, :uneven_columns_across, 3)
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,93 @@
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 CsClusterList < 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 cluster list (options)"
34
+
35
+ option :name,
36
+ :long => "--name NAME",
37
+ :description => "Specify cluster name to list"
38
+
39
+ option :keyword,
40
+ :long => "--keyword KEY",
41
+ :description => "List by keyword"
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('Pod', :bold),
53
+ ui.color('Zone', :bold),
54
+ ui.color('HypervisorType', :bold),
55
+ ui.color('ClusterType', :bold),
56
+ ui.color('AllocationState', :bold),
57
+ ui.color('ManagedState', :bold)
58
+ ]
59
+ end
60
+
61
+ columns = object_list.count
62
+ object_list = [] if locate_config_value(:noheader)
63
+
64
+ connection_result = connection.list_object(
65
+ "listClusters",
66
+ "cluster",
67
+ locate_config_value(:filter),
68
+ false,
69
+ locate_config_value(:keyword),
70
+ locate_config_value(:name)
71
+ )
72
+
73
+ output_format(connection_result)
74
+
75
+ connection_result.each do |r|
76
+ if locate_config_value(:fields)
77
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
78
+ else
79
+ object_list << r['name'].to_s
80
+ object_list << r['podname'].to_s
81
+ object_list << r['zonename'].to_s
82
+ object_list << r['hypervisortype'].to_s
83
+ object_list << r['clustertype'].to_s
84
+ object_list << r['allocationstate'].to_s
85
+ object_list << r['managedstate'].to_s
86
+ end
87
+ end
88
+ puts ui.list(object_list, :uneven_columns_across, columns)
89
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,85 @@
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 CsConfigList < 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 config list (options)"
34
+
35
+ option :name,
36
+ :long => "--name NAME",
37
+ :description => "Specify router name to list"
38
+
39
+ option :keyword,
40
+ :long => "--keyword KEY",
41
+ :description => "List by keyword"
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('Category', :bold),
52
+ ui.color('Name', :bold),
53
+ ui.color('Value', :bold)
54
+ ]
55
+ end
56
+
57
+ columns = object_list.count
58
+ object_list = [] if locate_config_value(:noheader)
59
+
60
+ connection_result = connection.list_object(
61
+ "listConfigurations",
62
+ "configuration",
63
+ locate_config_value(:filter),
64
+ false,
65
+ locate_config_value(:keyword),
66
+ locate_config_value(:name)
67
+ )
68
+
69
+ output_format(connection_result)
70
+
71
+ connection_result.each do |r|
72
+ if locate_config_value(:fields)
73
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
74
+ else
75
+ object_list << r['category'].to_s
76
+ object_list << r['name'].to_s
77
+ object_list << r['value'].to_s
78
+ end
79
+ end
80
+ puts ui.list(object_list, :uneven_columns_across, columns)
81
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,89 @@
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 CsDiskList < 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 disk list (options)"
34
+
35
+ option :name,
36
+ :long => "--name NAME",
37
+ :description => "Specify diskname to list"
38
+
39
+ option :keyword,
40
+ :long => "--service NAME",
41
+ :description => "Specify part of diskname 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('Domain', :bold),
53
+ ui.color('Size', :bold),
54
+ ui.color('Comment', :bold),
55
+ ui.color('Created', :bold)
56
+ ]
57
+ end
58
+
59
+ columns = object_list.count
60
+ object_list = [] if locate_config_value(:noheader)
61
+
62
+ connection_result = connection.list_object(
63
+ "listDiskOfferings",
64
+ "diskoffering",
65
+ locate_config_value(:filter),
66
+ false,
67
+ locate_config_value(:keyword),
68
+ locate_config_value(:name)
69
+ )
70
+
71
+ output_format(connection_result)
72
+
73
+ connection_result.each do |r|
74
+ if locate_config_value(:fields)
75
+ locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
76
+ else
77
+ object_list << r['name'].to_s
78
+ object_list << r['domain'].to_s
79
+ object_list << r['disksize'].to_s + 'GB'
80
+ object_list << r['displaytext'].to_s
81
+ object_list << r['created']
82
+ end
83
+ end
84
+ puts ui.list(object_list, :uneven_columns_across, columns)
85
+ list_object_fields(connection_result) if locate_config_value(:fieldlist)
86
+ end
87
+
88
+ end
89
+ end