knife-cloudstack-fog 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ *.old
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/CHANGES.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = Changes
2
+
3
+ == 2012-15-03 (0.2.0)
4
+ * Brought in sync with Chirajog's knife-cloudstack plugin. Rewritten to leverage FOG CloudStack support (available in GIT
5
+ gem), HTTP/HTTPS, and Security Groups.
6
+
7
+ == 2011-11-03 (0.0.11)
8
+ * Added LICENSE file and licensing headers to source. No feature changes.
9
+
10
+ == 2011-10-13 (0.0.10)
11
+ * Support for multi-homed VMs: The --networks option for the <tt>server create</tt> command takes a comma-separated list
12
+ of network offering names. The created VM will have one nic per network, with nics assigned to networks in the order
13
+ specified (e.g. the first network in the list will be assigned to eth0, the second to eth1 and so on). The --networks
14
+ option replaces the --network option, which supported a single network name.
15
+ * The <tt>server list</tt> command now shows the VM 'displayname' in parentheses when the displayname is defined and is
16
+ different than the VM name.
17
+ * Public IP logic has been updated to support multi-homed VMs. It now uses the first nic attached to a network with the
18
+ 'default' value set to true as the primary interface.
19
+
20
+ == 2011-08-30 (0.0.9)
21
+ * Added subcommands: <tt>server start</tt>, <tt>server stop</tt> and <tt>server reboot</tt>.
22
+ * Updated the <tt>hosts</tt> command to return short hostnames and FQDNs. Also added comments where needed so the output
23
+ can be directly pasted into /etc/hosts.
24
+
25
+ == 2011-08-06 (0.0.8)
26
+ * Changed cloudstack async command timeout from 60 to 300 seconds.
27
+
28
+ == 2011-07-21 (0.0.7)
29
+ * Fixed http_request actions in <tt>stack create</tt>.
30
+
31
+ == 2011-07-15 (0.0.6)
32
+ * The <tt>server delete</tt> command now deletes the chef node and client if their names match the fqdn of the server.
33
+ * Added the <tt>stack create</tt> and <tt>stack delete</tt> commands for bulk creation and deletion of servers using a
34
+ JSON definition file. These commands are still experimental and subject to change. See README.rdoc for details.
35
+ * Added a <tt>hosts</tt> command, which lists the public ip address and fqdn of all servers in /etc/hosts file format.
36
+ * Fixed nil reference bug in <tt>server list</tt> command.
37
+
38
+ == 2011-06-05 (0.0.5)
39
+ * Added <tt>--port-rules</tt> option to the <tt>cs server create</tt> command. It accepts a list of port forwarding
40
+ rules to be created for the server (only applies to servers on a virtual network). See 'Port forwarding rules for
41
+ virtual networks' in README.rdoc for details.
42
+
43
+ == 2011-06-01 (0.0.4)
44
+ * Fixed ssh detection bug.
45
+
46
+ == 2011-05-30 (0.0.3)
47
+
48
+ * Added support for virtual networks. A public IP address is allocated for each new server in a virtual network
49
+ and an ssh port forwarding rule is created. The IP is released when the server is destroyed as long as it doesn't
50
+ have forwarding rules for any servers other than the one being deleted.
51
+ * Default network is now detected automatically. If there is more than one network marked as 'default' for an
52
+ account, the first Direct network is preferred.
53
+
54
+ == 2011-05-22 (0.0.2)
55
+
56
+ * Added subcommands: <tt>service list</tt>, <tt>template list</tt>, <tt>network list</tt> and <tt>zone list</tt>.
57
+ * Removed -H (and --hostname) option from the <tt>cs server create</tt> command. The host name is now the first
58
+ argument to the command: <tt>knife cs server create myhostname</tt>. If a host name is not specified, CloudStack
59
+ will use an auto-generated name.
60
+ * Added --no-bootstrap option to the server create command. This prevents Chef from being installed on the new server.
61
+ * Fixed help banners (commands were shown as <tt>knife cloudstack ...</tt> instead of <tt>knife cs ...</tt>).
62
+ * Added README.rdoc.
63
+
64
+ == 2011-05-15 (0.0.1)
65
+
66
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-cloudstack.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,111 @@
1
+ = Knife Cloudstack
2
+
3
+ = DESCRIPTION:
4
+
5
+ This is the unofficial Opscode Knife plugin for Cloudstack Cloud. This plugin gives knife the ability to create, bootstrap, and manage instances in Cloudstack Compute clouds.
6
+
7
+ = INSTALLATION:
8
+
9
+ Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
10
+
11
+ $ gem install chef
12
+
13
+ Also ensure you are running the latest version of Fog. Versions earlier than 1.0.0 don't support Cloudstack Cloud:
14
+
15
+ $ gem update fog
16
+
17
+ This plugin is distributed as a Ruby Gem. To install it, run:
18
+
19
+ $ gem install knife-cloudstack
20
+
21
+ Depending on your system's configuration, you may need to run this command with root privileges.
22
+
23
+ = CONFIGURATION:
24
+
25
+ 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:
26
+
27
+ ### Note: You may need to append the :cloudstack_access_key_id with ":$PROJECT_NAME", if it differs from your Cloudstack Username.
28
+ knife[:cloudstack_access_key_id] = "Your Cloudstack Access Key ID"
29
+ knife[:cloudstack_secret_access_key] = "Your Cloudstack Secret Access Key"
30
+ ### Note: If you are not proxying HTTPS to the Cloudstack CLOUDSTACK API port, the scheme should be HTTP, and the PORT is 8773.
31
+ knife[:cloudstack_api_endpoint] = "https://cloud.mycompany.com/service/Cloud"
32
+
33
+ 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:
34
+
35
+ knife[:cloudstack_access_key_id] = "#{ENV['CLOUDSTACK_ACCESS_KEY']}"
36
+ knife[:cloudstack_secret_access_key] = "#{ENV['CLOUDSTACK_SECRET_KEY']}"
37
+ knife[:cloudstack_api_endpoint] = "#{ENV['CLOUDSTACK_URL']}"
38
+
39
+ 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
40
+
41
+ # provision a new webserver
42
+ 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'
43
+
44
+ Additionally the following options may be set in your `knife.rb`:
45
+
46
+ * flavor
47
+ * image
48
+ * availability_zone
49
+
50
+ = SUBCOMMANDS:
51
+
52
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
53
+
54
+ == knife cloudstack server create
55
+
56
+ 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 {ubuntu10.04-gems}[https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb] template. This can be overridden using the <tt>-d</tt> or <tt>--template-file</tt> command options.
57
+
58
+ == knife cloudstack server delete
59
+
60
+ 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.
61
+
62
+ == knife cloudstack server list
63
+
64
+ 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.
65
+
66
+ == knife cloudstack serviceoffering list
67
+
68
+ 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.
69
+
70
+ == knife cloudstack template list
71
+
72
+ 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.
73
+
74
+ == knife cloudstack keypair list
75
+
76
+ 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.
77
+
78
+ == knife cloudstack networks list
79
+
80
+ 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.
81
+
82
+ == knife cloudstack securitygroup list
83
+
84
+ 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.
85
+
86
+ == knife cloudstack zone list
87
+
88
+ 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.
89
+
90
+ == knife cloudstack diskofferings list
91
+
92
+ 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.
93
+
94
+
95
+ = LICENSE:
96
+
97
+ Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>)
98
+ Copyright:: Copyright (c) 2011 Clogeny, 2012 Datapipe
99
+ License:: Apache License, Version 2.0
100
+
101
+ Licensed under the Apache License, Version 2.0 (the "License");
102
+ you may not use this file except in compliance with the License.
103
+ You may obtain a copy of the License at
104
+
105
+ http://www.apache.org/licenses/LICENSE-2.0
106
+
107
+ Unless required by applicable law or agreed to in writing, software
108
+ distributed under the License is distributed on an "AS IS" BASIS,
109
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
110
+ See the License for the specific language governing permissions and
111
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,41 @@
1
+ bash -c '
2
+ <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
3
+
4
+ if [ ! -f /usr/bin/chef-client ]; then
5
+ wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
6
+ rpm -Uvh epel-release-5-4.noarch.rpm
7
+ wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>-O /etc/yum.repos.d/aegis.repo http://rpm.aegisco.com/aegisco/el5/aegisco.repo
8
+ yum install gcc gcc-c++ automake autoconf make ruby.x86_64 ruby-devel.x86_64 ruby-libs.x86_64 ruby-ri.x8_64 ruby-rdoc.x86_64 -y
9
+ yum remove ruby-libs.i386 -y
10
+ wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz
11
+ tar zxf rubygems-1.7.2.tgz
12
+ cd rubygems-1.7.2
13
+ ruby setup.rb --no-format-executable
14
+ gem install chef -V --no-rdoc --no-ri
15
+
16
+ fi
17
+
18
+
19
+ mkdir -p /etc/chef
20
+
21
+ (
22
+ cat <<'EOP'
23
+ <%= validation_key %>
24
+ EOP
25
+ ) > /tmp/validation.pem
26
+ awk NF /tmp/validation.pem > /etc/chef/validation.pem
27
+ rm /tmp/validation.pem
28
+
29
+ (
30
+ cat <<'EOP'
31
+ <%= config_content %>
32
+ EOP
33
+ ) > /etc/chef/client.rb
34
+
35
+ (
36
+ cat <<'EOP'
37
+ <%= { "run_list" => @run_list }.to_json %>
38
+ EOP
39
+ ) > /etc/chef/first-boot.json
40
+
41
+ <%= start_chef %>'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-cloudstack/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "knife-cloudstack-fog"
7
+ s.version = Knife::Cloudstack::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
11
+ s.authors = ["Chirag Jog", "Jeff Moody"]
12
+ s.email = ["chirag@clogeny.com", "jmoody@datapipe.com"]
13
+ s.homepage = "https://github.com/fifthecho/knife-cloudstack-fog"
14
+ s.summary = %q{Cloudstack Compute Support for Chef's Knife Command}
15
+ s.description = %q{Support for the Chef Knife command, leveraging FOG, for the Citrix CloudStack API}
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "fog", "~> 1.1.2"
23
+ end
@@ -0,0 +1,105 @@
1
+ #
2
+ # Author:: Chirag Jog (<chirag@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2011 Clogeny Technologies.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
7
+ # Copyright:: Copyright (c) 2012 Datapipe
8
+ # License:: Apache License, Version 2.0
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+
23
+ require 'chef/knife'
24
+
25
+ class Chef
26
+ class Knife
27
+ module CloudstackBase
28
+
29
+ # :nodoc:
30
+ # Would prefer to do this in a rational way, but can't be done b/c of
31
+ # Mixlib::CLI's design :(
32
+ def self.included(includer)
33
+ includer.class_eval do
34
+
35
+ deps do
36
+ require 'fog'
37
+ require 'readline'
38
+ require 'chef/json_compat'
39
+ end
40
+
41
+ option :cloudstack_access_key_id,
42
+ :short => "-A ID",
43
+ :long => "--cloudstack-access-key-id KEY",
44
+ :description => "Your Cloudstack Access Key ID",
45
+ :proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey }
46
+
47
+ option :cloudstack_secret_access_key,
48
+ :short => "-K SECRET",
49
+ :long => "--cloudstack-secret-access-key SECRET",
50
+ :description => "Your Cloudstack API Secret Access Key",
51
+ :proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey }
52
+
53
+ option :cloudstack_api_endpoint,
54
+ :long => "--cloudstack-api-endpoint ENDPOINT",
55
+ :description => "Your Cloudstack API endpoint",
56
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint }
57
+ end
58
+ end
59
+
60
+ def connection
61
+ @connection ||= begin
62
+ cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint])
63
+ connection = Fog::Compute.new(
64
+ :provider => :cloudstack,
65
+ :cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id],
66
+ :cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key],
67
+ :cloudstack_host => cloudstack_uri.host,
68
+ :cloudstack_port => cloudstack_uri.port,
69
+ :cloudstack_path => cloudstack_uri.path,
70
+ :cloudstack_scheme => cloudstack_uri.scheme
71
+ )
72
+ end
73
+ end
74
+
75
+ def locate_config_value(key)
76
+ key = key.to_sym
77
+ Chef::Config[:knife][key] || config[key]
78
+ end
79
+
80
+ def msg_pair(label, value, color=:cyan)
81
+ if value && !value.to_s.empty?
82
+ puts "#{ui.color(label, color)}: #{value}"
83
+ end
84
+ end
85
+
86
+ def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint])
87
+ errors = []
88
+
89
+ keys.each do |k|
90
+ pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
91
+ if Chef::Config[:knife][k].nil?
92
+ errors << "You did not provided a valid '#{pretty_key}' value."
93
+ end
94
+ end
95
+
96
+ if errors.each{|e| ui.error(e)}.any?
97
+ exit 1
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+ end
104
+
105
+
@@ -0,0 +1,57 @@
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackDiskofferingsList < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack diskofferings list (options)"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ diskoffering_list = [
35
+ ui.color('ID', :bold),
36
+ ui.color('Name', :bold),
37
+ ui.color('Description', :bold),
38
+ ui.color('Disk Size (in GB)', :bold)
39
+ ]
40
+ response = connection.list_disk_offerings['listdiskofferingsresponse']
41
+ if diskofferings = response['diskoffering']
42
+ diskofferings.each do |diskoffering|
43
+ diskoffering_list << diskoffering['id'].to_s
44
+ diskoffering_list << diskoffering['name'].to_s
45
+ diskoffering_list << diskoffering['displaytext'].to_s
46
+ disk_size = diskoffering['disksize']
47
+ diskoffering_list << disk_size.to_s
48
+
49
+ end
50
+ end
51
+ puts ui.list(diskoffering_list, :columns_across, 4)
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end