knife-cloudstack-fog 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05fe65a30aea4229b1b5f4447cd177deb529c59a
4
+ data.tar.gz: 03471506357fec26e43618d1b2f3d77248734617
5
+ SHA512:
6
+ metadata.gz: d064b3b0476ee7c5549aee573c7d0bf561f60fe0ec26d04493744cee70b264eddb46d8ae22ed7af8d1339c79663ff14ad567b8543af93d8e06a36eebfeb25350
7
+ data.tar.gz: 4081f2dd006525c54276b8d51f3693891652772888529359902d60fda5f9fe9c08b43fc84c6ced1fb6d697529cc436e0afa5af39ed5dc5069ae2b0e31c3714b8
@@ -1,142 +1,142 @@
1
- {<img src="https://badge.fury.io/rb/knife-cloudstack-fog.png" alt="Gem Version" />}[http://badge.fury.io/rb/knife-cloudstack-fog]
2
- {<img src="https://www.travis-ci.org/fifthecho/knife-cloudstack-fog.png?branch=master" alt="Build Status" />}[https://www.travis-ci.org/fifthecho/knife-cloudstack-fog]
3
- {<img src="https://gemnasium.com/fifthecho/knife-cloudstack-fog.png" alt="Dependency Status" />}[https://gemnasium.com/fifthecho/knife-cloudstack-fog]
4
-
5
- = Knife Cloudstack
6
-
7
- = DESCRIPTION:
8
-
9
- This is the unofficial Opscode Knife plugin for Apache CloudStack / Citrix CloudPlatform Clouds. This plugin gives knife the ability to create, bootstrap, and manage instances in Cloudstack Compute clouds.
10
-
11
- = INSTALLATION:
12
-
13
- Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
14
-
15
- $ gem install chef
16
-
17
- Also ensure you are running the latest version of Fog. Versions earlier than 1.3.1 don't fully support Cloudstack Cloud:
18
-
19
- $ gem update fog
20
-
21
- This plugin is distributed as a Ruby Gem. To install it, run:
22
-
23
- $ gem install knife-cloudstack-fog
24
-
25
- Depending on your system's configuration, you may need to run this command with root privileges.
26
-
27
- Also, all of these commands have been tested against CloudStack/CloudPlatform 2.2.14 and 3.0.6.
28
-
29
- = CONFIGURATION:
30
-
31
- In order to communicate with an Cloudstack Compute cloud's CLOUDSTACK API you will have to tell Knife about your Cloudstack Compute cloud API endpoint, Cloudstack Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your <tt>knife.rb</tt> file:
32
-
33
- ### Note: You may need to append the :cloudstack_access_key_id with ":$PROJECT_NAME", if it differs from your Cloudstack Username.
34
- knife[:cloudstack_access_key_id] = "Your Cloudstack Access Key ID"
35
- knife[:cloudstack_secret_access_key] = "Your Cloudstack Secret Access Key"
36
- ### Note: If you are not proxying HTTPS to the Cloudstack CLOUDSTACK API port, the scheme should be HTTP, and the PORT is 8773.
37
- knife[:cloudstack_api_endpoint] = "https://cloud.mycompany.com/service/Cloud"
38
-
39
- If your knife.rb file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:
40
-
41
- knife[:cloudstack_access_key_id] = "#{ENV['CLOUDSTACK_ACCESS_KEY']}"
42
- knife[:cloudstack_secret_access_key] = "#{ENV['CLOUDSTACK_SECRET_KEY']}"
43
- knife[:cloudstack_api_endpoint] = "#{ENV['CLOUDSTACK_URL']}"
44
-
45
- You also have the option of passing your Cloudstack API Key/Secret into the individual knife subcommands using the <tt>-A</tt> (or <tt>--cloudstack-access-key-id</tt>) <tt>-K</tt> (or <tt>--cloudstack-secret-access-key</tt>) command options
46
-
47
- # provision a new webserver
48
- knife cloudstack server create 'role[webserver]' -I <image template> -f <service offering> -A 'Your Cloudstack Access Key ID' --cloudstack-api-endpoint 'https://cloud.mycompany.com/v1.0'
49
-
50
- Additionally the following options may be set in your `knife.rb`:
51
-
52
- * flavor
53
- * image
54
- * availability_zone
55
-
56
- = SUBCOMMANDS:
57
-
58
- This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
59
-
60
- == knife cloudstack server create
61
-
62
- Provisions a new server in an Cloudstack Compute cloud and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server. By default the server is bootstrapped using the chef-full template. This can be overridden using the <tt>-d</tt> or <tt>--template-file</tt> command options.
63
-
64
- == knife cloudstack server delete
65
-
66
- Deletes an existing server in the currently configured Cloudstack Compute cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server.
67
-
68
- == knife cloudstack server list
69
-
70
- Outputs a list of all servers in the currently configured Cloudstack Compute cloud account. <b>PLEASE NOTE</b> - this shows all instances associated with the account, some of which may not be currently managed by the Chef server.
71
-
72
- == knife cloudstack serviceoffering list
73
-
74
- Outputs a list of all available service offerings (available hardware configuration for a server) available to the currently configured Cloudstack Compute cloud account. Each service offering has a unique combination of disk space, memory capacity and priority for CPU time. This data can be useful when choosing a service offering ID to pass to the <tt>knife cloudstack server create</tt> subcommand.
75
-
76
- == knife cloudstack template list
77
-
78
- Outputs a list of all available templates available to the currently configured Cloudstack Compute cloud account. A template is a collection of files used to create or rebuild a server. This data can be useful when choosing an template ID to pass to the <tt>knife cloudstack server create</tt> subcommand.
79
-
80
- == knife cloudstack keypair create
81
-
82
- Create a new SSH keypair or register a public key to the currently configured Cloudstack Compute cloud account. This command is valuable to provide password recovery options as well as associating a Cloudstack keypair with an instance for any advanced authentication methods when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
83
-
84
- == knife cloudstack keypair delete
85
-
86
- Delete a keypair which is abailable to the currently configured Cloudstack Compute cloud account.
87
-
88
- == knife cloudstack keypair list
89
-
90
- Outputs a list of all available keypairs available to the currently configured Cloudstack Compute cloud account. This information is valuable to provide password recovery options as well as associating a Cloudstack keypair with an instance for any advanced authentication methods when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
91
-
92
- == knife cloudstack network list
93
-
94
- Outputs a list of all available network offerings available to the currently configured Cloudstack Compute cloud account. This information is necessary to locate a network ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand if your Cloudstack Compute cloud requires a server be associated with a particular network offering.
95
-
96
- == knife cloudstack portforwardingrule list
97
-
98
- Outputs a list of all port forwarding rules.
99
-
100
- == knife cloudstack publicip create
101
-
102
- Assign a new public ip address to the zone specified by -z option. This sub command is available only on advanced network (VLAN enabled) zone.
103
-
104
- == knife cloudstack publicip list
105
-
106
- Outputs a list of all public ip addresses assigned to the account. This sub command is available only on advanced network (VLAN enabled) zone.
107
-
108
- == knife cloudstack securitygroup list
109
-
110
- Outputs a list of all available security groups defined for the currently configured Cloudstack Compute cloud account. This information is necessary to locate a security group ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand if your Cloudstack Compute cloud requires a server be associated with a security group.
111
-
112
- == knife cloudstack zone list
113
-
114
- Outputs a list of all available zones available to the currently configured Cloudstack Compute cloud account. This information is necessary to locate a zone ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
115
-
116
- == knife cloudstack diskofferings list
117
-
118
- Outputs a list of all available disk offerings available to the currently configured Cloudstack Compute cloud account. This information is valuable if you are also seeking to provision a data disk alongside your root volume when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
119
-
120
- == knife cloudstack network create
121
-
122
- Creates networks to be used by the knife cloudstack server create command in zones that are configured in Advanced/VPC networking modes.
123
-
124
-
125
-
126
- = LICENSE:
127
-
128
- Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>), Damien Fuentes, Takashi Kanai (<anikundesu@gmail.com>)
129
- Copyright:: Copyright (c) 2011 Clogeny, 2012 Datapipe, 2012 IDC Frontier Inc.
130
- License:: Apache License, Version 2.0
131
-
132
- Licensed under the Apache License, Version 2.0 (the "License");
133
- you may not use this file except in compliance with the License.
134
- You may obtain a copy of the License at
135
-
136
- http://www.apache.org/licenses/LICENSE-2.0
137
-
138
- Unless required by applicable law or agreed to in writing, software
139
- distributed under the License is distributed on an "AS IS" BASIS,
140
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
- See the License for the specific language governing permissions and
142
- limitations under the License.
1
+ {<img src="https://badge.fury.io/rb/knife-cloudstack-fog.png" alt="Gem Version" />}[http://badge.fury.io/rb/knife-cloudstack-fog]
2
+ {<img src="https://travis-ci.org/fifthecho/knife-cloudstack-fog.png?branch=master" alt="Build Status" />}[https://travis-ci.org/fifthecho/knife-cloudstack-fog]
3
+ {<img src="https://gemnasium.com/fifthecho/knife-cloudstack-fog.png" alt="Dependency Status" />}[https://gemnasium.com/fifthecho/knife-cloudstack-fog]
4
+
5
+ = Knife Cloudstack
6
+
7
+ = DESCRIPTION:
8
+
9
+ This is the unofficial Opscode Knife plugin for Apache CloudStack / Citrix CloudPlatform Clouds. This plugin gives knife the ability to create, bootstrap, and manage instances in Cloudstack Compute clouds.
10
+
11
+ = INSTALLATION:
12
+
13
+ Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
14
+
15
+ $ gem install chef
16
+
17
+ Also ensure you are running the latest version of Fog. Versions earlier than 1.3.1 don't fully support Cloudstack Cloud:
18
+
19
+ $ gem update fog
20
+
21
+ This plugin is distributed as a Ruby Gem. To install it, run:
22
+
23
+ $ gem install knife-cloudstack-fog
24
+
25
+ Depending on your system's configuration, you may need to run this command with root privileges.
26
+
27
+ Also, all of these commands have been tested against CloudStack/CloudPlatform 2.2.14 and 3.0.6.
28
+
29
+ = CONFIGURATION:
30
+
31
+ In order to communicate with an Cloudstack Compute cloud's CLOUDSTACK API you will have to tell Knife about your Cloudstack Compute cloud API endpoint, Cloudstack Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your <tt>knife.rb</tt> file:
32
+
33
+ ### Note: You may need to append the :cloudstack_access_key_id with ":$PROJECT_NAME", if it differs from your Cloudstack Username.
34
+ knife[:cloudstack_access_key_id] = "Your Cloudstack Access Key ID"
35
+ knife[:cloudstack_secret_access_key] = "Your Cloudstack Secret Access Key"
36
+ ### Note: If you are not proxying HTTPS to the Cloudstack CLOUDSTACK API port, the scheme should be HTTP, and the PORT is 8773.
37
+ knife[:cloudstack_api_endpoint] = "https://cloud.mycompany.com/service/Cloud"
38
+
39
+ If your knife.rb file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:
40
+
41
+ knife[:cloudstack_access_key_id] = "#{ENV['CLOUDSTACK_ACCESS_KEY']}"
42
+ knife[:cloudstack_secret_access_key] = "#{ENV['CLOUDSTACK_SECRET_KEY']}"
43
+ knife[:cloudstack_api_endpoint] = "#{ENV['CLOUDSTACK_URL']}"
44
+
45
+ You also have the option of passing your Cloudstack API Key/Secret into the individual knife subcommands using the <tt>-A</tt> (or <tt>--cloudstack-access-key-id</tt>) <tt>-K</tt> (or <tt>--cloudstack-secret-access-key</tt>) command options
46
+
47
+ # provision a new webserver
48
+ knife cloudstack server create 'role[webserver]' -I <image template> -f <service offering> -A 'Your Cloudstack Access Key ID' --cloudstack-api-endpoint 'https://cloud.mycompany.com/v1.0'
49
+
50
+ Additionally the following options may be set in your `knife.rb`:
51
+
52
+ * flavor
53
+ * image
54
+ * availability_zone
55
+
56
+ = SUBCOMMANDS:
57
+
58
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
59
+
60
+ == knife cloudstack server create
61
+
62
+ Provisions a new server in an Cloudstack Compute cloud and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server. By default the server is bootstrapped using the chef-full template. This can be overridden using the <tt>-d</tt> or <tt>--template-file</tt> command options.
63
+
64
+ == knife cloudstack server delete
65
+
66
+ Deletes an existing server in the currently configured Cloudstack Compute cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server.
67
+
68
+ == knife cloudstack server list
69
+
70
+ Outputs a list of all servers in the currently configured Cloudstack Compute cloud account. <b>PLEASE NOTE</b> - this shows all instances associated with the account, some of which may not be currently managed by the Chef server.
71
+
72
+ == knife cloudstack serviceoffering list
73
+
74
+ Outputs a list of all available service offerings (available hardware configuration for a server) available to the currently configured Cloudstack Compute cloud account. Each service offering has a unique combination of disk space, memory capacity and priority for CPU time. This data can be useful when choosing a service offering ID to pass to the <tt>knife cloudstack server create</tt> subcommand.
75
+
76
+ == knife cloudstack template list
77
+
78
+ Outputs a list of all available templates available to the currently configured Cloudstack Compute cloud account. A template is a collection of files used to create or rebuild a server. This data can be useful when choosing an template ID to pass to the <tt>knife cloudstack server create</tt> subcommand.
79
+
80
+ == knife cloudstack keypair create
81
+
82
+ Create a new SSH keypair or register a public key to the currently configured Cloudstack Compute cloud account. This command is valuable to provide password recovery options as well as associating a Cloudstack keypair with an instance for any advanced authentication methods when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
83
+
84
+ == knife cloudstack keypair delete
85
+
86
+ Delete a keypair which is abailable to the currently configured Cloudstack Compute cloud account.
87
+
88
+ == knife cloudstack keypair list
89
+
90
+ Outputs a list of all available keypairs available to the currently configured Cloudstack Compute cloud account. This information is valuable to provide password recovery options as well as associating a Cloudstack keypair with an instance for any advanced authentication methods when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
91
+
92
+ == knife cloudstack network list
93
+
94
+ Outputs a list of all available network offerings available to the currently configured Cloudstack Compute cloud account. This information is necessary to locate a network ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand if your Cloudstack Compute cloud requires a server be associated with a particular network offering.
95
+
96
+ == knife cloudstack portforwardingrule list
97
+
98
+ Outputs a list of all port forwarding rules.
99
+
100
+ == knife cloudstack publicip create
101
+
102
+ Assign a new public ip address to the zone specified by -z option. This sub command is available only on advanced network (VLAN enabled) zone.
103
+
104
+ == knife cloudstack publicip list
105
+
106
+ Outputs a list of all public ip addresses assigned to the account. This sub command is available only on advanced network (VLAN enabled) zone.
107
+
108
+ == knife cloudstack securitygroup list
109
+
110
+ Outputs a list of all available security groups defined for the currently configured Cloudstack Compute cloud account. This information is necessary to locate a security group ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand if your Cloudstack Compute cloud requires a server be associated with a security group.
111
+
112
+ == knife cloudstack zone list
113
+
114
+ Outputs a list of all available zones available to the currently configured Cloudstack Compute cloud account. This information is necessary to locate a zone ID when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
115
+
116
+ == knife cloudstack diskofferings list
117
+
118
+ Outputs a list of all available disk offerings available to the currently configured Cloudstack Compute cloud account. This information is valuable if you are also seeking to provision a data disk alongside your root volume when instantiating a server with the <tt>knife cloudstack server create</tt> subcommand.
119
+
120
+ == knife cloudstack network create
121
+
122
+ Creates networks to be used by the knife cloudstack server create command in zones that are configured in Advanced/VPC networking modes.
123
+
124
+
125
+
126
+ = LICENSE:
127
+
128
+ Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>), Damien Fuentes, Takashi Kanai (<anikundesu@gmail.com>)
129
+ Copyright:: Copyright (c) 2011 Clogeny, 2012 Datapipe, 2012 IDC Frontier Inc.
130
+ License:: Apache License, Version 2.0
131
+
132
+ Licensed under the Apache License, Version 2.0 (the "License");
133
+ you may not use this file except in compliance with the License.
134
+ You may obtain a copy of the License at
135
+
136
+ http://www.apache.org/licenses/LICENSE-2.0
137
+
138
+ Unless required by applicable law or agreed to in writing, software
139
+ distributed under the License is distributed on an "AS IS" BASIS,
140
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
+ See the License for the specific language governing permissions and
142
+ limitations under the License.
@@ -1,101 +1,101 @@
1
- #
2
- # Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>)
3
- # Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
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 CloudstackBase
24
-
25
- # :nodoc:
26
- # Would prefer to do this in a rational way, but can't be done b/c of
27
- # Mixlib::CLI's design :(
28
- def self.included(includer)
29
- includer.class_eval do
30
-
31
- deps do
32
- require 'fog'
33
- require 'readline'
34
- require 'chef/json_compat'
35
- end
36
-
37
- option :cloudstack_access_key_id,
38
- :short => "-A ID",
39
- :long => "--cloudstack-access-key-id KEY",
40
- :description => "Your Cloudstack Access Key ID",
41
- :proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey }
42
-
43
- option :cloudstack_secret_access_key,
44
- :short => "-K SECRET",
45
- :long => "--cloudstack-secret-access-key SECRET",
46
- :description => "Your Cloudstack API Secret Access Key",
47
- :proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey }
48
-
49
- option :cloudstack_api_endpoint,
50
- :long => "--cloudstack-api-endpoint ENDPOINT",
51
- :description => "Your Cloudstack API endpoint",
52
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint }
53
- end
54
- end
55
-
56
- def connection
57
- @connection ||= begin
58
- cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint])
59
- connection = Fog::Compute.new(
60
- :provider => :cloudstack,
61
- :cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id],
62
- :cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key],
63
- :cloudstack_host => cloudstack_uri.host,
64
- :cloudstack_port => cloudstack_uri.port,
65
- :cloudstack_path => cloudstack_uri.path,
66
- :cloudstack_scheme => cloudstack_uri.scheme
67
- )
68
- end
69
- end
70
-
71
- def locate_config_value(key)
72
- key = key.to_sym
73
- Chef::Config[:knife][key] || config[key]
74
- end
75
-
76
- def msg_pair(label, value, color=:cyan)
77
- if value && !value.to_s.empty?
78
- puts "#{ui.color(label, color)}: #{value}"
79
- end
80
- end
81
-
82
- def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint])
83
- errors = []
84
-
85
- keys.each do |k|
86
- pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
87
- if Chef::Config[:knife][k].nil?
88
- errors << "You did not provided a valid '#{pretty_key}' value."
89
- end
90
- end
91
-
92
- if errors.each{|e| ui.error(e)}.any?
93
- exit 1
94
- end
95
- end
96
-
97
- end
98
- end
99
- end
100
-
101
-
1
+ #
2
+ # Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>)
3
+ # Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
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 CloudstackBase
24
+
25
+ # :nodoc:
26
+ # Would prefer to do this in a rational way, but can't be done b/c of
27
+ # Mixlib::CLI's design :(
28
+ def self.included(includer)
29
+ includer.class_eval do
30
+
31
+ deps do
32
+ require 'fog'
33
+ require 'readline'
34
+ require 'chef/json_compat'
35
+ end
36
+
37
+ option :cloudstack_access_key_id,
38
+ :short => "-A ID",
39
+ :long => "--cloudstack-access-key-id KEY",
40
+ :description => "Your Cloudstack Access Key ID",
41
+ :proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey }
42
+
43
+ option :cloudstack_secret_access_key,
44
+ :short => "-K SECRET",
45
+ :long => "--cloudstack-secret-access-key SECRET",
46
+ :description => "Your Cloudstack API Secret Access Key",
47
+ :proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey }
48
+
49
+ option :cloudstack_api_endpoint,
50
+ :long => "--cloudstack-api-endpoint ENDPOINT",
51
+ :description => "Your Cloudstack API endpoint",
52
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint }
53
+ end
54
+ end
55
+
56
+ def connection
57
+ @connection ||= begin
58
+ cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint])
59
+ connection = Fog::Compute.new(
60
+ :provider => :cloudstack,
61
+ :cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id],
62
+ :cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key],
63
+ :cloudstack_host => cloudstack_uri.host,
64
+ :cloudstack_port => cloudstack_uri.port,
65
+ :cloudstack_path => cloudstack_uri.path,
66
+ :cloudstack_scheme => cloudstack_uri.scheme
67
+ )
68
+ end
69
+ end
70
+
71
+ def locate_config_value(key)
72
+ key = key.to_sym
73
+ Chef::Config[:knife][key] || config[key]
74
+ end
75
+
76
+ def msg_pair(label, value, color=:cyan)
77
+ if value && !value.to_s.empty?
78
+ puts "#{ui.color(label, color)}: #{value}"
79
+ end
80
+ end
81
+
82
+ def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint])
83
+ errors = []
84
+
85
+ keys.each do |k|
86
+ pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
87
+ if Chef::Config[:knife][k].nil?
88
+ errors << "You did not provided a valid '#{pretty_key}' value."
89
+ end
90
+ end
91
+
92
+ if errors.each{|e| ui.error(e)}.any?
93
+ exit 1
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+ end
100
+
101
+