diff --git a/.gitignore b/.gitignore
index 4b35972..b91d6d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,19 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+.idea
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
pkg
-dist
-make*
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+
diff --git a/CHANGES.rdoc b/CHANGES.rdoc
deleted file mode 100644
index 2358cc4..0000000
--- a/CHANGES.rdoc
+++ /dev/null
@@ -1,160 +0,0 @@
-= Changes
-
-== 2014-03-04 (0.0.17)
-* Added support for --isdynamicallyscalable for cs template register (Sander Botman, 3 Apr 2014)
-* Added support for --anti-affinity-groups for cs server create (John E. Vincent, 2 Apr 2014)
-* Bugfix: on winrm bootstrap (Sander van Harmelen, 26 Mar 2014)
-* Added support for --expunge for destroying server (Ian Southam, 19 Mar 2014)
-* Bugfix: cosmetic changes on error output (Sander Botman, 5 Mar 2014)
-
-== 2014-02-12 (0.0.16)
-* Added support for --no-public-ip for cs server list (Sander Botman, 12 Feb 2014)
-* Added support for secret and secret_file in cs server create (Jeremy Baumont, 10 Feb 2014)
-* Bugfix: correction in isextractable on cs template register (Etharin, 30 Jan 2014
-* Added support for private-ip in cs server create (Joaquim Dos Santos, 26 Jan 2014)
-* Bugfix: Keypair support on stack create (Ben Langfeld, 29 Nov 2013)
-* Bugfix: Bootstrap even without port_rules options (Ben Langfeld, 29 Nov 2013)
-* Bugfix: Option to specify iso as template when deploying instance cs server create (Sander Botman, 28 Nov 2013)
-* Restructure all list commands (Sander Botman, 28 Nov 2013)
-* Added subcommand: cs aag list (John E. Vincent, 23 Nov 2013)
-* Added support for anti-affinity groups in cs server create (John E. Vincent, 23 Nov 2013)
-* Added subcommand: cs server add nic (John E. Vincent, 13 Nov 2014)
-* Added Trademark (David Nalley, 08 Nov 2013)
-* Bugfix: fixing server creation inside basic networks (Sander Botman, 07 Nov 2013)
-
-== 2013-11-04 (0.0.15)
-* Bugfix: fixed the proxy with the option: --cloudstack-proxy http://username:password@yourproxy:8080 or use config file. (Sander Botman, 04 Nov 2013)
-* Added subcommand: cs publicip list (Sander Botman, 03 Nov 2013)
-* Bugfix: removed the chef rest dependency because this is changed in chef 11.8.0 (Sander Botman, 03 Nov 2013)
-* Bugfix: added the option --cloudstack-no-ssl-verify in order to ignore ssl verification (Sander Botman, 03 Nov 2013)
-* Added subcommand: cs forwardrule create (Sander Botman, 28 Aug 2013)
-* Added subcommand: cs firewallrule create (Sander Botman, 28 Aug 2013)
-* Added the option: --set-display-name to server create (Florin Stan, 5 Aug 2013)
-* Added the option: --keypair to server create (Florin Stan, 31 Jul 2013)
-* Added subcommand: cs volume create (Jeremy Baumont, 17 Jul 2013)
-* Added the option: --disk to server create (Stanislav Voroniy (voroniys) 13 Jun 2013)
-* Added subcommands: cs keypair list, cs keypair create, cs keypair delete and adding basic zone check. (Sebastian Goasguen (runseb) 29 May 2013)
-* Bugfix: changed output name to password (Warren Bain, 26 May 2013)
-* Bugfix: various bugfixes and fixing bootstrap context (bacoboy, 22 Apr 2013)
-
-== 2013-04-14 (0.0.14)
-* Added bash/addinstance.sh script in onder to ease instance creation from cli.
-
-* Added the cs_base.rb to merge all common options.
-* Added the cs_base_list.rb to merge all common options and functions for the list commands.
-* Added the option: -P / --cloudstack-project to the following commands: account list, firewallrule list, hosts,
- iso list, network list, router list, server list, template list, volume list
-
-* Added subcommands: account list, cluster list, config list, disk create,
- disk list, domain list,firewallrule list, host list,
- iso list, ostype list, oscategory list, pod list, project list,
- service create, template create, template extract, template register, router list, user list, volume list
-
-* Updated subcommands: hosts, network list, server list, service list,
- template list, zone list
-
-* Added option: --filter to all list commands. This filters your output on the fields that you specify.
- Filter can be a string 'name' or regexp '/name/i'. Example: --filter "instancename:/i-xxx/i,accountname:jenkins"
- Additional filters can be added by separating them using a comma ','
- NOTE: --filter is done client side, filtering by --name or --keyword is faster and is done server side.
-
-* Added option: --fields to all list commands. Here you specify the fields that you want to display in your output.
- Default outputs will be shown if no fields are defined. Example: --fields "name, instancename, domain"
-
-* Added option: --noheader to all list commands.
- This will remove the header from the output.
-
-* Added option: --fieldlist to all list commands. This will display the fields that you can use to filter or
- use in your output. Example will be given with the first result that you specify in your filter.
-
-* Added option: --listall to: account list, domain list, firewallrule list, hosts, iso list,
- network list, project list, router list, server list, template list, user list, volume list.
-
-* Added option: --keyword to: account list, cluster list, config list, disk list, firewallrule list,
- hosts, iso list, network list, ostype list, oscategory list, pod list, project list, router list,
- server list, service list, user list, volume list, zone list.
-
-* Added option: --name to: account list, cluster list, config list, disk list, host list, hosts, iso list,
- pod list, project list, router list, server list, service list, volume list
-
-* Added option: --action to: server list which start, stop or destroy the machines based on the result.
-* Added option: --cloudstack-password to let cloudstack generate the password (only works if your template supports this.)
-* Added option: --ipfwd-rules and --fw-rules to: server create
-* Fixed delay-loading.
-* Fixed -F json / --format json option for every list command.
-* Fixed --no-bootstrap option to ignore the chef bootstrap
-* Fixed default bootstrap template to: chef-full
-
-
-== 2012-11-29 (0.0.13)
-* Windows support
- https://github.com/CloudStack-extras/knife-cloudstack/issues/31
-* Support for Projects
-* HTTPS support
-
-== 2012-05-17 (0.0.12)
-* Adding option to disable public IP allocation on server create
- https://github.com/CloudStack/knife-cloudstack/pull/8
-* Fix whitespace issue in network names
- https://github.com/CloudStack/knife-cloudstack/pull/7
-
-== 2011-11-03 (0.0.11)
-* Added LICENSE file and licensing headers to source. No feature changes.
-
-== 2011-10-13 (0.0.10)
-* Support for multi-homed VMs: The --networks option for the server create command takes a comma-separated list
- of network offering names. The created VM will have one nic per network, with nics assigned to networks in the order
- specified (e.g. the first network in the list will be assigned to eth0, the second to eth1 and so on). The --networks
- option replaces the --network option, which supported a single network name.
-* The server list command now shows the VM 'displayname' in parentheses when the displayname is defined and is
- different than the VM name.
-* Public IP logic has been updated to support multi-homed VMs. It now uses the first nic attached to a network with the
- 'default' value set to true as the primary interface.
-
-== 2011-08-30 (0.0.9)
-* Added subcommands: server start, server stop and server reboot.
-* Updated the hosts command to return short hostnames and FQDNs. Also added comments where needed so the output
- can be directly pasted into /etc/hosts.
-
-== 2011-08-06 (0.0.8)
-* Changed cloudstack async command timeout from 60 to 300 seconds.
-
-== 2011-07-21 (0.0.7)
-* Fixed http_request actions in stack create.
-
-== 2011-07-15 (0.0.6)
-* The server delete command now deletes the chef node and client if their names match the fqdn of the server.
-* Added the stack create and stack delete commands for bulk creation and deletion of servers using a
- JSON definition file. These commands are still experimental and subject to change. See README.rdoc for details.
-* Added a hosts command, which lists the public ip address and fqdn of all servers in /etc/hosts file format.
-* Fixed nil reference bug in server list command.
-
-== 2011-06-05 (0.0.5)
-* Added --port-rules option to the cs server create command. It accepts a list of port forwarding
- rules to be created for the server (only applies to servers on a virtual network). See 'Port forwarding rules for
- virtual networks' in README.rdoc for details.
-
-== 2011-06-01 (0.0.4)
-* Fixed ssh detection bug.
-
-== 2011-05-30 (0.0.3)
-
-* Added support for virtual networks. A public IP address is allocated for each new server in a virtual network
- and an ssh port forwarding rule is created. The IP is released when the server is destroyed as long as it doesn't
- have forwarding rules for any servers other than the one being deleted.
-* Default network is now detected automatically. If there is more than one network marked as 'default' for an
- account, the first Direct network is preferred.
-
-== 2011-05-22 (0.0.2)
-
-* Added subcommands: service list, template list, network list and zone list.
-* Removed -H (and --hostname) option from the cs server create command. The host name is now the first
- argument to the command: knife cs server create myhostname. If a host name is not specified, CloudStack
- will use an auto-generated name.
-* Added --no-bootstrap option to the server create command. This prevents Chef from being installed on the new server.
-* Fixed help banners (commands were shown as knife cloudstack ... instead of knife cs ...).
-* Added README.rdoc.
-
-== 2011-05-15 (0.0.1)
-
-* Initial release
diff --git a/Gemfile b/Gemfile
index c80ee36..1925c91 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,5 @@
-source "http://rubygems.org"
+source 'https://rubygems.org'
+# Specify your gem's dependencies in knife-cloudstack.gemspec
gemspec
+gem 'knife-cloud', :git => 'https://github.com/sbotman/knife-cloud.git'
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index d645695..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..1b22bef
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d0c05d2
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+# Knife::Cloudstack
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'knife-cloudstack'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install knife-cloudstack
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it ( http://github.com//knife-cloudstack/fork )
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
diff --git a/README.rdoc b/README.rdoc
deleted file mode 100644
index 2500584..0000000
--- a/README.rdoc
+++ /dev/null
@@ -1,425 +0,0 @@
-= knife-cloudstack
-
-{}[https://codeclimate.com/github/CloudStack-extras/knife-cloudstack]
-{}[https://gemnasium.com/CloudStack-extras/knife-cloudstack]
-
-== DESCRIPTION:
-
-This is the Edmunds Knife plugin for CloudStack. This plugin gives Knife the ability to create, bootstrap and manage
-CloudStack instances.
-
-== INSTALLATION:
-This plugin is distributed as a Ruby Gem. To install it, run:
-
- gem install knife-cloudstack
-
-Depending on your system's configuration, you may need to run this command with root privileges.
-
-== CONFIGURATION:
-In order to communicate with the CloudStack API you will have to tell Knife about your CloudStack API Key, your Secret Key and the URL of the API endpoint.
-The easiest way to accomplish this is to create some entries in your knife.rb file:
-
- knife[:cloudstack_url] = "http://yourcloudstackserver.com:8080/client/api
- knife[:cloudstack_api_key] = "Your CloudStack API Key"
- knife[:cloudstack_secret_key] = "Your CloudStack Secret Key"
-
-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:
-
- knife[:cloudstack_url] = "#{ENV['CLOUDSTACK_URL']}"
- knife[:cloudstack_api_key] = "#{ENV['CLOUDSTACK_API_KEY']}"
- knife[:cloudstack_secret_key] = "#{ENV['CLOUDSTACK_SECRET_KEY']}"
-
-You also have the option of passing your CloudStack URL and API/Secret Keys into the individual knife subcommands using the -U (or --cloudstack-url),
--A (or --cloudstack-api-key ) -K (or --cloudstack-secret-key) command options
- # provision a new small RHEL 5.6 webserver
- knife cs server create my-server -r 'role[webserver]' -S "small" -T "RHEL 5.6 Base" -A 'Your CloudStack API Key' -K "Your CloudStack Secret Key" --distro "rhel5-gems"
-
-Additionally the following options may be set in your knife.rb:
-
-* knife[:cloudstack_service]
-* knife[:cloudstack_template]
-* knife[:cloudstack_zone]
-* knife[:cloudstack_proxy]
-* knife[:cloudstack_no_ssl_verify]
-* knife[:distro]
-* knife[:template_file]
-
-== Public Clouds (Tata InstaCompute, Ninefold etc):
-To get this plugin to work in public clouds, it is essential that the virtual network (and router) be allocated to the account. Cloudstack clouds automatically creates a virtual network when the first VM is requested to be created. Hence, it is essential to create the first VM (of a newly created account) manually(which can be terminated immediately if not required) to ensure the virtual network is created.
-
-== SUBCOMMANDS:
-
-This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --help flag
-
-=== knife cs list
-
---filter Filters your output on the fields that you specify. Filter can be a string 'name' or regexp '/name/i'
- Example: knife cs server list --filter "instancename:/i-xxx/i, account:accname"
-
---fields The fields that you want to display in your output. Default outputs will be shown if no fields are defined.
- Example: knife cs server list --fields "name, instancename, domain"
-
---fieldlist This will display all information returned by the cloudstack API. These fields can be used within the --fields or --filter to create custom output.
-The data displayed is based on first result returned in your output. You can get other result by using the --filter option.
-
---noheader this will remove the column header from the output.
-
-
-=== knife cs server create
-
-Provisions a new server in CloudStack and then performs 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 (default bootstrap option for knife,
-(Ref. http://docs.opscode.com/knife_bootstrap.html). This can be overridden using the -d or --template-file command options.
-VM provided with --no-bootstrap option have no forwarded ports or forwared ip rules (in case --static-nat is used).
-
-By default, new servers are allocated a public IP address mapping to the CloudStack private IP address. If you do not want this behavior, pass the --no-public-ip option.
-
-Forcing cloustack to reserve and use a certain private ipv4 address when deploying an instance inside an advanced zone is possible by passing followed by the intended ipv4 address. Ip Address must be contained within the network mask of the isolated network, of course.
-
- Example: knife cs server create testvm --private-ip 192.168.1.1 --networks mynetwork
-
-Here mynetwork must have a network mask for example like 192.168.1.0/24.
-
-==== Port forwarding rules for virtual networks
-The --port-rules option takes a comma separated list of port forwarding rules. These rules are created on the
-virtual public ip address of the server. Note that this option only applies to servers using a virtual network; it is
-ignored if the server's public ip address is on a direct attached network.
-
-Port forwarding rules have the syntax PUBLIC_PORT[:PRIVATE_PORT[:PROTOCOL]]. PRIVATE_PORT and
-PROTOCOL are optional. The default value of PRIVATE_PORT is PUBLIC_PORT and the default
-PROTOCOL is 'TCP'.
-For example, a rule to forward from public port 80 to private port 7000 would look like 80:7000:TCP.
-Since 'TCP' is the default protocol, the rule can be shortened to 80:7000. A rule can even be shortened to a
-single number when the public and private ports are the same. For example, a rule to forward from public port 25 to
-private port 25 can be stated as simply 25. A list of such rules for a webserver might look like
-80,443.
-
-==== IP forwarding rules
-The --ipfwd-rules option takes a comma separated list of ip forwarding rules. These rules are created on public ip appdress assigned obtained with --static-nat option.
-(Ref. http://cloudstack.apache.org/docs/api/apidocs-4.0.0/root_admin/createIpForwardingRule.html)
-
-Ip forwarding rules have the syntax START_PORT[:END_PORT[:PROTOCOL]]. END_PORT and PROTOCOL are optional.
-The default value of END_PORT is START_PORT and the default PROTOCOL is 'TCP'.
-For example, a rule to forward ports range from 1024 to 10000 would look like 1024:10000:TCP.
-Since 'TCP' is the default protocol, the rule can be shortened to 1024:10000. A rule can even be shortened to a
-single number when the start and end ports are the same. For example, a rule to forward port 22 can be stated as simply 22. A list of such rules for a webserver might look like 80,443.
-
-==== Create Firewall Rule for given ip address
-The -f, --fw-rules option takes a comma separated list of firewall rules which are applied to the public ip address assigned to the current server.
-
-Firewall rules have the syntax PROTOCOL[:CIDR_LIST[:START_PORT[:END_PORT]]]. START_PORT and END_PORT must not be specified when PROTOCOL is ICMP, CIDR_LIST is always optional.
-The default value of END_PORT is START_PORT, the default CIDR_LIST is '0.0.0.0/0'.
-For example, a rule to open firewall for port 80 to everyone would look like TCP::80 and a rule to open ICMP to internal network would look like ICMP:10.0.0.0/8.
-
-=== knife cs server delete
-
-Deletes an existing server in the currently configured CloudStack account. PLEASE NOTE - this does not delete
-the associated node and client objects from the Chef server.
-
-=== knife cs server list
-
-Displays a list of all servers in the currently configured CloudStack account. PLEASE NOTE - this shows all
-servers associated with the cloudstack account including servers that are not registered with a Chef server.
-
---listall This will list all the servers, depending on the account that you are using.
-
---keyword Filters your output on the instance name that you specify:
- Example: --keyword "i-324", This will display all servers with 'i-324' inside the instancename.
-
---name Filters your output on the name that you specify.
- Example: --name "webserver", This will display all servers that contains 'webserver' inside the hostname.
-
---action This action will be executed on the output of the list command. Actions can be start, stop or destroy.
-
-=== knife cs network list
-Displays a list of all networks available in the currently configured CloudStack account. A network can be specified
-when creating a new server by passing the network name as an argument to the -W (or --network) option of the
-knife cs server create command.
-
---listall This will list all the networks, depending on the account that you are using.
-
---keyword Filters your output on the keyword that you specify.
- Example: --keyword "network1", This will display all networks with 'network1' inside the name.
-
-=== knife cs service list
-Displays a list of all service offerings available in the currently configured CloudStack account. A service offering
-can be specified when creating a new server by passing the name as an argument to the -S (or --service) option of the
-knife cs server create command.
-
---keyword Filters your output on the service name, just like --name here below.
-
---name Filters your output on the name that you specify.
- Example: --name "medium" or --keyword "medium", This will display all cpu service offerings with 'medium' inside the name.
-
-=== knife cs template list
-Displays a list of all templates in the currently configured CloudStack account. Featured templates are displayed by default.
-Use the -F (or --filter) option to use a different filter. The allowable filter values are:
-
-* featured - templates that are featured and are public (this is the default)
-* self - templates that have been registered/created by the owner
-* self-executable - templates that have been registered/created by the owner that can be used to deploy a new VM
-* executable - all templates that can be used to deploy a new VM
-* community - templates that are public
-
-A template can be specified when creating a new server by passing the template name as an argument to the -T
-(or --template) option of the knife cs server create command.
-
---listall This will list all the templates, depending on the account that you are using.
-
-=== knife cs template create
-Creates a template based on a volumeID
-
-=== knife cs template extract
-Returns a link where an extractable template can be downloaded
-
-=== knife cs template register
-Creates a template based on a file
-
-=== knife cs volume create
-Creates a volume based on a name
-
-=== knife cs zone list
-Displays a list of all zones available in the currently configured CloudStack account. A zone can be specified
-when creating a new server by passing the zone name as an argument to the -Z (or --zone) option of the
-knife cs server create command.
-
---keyword Filters your output on the keyword that you specify.
- Example: --keyword "zone1", This will display all zones with 'zone1' inside the name
-
-=== knife cs hosts
-Convenience command that displays the public ip address and fqdn for all servers. Matches /etc/hosts file format.
-
---listall This will list all the servers, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs account list
-Displays all accounts that are currently in your cloudstack environment.
-
---listall This will list all the possible results, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs cluster list
-Displays all clusters that are currently available in your cloudstack environment.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs config list
-Displays all the configuration settings that are configured inside the cloudstack environment.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs disk list
-Displays all the disks that are available within cloudstack.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs domain list
-Displays all domains within the cloudstack environment.
-
---listall This will list all the domains, depending on the account that you are using.
-
-==== knife cs firewallrule list
-Displays all firewall rules that are currently active within your cloudstack environment.
-
---listall This will list all the firewallrules, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
-==== knife cs host list
-Displays all hosts from the cloudstack environment.
-
---name Filters your output on the name that you specify.
-
-==== knife cs iso list
-Displays all iso's that are available within the cloudstack environment.
-
---listall This will list all the iso's, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs ostype list
-Displays all the os types that are available within the cloudstack environment.
-
---keyword Filters your output on the keyword that you specify.
-
-==== knife cs oscategory list
-Displays all os categories that are available
---keyword Filters your output on the keyword that you specify.
-
-==== knife cs pod list
-Displays all the pods that are currently available within the cloudstack environment.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs project list
-Displays all the projects that are within the cloudstack environment.
-
---listall This will list all the projects, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs publicip list
-Displays all public ip's that are used within the cloudstack environment.
-
---listall This will list all the public ip's, depending on the account that you are using.
-
-==== knife cs router list
-Displays all the routers that are within the cloudstack environment.
-
---listall This will list all the routers, depending on the account that you are using.
-
---keyword Filters your result based on a keyword.
-
---name Filters your output on the name that you specify.
-
-==== knife cs user list
-Displays all the users that are available within your account.
-
---listall This will list all the users, depending on the account that you are using.
-
---keyword Filters your output on the keyword that you specify.
-
-==== knife cs volume list:
-Displays all the volumes that are currently available within the cloudstack environment.
-
---listall This will list all the volumes, depending on the account that you are using.
-
---keyword Filters your output on the keyword that you specify.
-
---name Filters your output on the name that you specify.
-
-=== knife cs stack create
-Creates a "stack" of servers based on a JSON definition file. Simple orchestration can be performed by
-specifying one or more actions to be executed after a server (or group of servers) is created.
-
-==== Example Stack Definition File:
-
- {
- "name": "hadoop_cluster_a",
- "description": "A small hadoop cluster with hbase",
- "version": "1.0",
- "environment": "production",
- "servers": [
- {
- "name": "zookeeper-a, zookeeper-b, zookeeper-c",
- "description": "Zookeeper nodes",
- "template": "rhel-5.6-base",
- "service": "small",
- "port_rules": "2181",
- "run_list": "role[cluster_a], role[zookeeper_server]",
- "actions": [
- { "knife_ssh": ["role:zookeeper_server", "sudo chef-client"] }
- ]
- },
- {
- "name": "hadoop-master",
- "description": "Hadoop master node",
- "template": "rhel-5.6-base",
- "service": "large",
- "networks": "app-net, storage-net",
- "port_rules": "50070, 50030, 60010",
- "run_list": "role[cluster_a], role[hadoop_master], role[hbase_master]"
- },
- {
- "name": "hadoop-worker-a hadoop-worker-b hadoop-worker-c",
- "description": "Hadoop worker nodes",
- "template": "rhel-5.6-base",
- "service": "medium",
- "port_rules": "50075, 50060, 60030",
- "run_list": "role[cluster_a], role[hadoop_worker], role[hbase_regionserver]",
- "actions": [
- { "knife_ssh": ["role:hadoop_master", "sudo chef-client"] },
- { "http_request": "http://${hadoop-master}:50070/index.jsp" }
- ]
- }
- ]
- }
-
-==== Stack Attributes
-name:: Stack name. May be used in the future to e.g. look up a stack in a databag.
-version:: Stack version. This attribute is not currently used.
-environment:: Chef environment used for all servers in the stack.
-servers:: List of servers to create.
-
-==== Server Attributes
-name:: The name of the new server. Specify a list of names separated by commas and/or spaces to create multiple servers.
-description:: Server description.
-template:: Cloudstack template name.
-service:: Cloudstack service offering name.
-port_rules:: Port forwarding rules for virtual networks. These are ignored when using direct or other network types.
-run_list:: Chef run list.
-actions:: List of actions to perform after the server (or group of servers) is created.
-
-==== Actions
-knife-ssh:: Performs a knife-ssh command. Takes the search query and the command to execute as an array of arguments.
-http_request:: Performs an http request. Supports references to server names in the stack with ${server_name}.
-
-==== Upcoming Actions
-The following actions are under development:
-
-runlist_add:: Adds an entry from the run list.
-runlist_remove:: Removes an entry from the run list.
-
-=== knife cs stack delete
-Deletes all servers in the specified stack definition.
-
-=== knife cs server start
-Starts the specified virtual machine(s).
-
-=== knife cs server stop
-Stops the specified virtual machine(s). Force stop is optional.
-
-=== knife cs server reboot
-Reboots the specified virtual machines(s).
-
-== LICENSE:
-
-Author:: Ryan Holmes
-Author:: KC Braunschweig
-Author:: John E. Vincent
-Author:: Sander Botman
-Author:: Frank Breedijk
-Author:: Jeremy Baumont
-Copyright:: Copyright (c) 2011 Edmunds, Inc.
-License:: Apache License, Version 2.0
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-== Trademark Attribution
-
-knife is a trademark of Opscode
-
-CloudStack is a trademark or registered trademark of The Apache Software Foundation
-
-The use of these marks is nominative in describing the function and integration of
-this software and does not imply endorsement by Opscode, the Apache Software Foundation,
-or Apache CloudStack.
diff --git a/knife-cloudstack.gemspec b/knife-cloudstack.gemspec
index fbf2e2f..46f8025 100644
--- a/knife-cloudstack.gemspec
+++ b/knife-cloudstack.gemspec
@@ -1,18 +1,27 @@
-Gem::Specification.new do |s|
- s.name = %q{knife-cloudstack}
- s.version = "0.0.17"
- s.date = %q{2014-04-03}
- s.authors = ['Ryan Holmes', 'KC Braunschweig', 'John E. Vincent', 'Chirag Jog', 'Sander Botman']
- s.email = ['rholmes@edmunds.com', 'kcbraunschweig@gmail.com', 'lusis.org+github.com@gmail.com', 'chirag.jog@me.com', 'sbotman@schubergphilis.com']
- s.summary = %q{A knife plugin for the CloudStack API}
- s.homepage = %q{http://cloudstack.org/}
- s.description = %q{A Knife plugin to create, list and manage CloudStack servers}
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'knife-cs/version'
- s.has_rdoc = false
- s.extra_rdoc_files = ["README.rdoc", "CHANGES.rdoc", "LICENSE" ]
+Gem::Specification.new do |spec|
+ spec.name = "knife-cloudstack"
+ spec.version = Knife::Cloudstack::VERSION
+ spec.authors = ["Sander Botman"]
+ spec.email = ["sbotman@schubergphilis.com"]
+ spec.summary = %q{CloudStack Support for Chef's Knife Command}
+ spec.description = %q{CloudStack Support for Chef's Knife Command using knife-cloud}
+ spec.homepage = ""
+ spec.license = "Apache 2.0"
- s.add_dependency "chef", ">= 0.10.0"
- s.add_dependency "knife-windows", ">= 0"
- s.require_path = 'lib'
- s.files = ["CHANGES.rdoc","README.rdoc", "LICENSE"] + Dir.glob("lib/**/*")
+ spec.files = `git ls-files -z`.split("\x0")
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.require_paths = ["lib"]
+
+ spec.add_development_dependency "bundler", "~> 1.5"
+ spec.add_development_dependency "rake"
+
+ spec.add_dependency "fog", ">= 1.10.0"
+ spec.add_dependency "chef", ">= 0.10.10"
+ spec.add_dependency "knife-windows"
end
diff --git a/lib/chef/knife/cs_aag_list.rb b/lib/chef/knife/cs_aag_list.rb
deleted file mode 100644
index ec9bda3..0000000
--- a/lib/chef/knife/cs_aag_list.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Author:: John E. Vincent ()
-# Copyright:: Copyright (c) 2013 John E. Vincent.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsAagList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs aag list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify aag name to list"
-
- option :keyword,
- :long => "--service NAME",
- :description => "Specify part of aag name to list"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Domain :domain',
- 'Type :type',
- 'Description :description',
- 'Id :id'
- ]
-
- params = { 'command' => "listAffinityGroups" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "affinitygroup")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_account_list.rb b/lib/chef/knife/cs_account_list.rb
deleted file mode 100644
index 3537894..0000000
--- a/lib/chef/knife/cs_account_list.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsAccountList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs account list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all the accounts",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify account name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- if locate_config_value(:cloudstack_project)
- columns = [
- 'Account :account',
- 'Domain :domain',
- 'Type :accounttype',
- 'Role :role',
- 'Users :user'
- ]
- params = { 'command' => "listProjectAccounts" }
- else
- columns = [
- 'Name :name',
- 'Domain :domain',
- 'State :state',
- 'Type :accounttype',
- 'Users :user'
- ]
- params = { 'command' => "listAccounts" }
- end
-
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- if locate_config_value(:cloudstack_project)
- result = connection.list_object(params, "projectaccount")
- else
- result = connection.list_object(params, "account")
- end
-
- result.each do |r|
- r['accounttype'] = 'User' if r['accounttype'] == 0
- r['accounttype'] = 'Admin' if r['accounttype'] == 1
- r['accounttype'] = 'Domain Admin' if r['accounttype'] == 2
- r['user'] = r['user'].count if r['user']
- end
-
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_base.rb b/lib/chef/knife/cs_base.rb
index 68f89b8..3777a55 100644
--- a/lib/chef/knife/cs_base.rb
+++ b/lib/chef/knife/cs_base.rb
@@ -1,6 +1,6 @@
#
# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
+# Copyright:: Copyright (c) 2014
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,15 +16,22 @@
# limitations under the License.
#
+require 'chef/knife'
+
class Chef
class Knife
- module KnifeCloudstackBase
+ module CsBase
+ # :nodoc:
+ # Would prefer to do this in a rational way, but can't be done b/c of
+ # Mixlib::CLI's design :(
def self.included(includer)
includer.class_eval do
deps do
- require 'knife-cloudstack/connection'
+ require 'fog'
+ require 'readline'
+ require 'chef/json_compat'
end
option :cloudstack_url,
@@ -44,56 +51,70 @@ def self.included(includer)
:long => "--cloudstack-secret-key SECRET",
:description => "Your CloudStack secret key",
:proc => Proc.new { |key| Chef::Config[:knife][:cloudstack_secret_key] = key }
+ end
+ end
- option :cloudstack_project,
- :short => "-P PROJECT_NAME",
- :long => '--cloudstack-project PROJECT_NAME',
- :description => "Cloudstack Project in which to create server",
- :proc => Proc.new { |v| Chef::Config[:knife][:cloudstack_project] = v },
- :default => nil
-
- option :cloudstack_no_ssl_verify,
- :long => '--cloudstack-no-ssl-verify',
- :description => "Disable certificate verify on SSL",
- :boolean => true
-
- option :cloudstack_proxy,
- :long => '--cloudstack-proxy PROXY',
- :description => "Enable proxy configuration for cloudstack api access"
-
- def validate_base_options
- unless locate_config_value :cloudstack_url
- ui.error "Cloudstack URL not specified"
- exit 1
- end
- unless locate_config_value :cloudstack_api_key
- ui.error "Cloudstack API key not specified"
- exit 1
- end
- unless locate_config_value :cloudstack_secret_key
- ui.error "Cloudstack Secret key not specified"
- exit 1
- end
- end
- def connection
- @connection ||= CloudstackClient::Connection.new(
- locate_config_value(:cloudstack_url),
- locate_config_value(:cloudstack_api_key),
- locate_config_value(:cloudstack_secret_key),
- locate_config_value(:cloudstack_project),
- locate_config_value(:cloudstack_no_ssl_verify),
- locate_config_value(:cloudstack_proxy)
- )
- end
+ def connection
+ @connection ||= begin
+ cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_url])
+ connection = Fog::Compute.new(
+ :provider => :cloudstack,
+ :cloudstack_api_key => Chef::Config[:knife][:cloudstack_api_key],
+ :cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_key],
+ :cloudstack_host => cloudstack_uri.host,
+ :cloudstack_port => cloudstack_uri.port,
+ :cloudstack_path => cloudstack_uri.path,
+ :cloudstack_scheme => cloudstack_uri.scheme
+ )
+ end
+ end
+
+ def locate_config_value(key)
+ key = key.to_sym
+ config[key] || Chef::Config[:knife][key]
+ end
+
+ def msg_pair(label, value, color=:cyan)
+ if value && !value.to_s.empty?
+ puts "#{ui.color(label, color)}: #{value}"
+ end
+ end
- def locate_config_value(key)
- key = key.to_sym
- config[key] || Chef::Config[:knife][key] || nil
- end
+ def is_image_windows?
+ image_info = connection.images.get(@server.image_id)
+ return image_info.platform == 'windows'
+ end
+
+ def validate!
+ errors = []
+ # simple validation for the moment, we need to impove this later.
+
+ if locate_config_value(:cloudstack_url).nil?
+ errors << "Please provide the API url within the configuration or with the option -U"
+ end
+
+ if locate_config_value(:cloudstack_api_key).nil?
+ errors << "Please provide the API key within the configuration or with the option -A"
+ end
+ if locate_config_value(:cloudstack_secret_key).nil?
+ errors << "Please provide the secret key within the configuration or with the option -K"
end
+
+ if errors.each{|e| ui.error(e)}.any?
+ exit 1
+ end
+ end
+
+ end
+
+ def iam_name_from_profile(profile)
+ # The IAM profile object only contains the name as part of the arn
+ if profile && profile.key?('arn')
+ name = profile['arn'].split('/')[-1]
end
+ name ||= ''
end
end
-end
+end
\ No newline at end of file
diff --git a/lib/chef/knife/cs_baselist.rb b/lib/chef/knife/cs_baselist.rb
deleted file mode 100644
index 8256e4b..0000000
--- a/lib/chef/knife/cs_baselist.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'json'
-require 'chef/knife/cs_base'
-
-class Chef
- class Knife
- module KnifeCloudstackBaseList
-
- def self.included(includer)
- includer.class_eval do
- include Chef::Knife::KnifeCloudstackBase
-
- option :filter,
- :long => "--filter 'FIELD:NAME'",
- :description => "Specify field and part of name to list"
-
- option :fields,
- :long => "--fields 'NAME, NAME'",
- :description => "The fields to output, comma-separated"
-
- option :fieldlist,
- :long => "--fieldlist",
- :description => "The available fields to output/filter",
- :boolean => true
-
- option :noheader,
- :long => "--noheader",
- :description => "Removes header from output",
- :boolean => true
- end
- end
-
- def output_format(json)
- if locate_config_value(:format) =~ /^j/i
- json_hash = {};
- json.each { |k| json_hash.merge!( k['id'] => k) }
- puts JSON.pretty_generate(json_hash)
- exit 0
- end
- end
-
- def list_object_fields(object)
- exit 1 if object.nil? || object.empty?
- object_fields = [
- ui.color('Key', :bold),
- ui.color('Type', :bold),
- ui.color('Value', :bold)
- ]
-
- object.first.sort.each do |k,v|
- object_fields << ui.color(k, :yellow, :bold)
- object_fields << v.class.to_s
- if v.kind_of?(Hash)
- object_fields << ''
- elsif v.kind_of?(Array)
- object_fields << ''
- else
- object_fields << ("#{v}").strip.to_s
- end
- end
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 3)
- end
-
- def list_object(columns, object)
-
- output_format(object)
- object_list = []
- if locate_config_value(:fields)
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
- else
- columns.each do |column|
- n = (column.split(':').first).strip
- object_list << (ui.color("#{n}", :bold) || 'N/A')
- end
- end
-
- n_columns = object_list.count
- object_list = [] if locate_config_value(:noheader)
-
- object.each do |r|
- if locate_config_value(:fields)
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
- else
- columns.each { |column| object_list << (r["#{column.split(':').last.strip}"].to_s || 'N/A') }
- end
- end
- puts ui.list(object_list, :uneven_columns_across, n_columns)
- list_object_fields(object) if locate_config_value(:fieldlist)
- end
-
- end
- end
-end
diff --git a/lib/chef/knife/cs_cluster_list.rb b/lib/chef/knife/cs_cluster_list.rb
deleted file mode 100644
index ee005bc..0000000
--- a/lib/chef/knife/cs_cluster_list.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsClusterList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs cluster list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify cluster name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Pod :podname',
- 'Zone :zonename',
- 'HypervizorType :hypervisortype',
- 'ClusterType :clustertype',
- 'AllocationState :allocationstate',
- 'ManagedState :managedstate'
- ]
-
- params = { 'command' => "listClusters" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "cluster")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_config_list.rb b/lib/chef/knife/cs_config_list.rb
deleted file mode 100644
index b4f0965..0000000
--- a/lib/chef/knife/cs_config_list.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsConfigList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs config list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify router name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Category :category',
- 'Name :name',
- 'Value :value'
- ]
-
- params = { 'command' => "listConfigurations" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "configuration")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_disk_list.rb b/lib/chef/knife/cs_disk_list.rb
deleted file mode 100644
index c6096d8..0000000
--- a/lib/chef/knife/cs_disk_list.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsDiskList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs disk list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify diskname to list"
-
- option :keyword,
- :long => "--service NAME",
- :description => "Specify part of diskname to list"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Domain :domain',
- 'Size :disksize',
- 'Comment :displaytext',
- 'Created :created'
- ]
-
- params = { 'command' => "listDiskOfferings" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "diskoffering")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_domain_list.rb b/lib/chef/knife/cs_domain_list.rb
deleted file mode 100644
index c8d66ee..0000000
--- a/lib/chef/knife/cs_domain_list.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsDomainList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs domain list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all the domains",
- :boolean => true
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'ID :id',
- 'Level :level',
- 'Path :path'
- ]
-
- params = { 'command' => "listDomains" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
-
- result = connection.list_object(params, "domain")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_firewallrule_create.rb b/lib/chef/knife/cs_firewallrule_create.rb
deleted file mode 100644
index 1733060..0000000
--- a/lib/chef/knife/cs_firewallrule_create.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsFirewallruleCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs firewallrule create hostname 8080:8090:TCP:10.0.0.0/24"
-
- option :syncrequest,
- :long => "--sync",
- :description => "Execute command as sync request",
- :boolean => true
-
- def run
-
- hostname = @name_args.shift
- unless /^[a-zA-Z0-9][a-zA-Z0-9-]*$/.match hostname then
- ui.error "Invalid hostname. Please specify a short hostname, not an fqdn (e.g. 'myhost' instead of 'myhost.domain.com')."
- exit 1
- end
-
- params = {}
- locate_config_value(:openfirewall) ? params['openfirewall'] = 'true' : params['openfirewall'] = 'false'
-
- # Lookup all server objects.
- connection_result = connection.list_object(
- "listVirtualMachines",
- "virtualmachine"
- )
-
- # Lookup the hostname in the connection result
- server = {}
- connection_result.map { |n| server = n if n['name'].upcase == hostname.upcase }
-
- if server['name'].nil?
- ui.error "Cannot find hostname: #{hostname}."
- exit 1
- end
-
- # Lookup the public ip address of the server
- server_public_address = connection.get_server_public_ip(server)
- ip_address = connection.get_public_ip_address(server_public_address)
-
- if ip_address.nil? || ip_address['id'].nil?
- ui.error "Cannot find public ip address for hostname: #{hostname}."
- exit 1
- end
-
- @name_args.each do |rule|
- create_port_forwarding_rule(ip_address, server['id'], rule, connection, params)
- end
-
- end
-
- def create_port_forwarding_rule(ip_address, server_id, rule, connection, other_params)
- args = rule.split(':')
- startport = args[0]
- endport = args[1] || args[0]
- protocol = args[2] || "TCP"
- cidrlist = args[3] || "0.0.0.0/0"
-
- # Required parameters
- params = {
- 'command' => 'createFirewallRule',
- 'ipaddressId' => ip_address['id'],
- 'protocol' => protocol
- }
-
- # Optional parameters
- opt_params = {
- 'startport' => startport,
- 'endport' => endport,
- 'cidrlist' => cidrlist
- }
-
- params.merge!(opt_params)
-
- Chef::Log.debug("Creating Firewall Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, start: #{startport} end: #{endport} cidr: #{cidrlist}")
-
- if locate_config_value(:syncrequest)
- result = connection.send_request(params)
- Chef::Log.debug("JobResult: #{result}")
- else
- result = connection.send_async_request(params)
- Chef::Log.debug("AsyncJobResult: #{result}")
- end
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_firewallrule_list.rb b/lib/chef/knife/cs_firewallrule_list.rb
deleted file mode 100644
index c975b5a..0000000
--- a/lib/chef/knife/cs_firewallrule_list.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsFirewallruleList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs firewallrule list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all firewall rules",
- :boolean => true
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'ID :id',
- 'Protocol :protocol',
- 'Start Port :startport',
- 'End Port :endport',
- 'IP AddressID :ipaddressid',
- 'IP Address :ipaddress',
- 'State :state',
- 'CIDR List :cidrlist'
- ]
-
- params = { 'command' => "listFirewallRules" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
-
- result = connection.list_object(params, "firewallrule")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_forwardrule_create.rb b/lib/chef/knife/cs_forwardrule_create.rb
deleted file mode 100644
index e89868e..0000000
--- a/lib/chef/knife/cs_forwardrule_create.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsForwardruleCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs forwardrule create hostname 8080:8090:TCP"
-
- option :openfirewall,
- :long => "--openfirewall",
- :description => "Add rule also to firewall",
- :boolean => true
-
- option :syncrequest,
- :long => "--sync",
- :description => "Execute command as sync request",
- :boolean => true
-
- def run
-
- hostname = @name_args.shift
- unless /^[a-zA-Z0-9][a-zA-Z0-9-]*$/.match hostname then
- ui.error "Invalid hostname. Please specify a short hostname, not an fqdn (e.g. 'myhost' instead of 'myhost.domain.com')."
- exit 1
- end
-
- params = {}
- locate_config_value(:openfirewall) ? params['openfirewall'] = 'true' : params['openfirewall'] = 'false'
-
- # Lookup all server objects.
- connection_result = connection.list_object(
- "listVirtualMachines",
- "virtualmachine"
- )
-
- # Lookup the hostname in the connection result
- server = {}
- connection_result.map { |n| server = n if n['name'].upcase == hostname.upcase }
-
- if server['name'].nil?
- ui.error "Cannot find hostname: #{hostname}."
- exit 1
- end
-
- # Lookup the public ip address of the server
- server_public_address = connection.get_server_public_ip(server)
- ip_address = connection.get_public_ip_address(server_public_address)
-
- if ip_address.nil? || ip_address['id'].nil?
- ui.error "Cannot find public ip address for hostname: #{hostname}."
- exit 1
- end
-
- @name_args.each do |rule|
- create_port_forwarding_rule(ip_address, server['id'], rule, connection, params)
- end
-
- end
-
- def create_port_forwarding_rule(ip_address, server_id, rule, connection, other_params)
- args = rule.split(':')
- public_port = args[0]
- private_port = args[1] || args[0]
- protocol = args[2] || "TCP"
-
- params = {
- 'ipaddressId' => ip_address['id'],
- 'protocol' => protocol
- }
-
- if ip_address['isstaticnat'] == 'true'
- other_params['command'] = 'createIpForwardingRule'
- other_params['startport'] = public_port
- other_params['endport'] = public_port
- Chef::Log.debug("Creating IP Forwarding Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, public port: #{public_port}")
- else
- other_params['command'] = 'createPortForwardingRule'
- other_params['privatePort'] = private_port
- other_params['publicPort'] = public_port
- other_params['virtualMachineId'] = server_id
- Chef::Log.debug("Creating Port Forwarding Rule for #{ip_address['id']} with protocol: #{protocol},
- public port: #{public_port} and private port: #{private_port} and server: #{server_id}")
- end
- locate_config_value(:syncrequest) ? result = connection.send_request(params.merge(other_params)) : result = connection.send_async_request(params.merge(other_params))
- Chef::Log.debug("AsyncJobResult: #{result}")
- end
- end
-end
diff --git a/lib/chef/knife/cs_host_list.rb b/lib/chef/knife/cs_host_list.rb
deleted file mode 100644
index bc5c9bb..0000000
--- a/lib/chef/knife/cs_host_list.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsHostList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs host list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify hostname to list"
-
- option :keyword,
- :long => "--service NAME",
- :description => "Specify part of hostname to list"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Address :ipaddress',
- 'State :state',
- 'Type :type',
- 'Cluster :clustername',
- 'Pod :podname',
- 'Zone :zonename',
- 'Resource :resourcestate'
- ]
-
- params = { 'command' => "listHosts" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "host")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_hosts.rb b/lib/chef/knife/cs_hosts.rb
deleted file mode 100644
index 58c80b3..0000000
--- a/lib/chef/knife/cs_hosts.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: KC Braunschweig ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsHosts < Chef::Knife
-
- MEGABYTES = 1024 * 1024
-
- include Chef::Knife::KnifeCloudstackBase
- include Chef::Knife::KnifeCloudstackBaseList
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs hosts"
-
- def run
- validate_base_options
-
- host_list = [
- ui.color('#Public IP', :bold),
- ui.color('Host', :bold),
- ui.color('FQDN', :bold)
- ]
-
- servers = connection.list_servers
- pf_rules = connection.list_port_forwarding_rules
- servers.each do |s|
- host_list << (connection.get_server_public_ip(s, pf_rules) || '#')
- host_list << (s['name'] || '')
- host_list << (connection.get_server_fqdn(s) || '')
- end
- puts ui.list(host_list, :columns_across, 3)
-
- end
- end
-end
diff --git a/lib/chef/knife/cs_iso_list.rb b/lib/chef/knife/cs_iso_list.rb
deleted file mode 100644
index d5e62e0..0000000
--- a/lib/chef/knife/cs_iso_list.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsIsoList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs iso list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all iso's",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify iso name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- option :isofilter,
- :long => "--isofilter FILTER",
- :description => "Default: 'featured'. Options: 'self','selfexecutable','sharedexecutable','executable','community'",
- :default => "featured"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Account :account',
- 'Domain :domain',
- 'Public :ispublic',
- 'Size :size',
- 'OS :ostypename'
- ]
-
- params = { 'command' => "listIsos" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- if ['all','featured','self','selfexecutable','sharedexecutable','executable','community'].include?(locate_config_value(:templatefilter))
- params['isofilter'] = locate_config_value(:isofilter)
- else
- params['isofilter'] = 'featured'
- end
-
- result = connection.list_object(params, "iso")
- result.each do |r|
- r['size'] = human_file_size(r['size']) if r['size']
- end
-
- list_object(columns, result)
- end
-
- def human_file_size n
- count = 0
- while n >= 1024 and count < 4
- n /= 1024.0
- count += 1
- end
- format("%.0f", n) + %w(B KB MB GB TB)[count]
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_keypair_create.rb b/lib/chef/knife/cs_keypair_create.rb
deleted file mode 100644
index 3dfaea5..0000000
--- a/lib/chef/knife/cs_keypair_create.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright:: Copyright (c) 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsKeypairCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs keypair create KEY_NAME (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify the ssh keypair name"
-
- option :noheader,
- :long => "--noheader",
- :description => "Removes header from output",
- :boolean => true
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate keypair name")
- keypairname = locate_config_value(:name) || @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9\-\_]*$/.match(keypairname) then
- ui.error "Invalid keypairname. Please specify a short name for the keypair"
- exit 1
- end
-
- ui.info("#{ui.color("Creating SSH Keypair: #{keypairname}", :magenta)}") unless locate_config_value(:noheader)
-
- params = {
- 'command' => 'createSSHKeyPair',
- 'name' => keypairname,
- }
-
- json = connection.send_request(params)
-
- unless json then
- ui.error("Unable to create SSH Keypair")
- exit 1
- end
-
- fingerprint = json['keypair']['fingerprint']
- privatekey = json['keypair']['privatekey']
- ui.info("Fingerprint: #{fingerprint}") unless locate_config_value(:noheader)
- ui.info(privatekey)
- puts "\n" unless locate_config_value(:noheader)
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_keypair_delete.rb b/lib/chef/knife/cs_keypair_delete.rb
deleted file mode 100644
index e270917..0000000
--- a/lib/chef/knife/cs_keypair_delete.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright:: Copyright (c) 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsKeypairDelete < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs keypair delete KEY_NAME (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify the ssh keypair name"
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate keypair name")
- keypairname = locate_config_value(:name) || @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9\-\_]*$/.match(keypairname) then
- ui.error "Invalid keypairname. Please specify a short name for the keypair"
- exit 1
- end
-
- params = {
- 'command' => 'deleteSSHKeyPair',
- 'name' => keypairname,
- }
-
- json = connection.send_request(params)
-
- unless json['success'] == 'true' then
- ui.error("Unable to delete SSH Keypair")
- exit 1
- end
- print "#{ui.color("Deleted the SSH Keypair: #{keypairname}", :magenta)}\n"
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_keypair_list.rb b/lib/chef/knife/cs_keypair_list.rb
deleted file mode 100644
index 16e9b37..0000000
--- a/lib/chef/knife/cs_keypair_list.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsKeypairList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs keypair list (options)"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Fingerprint :fingerprint'
- ]
-
- params = { 'command' => "listSSHKeyPairs" }
-
- result = connection.list_object(params, "sshkeypair")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_network_list.rb b/lib/chef/knife/cs_network_list.rb
deleted file mode 100644
index d3ad254..0000000
--- a/lib/chef/knife/cs_network_list.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsNetworkList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs network list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all networks",
- :boolean => true
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Type :type',
- 'Default :default',
- 'Shared :shared',
- 'Gateway :gateway',
- 'Netmask :netmask',
- 'Account :account',
- 'Domain :domain'
- ]
-
- params = { 'command' => "listNetworks" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
-
- result = connection.list_object(params, "network")
- list_object(columns, result)
- end
- end
-end
diff --git a/lib/chef/knife/cs_oscategory_list.rb b/lib/chef/knife/cs_oscategory_list.rb
deleted file mode 100644
index 116ec89..0000000
--- a/lib/chef/knife/cs_oscategory_list.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsOscategoryList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs oscategory list (options)"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'ID :id'
- ]
-
- params = { 'command' => "listOsCategories" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
-
- result = connection.list_object(params, "oscategory")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_ostype_list.rb b/lib/chef/knife/cs_ostype_list.rb
deleted file mode 100644
index 9d5185a..0000000
--- a/lib/chef/knife/cs_ostype_list.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsOstypeList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs ostype list (options)"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Description :description',
- 'ID :id',
- 'OS Categorie ID :oscategoryid'
- ]
-
- params = { 'command' => "listOsTypes" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
-
- result = connection.list_object(params, "ostype")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_pod_list.rb b/lib/chef/knife/cs_pod_list.rb
deleted file mode 100644
index b49906b..0000000
--- a/lib/chef/knife/cs_pod_list.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsPodList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs pod list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify router pod to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Zone :zonename',
- 'Gateway :gateway',
- 'Netmask :netmask',
- 'Start IP :startip',
- 'End IP :endip',
- 'AllocationState :allocationstate'
- ]
-
- params = { 'command' => "listPods" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "pod")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_project_list.rb b/lib/chef/knife/cs_project_list.rb
deleted file mode 100644
index 4f9a74c..0000000
--- a/lib/chef/knife/cs_project_list.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsProjectList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs project list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all projects",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify project name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Account :account',
- 'Domain :domain',
- 'State :state'
- ]
-
- params = { 'command' => "listProjects" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "project")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_publicip_list.rb b/lib/chef/knife/cs_publicip_list.rb
deleted file mode 100644
index a9074b9..0000000
--- a/lib/chef/knife/cs_publicip_list.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsPublicipList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs publicip list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all public ip addresses",
- :boolean => true
-
- def run
- validate_base_options
-
- columns = [
- 'IP :ipaddress',
- 'Account :account',
- 'Domain :domain',
- 'Zone :zonename',
- 'State :state',
- 'Allocated :allocated'
- ]
-
- params = { 'command' => "listPublicIpAddresses" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
-
- result = connection.list_object(params, "publicipaddress")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_router_list.rb b/lib/chef/knife/cs_router_list.rb
deleted file mode 100644
index 14f6923..0000000
--- a/lib/chef/knife/cs_router_list.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsRouterList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs router list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all routers",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify router name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Account :account',
- 'Domain :domain',
- 'State :state',
- 'Address :publicip'
- ]
-
- params = { 'command' => "listRouters" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "router")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_securitygroup_list.rb b/lib/chef/knife/cs_securitygroup_list.rb
deleted file mode 100644
index 35de3d1..0000000
--- a/lib/chef/knife/cs_securitygroup_list.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Author:: Sebastien Goasguen ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsSecuritygroupList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs securitygroup list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify security group to list"
-
- option :keyword,
- :long => "--keyword NAME",
- :description => "Specify part of servicename to list"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Description :description',
- 'Account :account'
- ]
-
- params = { 'command' => "listSecurityGroups" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "securitygroup")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_server_add_nic.rb b/lib/chef/knife/cs_server_add_nic.rb
deleted file mode 100644
index f6fc84b..0000000
--- a/lib/chef/knife/cs_server_add_nic.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# Author:: John E. Vincent ()
-# Copyright:: Copyright (c) 2013 John E. Vincent
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsServerAddNic < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
- include Chef::Knife::KnifeCloudstackBaseList
-
- deps do
- require 'knife-cloudstack/connection'
- require 'chef/knife'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server add nic SERVERID NETWORKID (--ipaddress X.X.X.X)"
-
- option :ipaddress,
- :long => "--ipaddress IPADDRESS",
- :description => "Attach with the specified IP",
- :default => nil
-
-
- def run
- validate_base_options
-
- @server_id, @network_id = name_args
-
- if @network_id.nil? || @server_id.nil?
- show_usage
- ui.fatal("You must provide both a network id and a server id")
- exit(1)
- end
-
- @ipaddr = locate_config_value(:ipaddress)
-
- object_list = []
- if locate_config_value(:fields)
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
- else
- object_list << ui.color('Server', :bold)
- object_list << ui.color('Network', :bold)
- object_list << ui.color('Type', :bold)
- object_list << ui.color('Default', :bold)
- object_list << ui.color('Address', :bold)
- object_list << ui.color('Gateway', :bold)
- object_list << ui.color('Netmask', :bold)
- object_list << ui.color('ID', :bold)
- end
-
- columns = object_list.count
-
- connection_result = connection.add_nic_to_vm(
- @network_id,
- @server_id,
- @ipaddr
- )
-
- output_format(connection_result)
-
- object_list << connection_result['name']
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- if connection_result['nic']
- connection_result['nic'].each do |r|
- if locate_config_value(:fields)
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
- else
- object_list << ''
- object_list << r['networkname'].to_s
- object_list << r['type'].to_s
- object_list << (r['isdefault'] ? r['isdefault'].to_s : 'false')
- object_list << (r['ipaddress'] || '')
- object_list << (r['gateway'] || '')
- object_list << (r['netmask'] || '')
- object_list << (r['networkid'] || '')
- end
- end
- puts ui.list(object_list, :uneven_columns_across, columns)
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
- else
- ui.error("No nics returned in response")
- end
- end
- end
-end
diff --git a/lib/chef/knife/cs_server_create.rb b/lib/chef/knife/cs_server_create.rb
deleted file mode 100644
index 3d1fd92..0000000
--- a/lib/chef/knife/cs_server_create.rb
+++ /dev/null
@@ -1,633 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Author:: Sander van Harmelen ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-require 'chef/knife/winrm_base'
-
-module KnifeCloudstack
- class CsServerCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
- include Chef::Knife::WinrmBase
-
- # Seconds to delay between detecting ssh and initiating the bootstrap
- BOOTSTRAP_DELAY = 20
- #The machine will reboot once so we need to handle that
- WINRM_BOOTSTRAP_DELAY = 200
-
- # Seconds to wait between ssh pings
- SSH_POLL_INTERVAL = 10
-
- deps do
- require 'chef/knife/bootstrap'
- require 'chef/knife/bootstrap_windows_winrm'
- require 'chef/knife/bootstrap_windows_ssh'
- require 'chef/knife/core/windows_bootstrap_context'
- require 'chef/knife/winrm'
- require 'socket'
- require 'net/ssh/multi'
- require 'chef/knife'
- require 'chef/knife/bootstrap'
- require 'chef/json_compat'
- require 'knife-cloudstack/connection'
- require 'winrm'
- require 'httpclient'
- require 'em-winrm'
- Chef::Knife::Bootstrap.load_deps
- end
-
- banner "knife cs server create [SERVER_NAME] (options)"
-
- option :cloudstack_service,
- :short => "-S SERVICE",
- :long => "--service SERVICE",
- :description => "The CloudStack service offering name",
- :proc => Proc.new { |o| Chef::Config[:knife][:cloudstack_service] = o },
- :default => "M"
-
- option :cloudstack_template,
- :short => "-T TEMPLATE",
- :long => "--template TEMPLATE",
- :description => "The CloudStack template for the server",
- :proc => Proc.new { |t| Chef::Config[:knife][:cloudstack_template] = t }
-
- option :cloudstack_zone,
- :short => "-Z ZONE",
- :long => "--zone ZONE",
- :description => "The CloudStack zone for the server",
- :proc => Proc.new { |z| Chef::Config[:knife][:cloudstack_zone] = z }
-
- option :cloudstack_networks,
- :short => "-W NETWORKS",
- :long => "--networks NETWORK",
- :description => "Comma separated list of CloudStack network names",
- :proc => lambda { |n| n.split(',').map {|sn| sn.strip}} ,
- :default => []
-
- option :cloudstack_disk,
- :short => "-D DISK",
- :long => "--disk DISK",
- :description => "The CloudStack disk offering name",
- :proc => Proc.new { |d| Chef::Config[:knife][:cloudstack_disk] = d }
-
- option :cloudstack_hypervisor,
- :long => '--cloudstack-hypervisor HYPERVISOR',
- :description => "The CloudStack hypervisor type for the server"
-
- option :cloudstack_password,
- :long => "--cloudstack-password",
- :description => "Enables auto-generated passwords by Cloudstack",
- :boolean => true
-
- option :public_ip,
- :long => "--[no-]public-ip",
- :description => "Allocate a public IP for this server",
- :boolean => true,
- :default => true
-
- option :ik_private_ip,
- :long => "--private-ip PRIVATE_IPV4_ADDRESS",
- :description => "Pass a certain private ipv4 address to cloudstack when deploying (only supported on isolated networks)"
-
- option :chef_node_name,
- :short => "-N NAME",
- :long => "--node-name NAME",
- :description => "The Chef node name for your new node"
-
- option :ssh_user,
- :short => "-x USERNAME",
- :long => "--ssh-user USERNAME",
- :description => "The ssh username"
-
- option :ssh_password,
- :short => "-P PASSWORD",
- :long => "--ssh-password PASSWORD",
- :description => "The ssh password"
-
- option :ssh_port,
- :long => "--ssh-port PORT",
- :description => "The ssh port",
- :default => "22"
-
- option :identity_file,
- :short => "-i IDENTITY_FILE",
- :long => "--identity-file IDENTITY_FILE",
- :description => "The SSH identity file used for authentication"
-
- option :secret_file,
- :long => "--secret-file SECRET_FILE",
- :description => "The path to the file that contains the encryption key."
-
- option :secret,
- :long => "--secret SECRET",
- :description => "The encryption key that is used for values contained within a data bag item."
-
- option :prerelease,
- :long => "--prerelease",
- :description => "Install the pre-release chef gems"
-
- option :bootstrap_version,
- :long => "--bootstrap-version VERSION",
- :description => "The version of Chef to install",
- :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
-
- option :distro,
- :short => "-d DISTRO",
- :long => "--distro DISTRO",
- :description => "Bootstrap a distro using a template",
- :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
- :default => "chef-full"
-
- option :template_file,
- :long => "--template-file TEMPLATE",
- :description => "Full path to location of template to use",
- :proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
- :default => false
-
- option :run_list,
- :short => "-r RUN_LIST",
- :long => "--run-list RUN_LIST",
- :description => "Comma separated list of roles/recipes to apply",
- :proc => lambda { |o| o.split(/[\s,]+/) },
- :default => []
-
- option :no_host_key_verify,
- :long => "--no-host-key-verify",
- :description => "Disable host key verification",
- :boolean => true,
- :default => false
-
- option :bootstrap,
- :long => "--[no-]bootstrap",
- :description => "Disable Chef bootstrap",
- :boolean => true,
- :default => true
-
- option :port_rules,
- :short => "-p PORT_RULES",
- :long => "--port-rules PORT_RULES",
- :description => "Comma separated list of port forwarding rules, e.g. '25,53:4053,80:8080:TCP'",
- :proc => lambda { |o| o.split(/[\s,]+/) },
- :default => []
-
- option :keypair,
- :long => "--keypair NAME",
- :description => "Name of the keypair that should be used to create the vm",
- :default => false
-
- option :static_nat,
- :long => '--static-nat',
- :description => 'Support Static NAT',
- :boolean => true,
- :default => false
-
- option :ipfwd_rules,
- :long => "--ipfwd-rules PORT_RULES",
- :description => "Comma separated list of ip forwarding rules, e.g. '1024:10000:TCP,1024:2048,22'",
- :proc => lambda { |o| o.split(/[\s,]+/) },
- :default => []
-
- option :aag,
- :long => "--anti-affinity-groups GROUP_NAME",
- :description => "Comma separated list of anti-affinity group names",
- :default => false
-
- option :fw_rules,
- :short => "-f PORT_RULES",
- :long => "--fw-rules PORT_RULES",
- :description => "Comma separated list of firewall rules, e.g. 'TCP:192.168.0.0/16:1024:65535,TCP::22,UDP::123,ICMP'",
- :proc => lambda { |o| o.split(/[\s,]+/) },
- :default => []
-
- option :bootstrap_protocol,
- :long => "--bootstrap-protocol protocol",
- :description => "Protocol to bootstrap windows servers. options: winrm/ssh",
- :default => "ssh"
-
- option :fqdn,
- :long => '--fqdn',
- :description => "FQDN which Kerberos Understands (only for Windows Servers)"
-
- option :set_display_name,
- :long => '--set-display-name',
- :description => "Set the same server display name as Chef node name.",
- :boolean => true,
- :default => false
-
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate hostname and options")
- hostname = @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9-]*$/.match hostname then
- ui.error "Invalid hostname. Please specify a short hostname, not an fqdn (e.g. 'myhost' instead of 'myhost.domain.com')."
- exit 1
- end
- validate_options
-
- # This little peace of code sets the Chef node-name to the VM name when a node-name is not specifically given
- unless locate_config_value :chef_node_name
- config[:chef_node_name] = @name_args.first
- end
-
- if @windows_image and locate_config_value(:kerberos_realm)
- Chef::Log.debug("Load additional gems for AD/Kerberos Authentication")
- if @windows_platform
- require 'em-winrs'
- else
- require 'gssapi'
- end
- end
-
- $stdout.sync = true
-
- Chef::Log.info("Creating instance with
- service : #{locate_config_value(:cloudstack_service)}
- template : #{locate_config_value(:cloudstack_template)}
- disk : #{locate_config_value(:cloudstack_disk)}
- zone : #{locate_config_value(:cloudstack_zone)}
- project: #{locate_config_value(:cloudstack_project)}
- network: #{locate_config_value(:cloudstack_networks)}")
-
- print "\n#{ui.color("Waiting for Server to be created", :magenta)}"
- params = {}
- params['hypervisor'] = locate_config_value(:cloudstack_hypervisor) if locate_config_value(:cloudstack_hypervisor)
-
- params['keypair'] = locate_config_value :keypair if locate_config_value :keypair
- params['affinitygroupnames'] = locate_config_value :aag if locate_config_value :aag
- params['displayname'] = if locate_config_value :set_display_name and locate_config_value :chef_node_name then locate_config_value :chef_node_name else hostname end
- params['ipaddress'] = locate_config_value(:ik_private_ip) if locate_config_value(:ik_private_ip)
-
- server = connection.create_server(
- hostname,
- locate_config_value(:cloudstack_service),
- locate_config_value(:cloudstack_template),
- locate_config_value(:cloudstack_disk),
- locate_config_value(:cloudstack_zone),
- locate_config_value(:cloudstack_networks),
- params
- )
-
- zone_name = locate_config_value(:cloudstack_zone)
- zone = zone_name ? connection.get_zone(zone_name) : connection.get_default_zone
-
- config[:public_ip] = false if zone['networktype'] == 'Basic'
- public_ip = find_or_create_public_ip(server, connection)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << server['name'].to_s
- object_fields << ui.color("Password:", :cyan) if locate_config_value(:cloudstack_password)
- object_fields << server['password'] if locate_config_value(:cloudstack_password)
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << public_ip
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
-
- return unless config[:bootstrap]
-
- if @bootstrap_protocol == 'ssh'
- print "\n#{ui.color("Waiting for sshd on: #{public_ip}", :magenta)}"
-
- print(".") until is_ssh_open?(public_ip) {
- sleep BOOTSTRAP_DELAY
- puts "\n"
- }
- elsif @bootstrap_protocol == 'winrm'
- print "\n#{ui.color("Waiting for winrm to be active on: #{public_ip}", :magenta)}"
- print(".") until tcp_test_winrm(public_ip,locate_config_value(:winrm_port)) {
- sleep WINRM_BOOTSTRAP_DELAY
- puts("\n")
- }
- else
- puts "Cannot determine the bootstrap protocol."
- puts "Please specify either ssh or winrm as bootstrap protocol."
- exit 1
- end
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << server['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << public_ip
- object_fields << ui.color("Environment:", :cyan)
- object_fields << (config[:environment] || '_default')
- object_fields << ui.color("Run List:", :cyan)
- object_fields << config[:run_list].join(', ')
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
-
- bootstrap(server, public_ip).run
- end
-
- def fetch_server_fqdn(ip_addr)
- require 'resolv'
- Resolv.getname(ip_addr)
- end
-
- def is_image_windows?
- template_name = locate_config_value(:cloudstack_template)
- template = connection.get_template(template_name, locate_config_value(:cloudstack_zone))
- template = connection.get_iso(template_name, locate_config_value(:cloudstack_zone)) unless template
- if !template
- ui.error("Template: #{template_name} does not exist!")
- exit 1
- end
- return template['ostypename'].scan('Windows').length > 0
- end
-
- def validate_options
- unless locate_config_value :cloudstack_template
- ui.error "Cloudstack template not specified"
- exit 1
- end
- @windows_image = is_image_windows?
- @windows_platform = is_platform_windows?
-
- unless locate_config_value :cloudstack_service
- ui.error "Cloudstack service offering not specified"
- exit 1
- end
- if config[:bootstrap]
- if locate_config_value(:bootstrap_protocol) == 'ssh'
- identity_file = locate_config_value :identity_file
- ssh_user = locate_config_value :ssh_user
- ssh_password = locate_config_value :ssh_password
- unless identity_file || (ssh_user && ssh_password) || locate_config_value(:cloudstack_password)
- ui.error("You must specify either an ssh identity file or an ssh user and password")
- exit 1
- end
- @bootstrap_protocol = 'ssh'
- elsif locate_config_value(:bootstrap_protocol) == 'winrm'
- if not @windows_image
- ui.error("Only Windows Images support WinRM protocol for bootstrapping.")
- exit 1
- end
- winrm_user = locate_config_value :winrm_user
- winrm_password = locate_config_value :winrm_password
- winrm_transport = locate_config_value :winrm_transport
- winrm_port = locate_config_value :winrm_port
- unless (winrm_user && winrm_transport && winrm_port) && (locate_config_value(:cloudstack_password) || winrm_password)
- ui.error("WinRM User, Password, Transport and Port are compulsory parameters")
- exit 1
- end
- @bootstrap_protocol = 'winrm'
- end
- end
- end
-
- def find_or_create_public_ip(server, connection)
- nic = connection.get_server_default_nic(server) || {}
- if (config[:public_ip] == false)
- nic['ipaddress']
- else
- puts("\nAllocate ip address, create forwarding rules")
- ip_address = connection.associate_ip_address(server['zoneid'], locate_config_value(:cloudstack_networks))
- puts("\nAllocated IP Address: #{ip_address['ipaddress']}")
- Chef::Log.debug("IP Address Info: #{ip_address}")
-
- if locate_config_value :static_nat
- Chef::Log.debug("Enabling static NAT for IP Address : #{ip_address['ipaddress']}")
- connection.enable_static_nat(ip_address['id'], server['id'])
- end
- create_port_forwarding_rules(ip_address, server['id'], connection)
- create_ip_forwarding_rules(ip_address, connection)
- create_firewall_rules(ip_address, connection)
- ip_address['ipaddress']
- end
- end
-
- def create_port_forwarding_rules(ip_address, server_id, connection)
- Chef::Log.debug("Creating IP Forwarding Rule")
- rules = locate_config_value(:port_rules) || []
- if config[:bootstrap]
- if @bootstrap_protocol == 'ssh'
- rules += ["#{locate_config_value(:ssh_port)}"] #SSH Port
- elsif @bootstrap_protocol == 'winrm'
- rules +=[locate_config_value(:winrm_port)]
- else
- puts("\nUnsupported bootstrap protocol : #{@bootstrap_protocol}")
- exit 1
- end
- end
- return if rules.empty?
- rules.each do |rule|
- args = rule.split(':')
- public_port = args[0]
- private_port = args[1] || args[0]
- protocol = args[2] || "TCP"
- if locate_config_value :static_nat
- Chef::Log.debug("Creating IP Forwarding Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, public port: #{public_port}")
- connection.create_ip_fwd_rule(ip_address['id'], protocol, public_port, public_port)
- else
- Chef::Log.debug("Creating Port Forwarding Rule for #{ip_address['id']} with protocol: #{protocol},
- public port: #{public_port} and private port: #{private_port} and server: #{server_id}")
- connection.create_port_forwarding_rule(ip_address['id'], private_port, protocol, public_port, server_id)
- end
- end
- end
-
- def create_ip_forwarding_rules(ip_address, connection)
- Chef::Log.debug("Creating IP Forwarding Rule")
- rules = locate_config_value(:ipfwd_rules)
- return unless rules
- rules.each do |rule|
- args = rule.split(':')
- startport = args[0]
- endport = args[1] || args[0]
- protocol = args[2] || "TCP"
- if locate_config_value :static_nat
- Chef::Log.debug("Creating IP Forwarding Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, startport: #{startport}, endport: #{endport}")
- connection.create_ip_fwd_rule(ip_address['id'], protocol, startport, endport)
- end
- end
- end
-
- def create_firewall_rules(ip_address, connection)
- Chef::Log.debug("Creating Firewall Rule")
- rules = locate_config_value(:fw_rules)
- return unless rules
- icmptype={
- '0' => {'code' => [0]},
- '8' => {'code' => [0]},
- '3' => {'code' => [0, 1]}
- }
- rules.each do |rule|
- args = rule.split(':')
- protocol = args[0]
- cidr_list = (args[1].nil? || args[1].length == 0) ? "0.0.0.0/0" : args[1]
- startport = args[2]
- endport = args[3] || args[2]
- if protocol == "ICMP"
- icmptype.each do |type, value|
- value['code'].each do |code_id|
- Chef::Log.debug("Creating Firewall Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, icmptype: #{type}, icmpcode: #{code_id}, cidrList: #{cidr_list}")
- connection.create_firewall_rule(ip_address['id'], protocol, type, code_id, cidr_list)
- end
- end
- else
- Chef::Log.debug("Creating Firewall Rule for
- #{ip_address['ipaddress']} with protocol: #{protocol}, startport: #{startport}, endport: #{endport}, cidrList: #{cidr_list}")
- connection.create_firewall_rule(ip_address['id'], protocol, startport, endport, cidr_list)
- end
- end
- end
-
- def tcp_test_winrm(hostname, port)
- TCPSocket.new(hostname, port)
- return true
- rescue SocketError
- sleep 2
- false
- rescue Errno::ETIMEDOUT
- false
- rescue Errno::EPERM
- false
- rescue Errno::ECONNREFUSED
- sleep 2
- false
- rescue Errno::EHOSTUNREACH
- sleep 2
- false
- rescue Errno::ENETUNREACH
- sleep 2
- false
- end
-
- #noinspection RubyArgCount,RubyResolve
- def is_ssh_open?(ip)
- s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
- sa = Socket.sockaddr_in(locate_config_value(:ssh_port), ip)
-
- begin
- s.connect_nonblock(sa)
- rescue Errno::EINPROGRESS
- resp = IO.select(nil, [s], nil, 1)
- if resp.nil?
- sleep SSH_POLL_INTERVAL
- return false
- end
-
- begin
- s.connect_nonblock(sa)
- rescue Errno::EISCONN
- Chef::Log.debug("sshd accepting connections on #{ip}")
- yield
- return true
- rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
- sleep SSH_POLL_INTERVAL
- return false
- end
- ensure
- s && s.close
- end
- end
-
- def is_platform_windows?
- return RUBY_PLATFORM.scan('w32').size > 0
- end
-
- def bootstrap(server, public_ip)
- if @windows_image
- Chef::Log.debug("Windows Bootstrapping")
- bootstrap_for_windows_node(server, public_ip)
- else
- Chef::Log.debug("Linux Bootstrapping")
- bootstrap_for_node(server, public_ip)
- end
- end
-
- def bootstrap_for_windows_node(server, fqdn)
- if locate_config_value(:bootstrap_protocol) == 'winrm'
- bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
- if locate_config_value(:kerberos_realm)
- #Fetch AD/WINS based fqdn if any for Kerberos-based Auth
- private_ip_address = connection.get_server_default_nic(server)["ipaddress"]
- fqdn = locate_config_value(:fqdn) || fetch_server_fqdn(private_ip_address)
- end
- bootstrap.name_args = [fqdn]
- bootstrap.config[:winrm_user] = locate_config_value(:winrm_user) || 'Administrator'
- locate_config_value(:cloudstack_password) ? bootstrap.config[:winrm_password] = server['password'] : bootstrap.config[:winrm_password] = locate_config_value(:winrm_password)
- bootstrap.config[:winrm_transport] = locate_config_value(:winrm_transport)
- bootstrap.config[:winrm_port] = locate_config_value(:winrm_port)
- elsif locate_config_value(:bootstrap_protocol) == 'ssh'
- bootstrap = Chef::Knife::BootstrapWindowsSsh.new
- if locate_config_value(:cloudstack_password)
- bootstrap.config[:ssh_user] = locate_config_value(:ssh_user) || 'Administrator'
- else
- bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
- end
- locate_config_value(:cloudstack_password) ? bootstrap.config[:ssh_password] = server['password'] : bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
- bootstrap.config[:ssh_port] = locate_config_value(:ssh_port)
- bootstrap.config[:identity_file] = locate_config_value(:identity_file)
- bootstrap.config[:no_host_key_verify] = locate_config_value(:no_host_key_verify)
- else
- ui.error("Unsupported Bootstrapping Protocol. Supported : winrm, ssh")
- exit 1
- end
- bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server["name"]
- bootstrap.config[:encrypted_data_bag_secret] = locate_config_value(:secret)
- bootstrap.config[:encrypted_data_bag_secret_file] = locate_config_value(:secret_file)
- bootstrap_common_params(bootstrap)
- end
-
- def bootstrap_common_params(bootstrap)
- bootstrap.config[:run_list] = config[:run_list]
- bootstrap.config[:prerelease] = config[:prerelease]
- bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
- bootstrap.config[:distro] = locate_config_value(:distro)
- bootstrap.config[:template_file] = locate_config_value(:template_file)
- bootstrap.config[:first_boot_attributes] = locate_config_value(:first_boot_attributes)
- bootstrap.config[:environment] = locate_config_value(:environment)
- bootstrap
- end
-
- def bootstrap_for_node(server,fqdn)
- bootstrap = Chef::Knife::Bootstrap.new
- bootstrap.name_args = [fqdn]
- if locate_config_value(:cloudstack_password)
- bootstrap.config[:ssh_user] = locate_config_value(:ssh_user) || 'root'
- else
- bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
- end
- locate_config_value(:cloudstack_password) ? bootstrap.config[:ssh_password] = server['password'] : bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
- bootstrap.config[:ssh_port] = locate_config_value(:ssh_port) || 22
- bootstrap.config[:identity_file] = locate_config_value(:identity_file)
- bootstrap.config[:secret_file] = locate_config_value(:secret_file)
- bootstrap.config[:secret] = locate_config_value(:secret)
- bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server["name"]
- bootstrap.config[:use_sudo] = true unless locate_config_value(:ssh_user) == 'root'
-
- # may be needed for vpc_mode
- bootstrap.config[:host_key_verify] = config[:host_key_verify]
- bootstrap_common_params(bootstrap)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_server_delete.rb b/lib/chef/knife/cs_server_delete.rb
deleted file mode 100644
index 777ee65..0000000
--- a/lib/chef/knife/cs_server_delete.rb
+++ /dev/null
@@ -1,146 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsServerDelete < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- require 'chef/api_client'
- require 'chef/knife'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server delete SERVER_NAME [SERVER_NAME ...] (options)"
-
- def run
- validate_base_options
-
- @name_args.each do |hostname|
- server = connection.get_server(hostname)
-
- if !server then
- ui.error("Server '#{hostname}' not found")
- next
- end
-
- if server['state'] == 'Destroyed' then
- ui.warn("Server '#{hostname}' already destroyed")
- next
- end
-
- rules = connection.list_port_forwarding_rules
-
- show_object_details(server, connection, rules)
-
- result = confirm_action("Do you really want to delete this server")
- if result
- print "#{ui.color("Waiting for deletion", :magenta)}"
- disassociate_virtual_ip_address server
- connection.delete_server(hostname, false)
- puts "\n"
- ui.msg("Deleted server #{hostname}")
-
- # delete chef client and node
- node_name = connection.get_server_fqdn server
- delete_chef = confirm_action("Do you want to delete the chef node and client '#{node_name}")
- if delete_chef
- delete_node node_name
- delete_client node_name
- end
-
- end
- end
- end
-
- def show_object_details(s, connection, rules)
- return if locate_config_value(:yes)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << s['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << (connection.get_server_public_ip(s, rules) || '')
- object_fields << ui.color("Service:", :cyan)
- object_fields << s['serviceofferingname'].to_s
- object_fields << ui.color("Template:", :cyan)
- object_fields << s['templatename']
- object_fields << ui.color("Domain:", :cyan)
- object_fields << s['domain']
- object_fields << ui.color("Zone:", :cyan)
- object_fields << s['zonename']
- object_fields << ui.color("State:", :cyan)
- object_fields << s['state']
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
- end
-
- def confirm_action(question)
- return true if locate_config_value(:yes)
- result = ui.ask_question(question, :default => "Y" )
- if result == "Y" || result == "y" then
- return true
- else
- return false
- end
- end
-
- def disassociate_virtual_ip_address(server)
- ip_addr = connection.get_server_public_ip(server)
- return unless ip_addr
- ip_addr_info = connection.get_public_ip_address(ip_addr)
- #Check if Public IP has been allocated and is not Source NAT
- if ip_addr_info
- if not ip_addr_info['issourcenat']
- connection.disassociate_ip_address(ip_addr_info['id'])
- end
- end
- end
-
- def delete_client(name)
- begin
- client = Chef::ApiClient.load(name)
- rescue Net::HTTPServerException
- return
- end
-
- client.destroy
- ui.msg "Deleted client #{name}"
- end
-
- def delete_node(name)
- begin
- node = Chef::Node.load(name)
- rescue Net::HTTPServerException
- return
- end
-
- node.destroy
- ui.msg "Deleted node #{name}"
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_server_list.rb b/lib/chef/knife/cs_server_list.rb
index 3fff29e..74aed54 100644
--- a/lib/chef/knife/cs_server_list.rb
+++ b/lib/chef/knife/cs_server_list.rb
@@ -1,8 +1,6 @@
#
-# Author:: Ryan Holmes ()
# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
+# Copyright:: Copyright (c) 2014
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,150 +16,137 @@
# limitations under the License.
#
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsServerList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs server list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all the accounts",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify hostname to list"
-
- option :keyword,
- :long => "--keyword NAME",
- :description => "Specify part of instancename to list"
-
- option :action,
- :short => "-a ACTION",
- :long => "--action ACTION",
- :description => "start, stop or destroy the instances in your result"
-
- option :expunge,
- :long => "--expunge",
- :description => "If used with --action destroy, will cause the server to be expunged"
- option :public_ip,
- :long => "--[no-]public-ip",
- :description => "Show or don't show the public IP for server in your result",
- :boolean => true,
- :default => true
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Public IP :ipaddress',
- 'Service :serviceofferingname',
- 'Template :templatename',
- 'State :state',
- 'Instance :instancename',
- 'Hypervisor :hostname'
- ]
-
- params = { 'command' => "listVirtualMachines" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
- params['expunge'] = locate_config_value(:expunge) if locate_config_value(:expunge)
- params['expunge'] = false if params['expunge'].nil?
-
- ##
- # Get the public IP address if possible, except when the option --no-public-ip is given.
-
- rules = connection.list_port_forwarding_rules(nil, true)
- public_list = connection.list_public_ip_addresses(true)
- result = connection.list_object(params, "virtualmachine")
- result.each do |n|
- public_ip = connection.get_server_public_ip(n, rules, public_list) if locate_config_value(:public_ip)
- private_ip = (n['nic'].select { |k| k['isdefault'] }).first
- public_ip ? n['ipaddress'] = public_ip : n['ipaddress'] = private_ip['ipaddress'] || "N/A"
+require 'chef/knife/cs_base'
+
+class Chef
+ class Knife
+ class CsServerList < Knife
+
+ include Chef::Knife::CsBase
+
+ banner "knife cs server list (options)"
+
+ option :id,
+ :short => "-i",
+ :long => "--id",
+ :boolean => true,
+ :default => false,
+ :description => "Display the ID's instead of the names in output"
+
+ option :tags,
+ :short => "-t TAG1,TAG2",
+ :long => "--tags TAG1,TAG2",
+ :description => "List of tags to output"
+
+ def fcolor(flavor)
+ case flavor
+ when /.*micro.*/i
+ fcolor = :blue
+ when /.*small.*/i
+ fcolor = :magenta
+ when /.*medium.*/i
+ fcolor = :cyan
+ when /.*large.*/i
+ fcolor = :green
+ when /.*xlarge.*/i
+ fcolor = :red
+ end
+ end
+
+ def azcolor(az)
+ case az
+ when /a$/
+ color = :blue
+ when /b$/
+ color = :green
+ when /c$/
+ color = :red
+ when /d$/
+ color = :magenta
+ else
+ color = :cyan
+ end
end
- list_object(columns, result)
-
- ##
- # Executing actions against the list results that are returned.
-
- if locate_config_value(:action)
- result.each do |r|
- hostname = r['name']
- case locate_config_value(:action).downcase
- when "start" then
- show_object_details(r, connection, rules)
- result = confirm_action("Do you really want to start this server ")
- if result then
- print "#{ui.color("Waiting for startup", :magenta)}"
- connection.start_server(hostname)
- puts "\n"
- ui.msg("Started server #{hostname}")
- end
- when "stop" then
- show_object_details(r, connection, rules)
- result = confirm_action("Do you really want to stop this server ")
- if result then
- print "#{ui.color("Waiting for shutdown", :magenta)}"
- connection.stop_server(hostname)
- puts "\n"
- ui.msg("Shutdown server #{hostname}")
- end
- when "destroy" then
- show_object_details(r, connection, rules)
- result = confirm_action("Do you really want to destroy this server ")
- if result then
- print "#{ui.color("Waiting for demolition", :magenta)}"
- connection.delete_server(hostname, params['expunge'])
- puts "\n"
- ui.msg("Destroyed server #{hostname}")
+ def groups_with_ids(groups)
+ groups.map{|g|
+ "#{g} (#{@group_id_hash[g]})"
+ }
+ end
+
+ def vpc_with_name(vpc_id)
+ this_vpc = @vpcs.select{|v| v.id == vpc_id }.first
+ if this_vpc.tags["Name"]
+ vpc_name = this_vpc.tags["Name"]
+ "#{vpc_name} (#{vpc_id})"
+ else
+ vpc_id
+ end
+ end
+
+ def private_ip_address(server)
+ return nil if server.nics.empty?
+ default_nic = server.nics.select {|n| n['isdefault'] == true }.first
+ return nil if default_nic.nil? || default_nic.empty?
+ default_nic['ipaddress']
+ end
+
+
+ def run
+ $stdout.sync = true
+
+ validate!
+
+ server_list = [
+
+ if config[:id]
+ ui.color('ID', :bold)
+ else
+ ui.color('Name', :bold)
+ end,
+
+ ui.color('Public IP', :bold),
+ ui.color('Private IP', :bold),
+
+ ui.color('Service', :bold),
+ ui.color('Image', :bold),
+ ui.color('Zone', :bold),
+ ui.color('State', :bold)
+
+ ].flatten.compact
+
+ output_column_count = server_list.length
+
+ connection.servers.all.each do |server|
+
+ config[:id] ? server_list << server.id.to_s : server_list << server.name.to_s
+
+ # Still need to fix the public IP's (need to call the API for all forwards and filter on ssh/winrm sessions or something)
+ server_list << "pub_ip" # public_ip_address(server).to_s || "unknown"
+ server_list << private_ip_address(server).to_s || "unknown"
+
+ config[:id] ? server_list << server.flavor_id.to_s : server_list << server.flavor_name.to_s
+ config[:id] ? server_list << server.image_id.to_s : server_list << server.image_name.to_s
+ config[:id] ? server_list << server.zone_id.to_s : server_list << server.zone_name.to_s
+
+ server_list << begin
+ state = server.state.to_s.downcase
+ case state
+ when 'destroyed', 'expunging'
+ ui.color(state, :purple)
+ when 'shutting-down','terminated','stopping','stopped'
+ ui.color(state, :red)
+ when 'pending'
+ ui.color(state, :yellow)
+ else
+ ui.color(state, :green)
end
end
end
- end
- end
-
- def show_object_details(s, connection, rules)
- return if locate_config_value(:yes)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << s['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << (connection.get_server_public_ip(s, rules) || '')
- object_fields << ui.color("Service:", :cyan)
- object_fields << s['serviceofferingname'].to_s
- object_fields << ui.color("Template:", :cyan)
- object_fields << s['templatename']
- object_fields << ui.color("Domain:", :cyan)
- object_fields << s['domain']
- object_fields << ui.color("Zone:", :cyan)
- object_fields << s['zonename']
- object_fields << ui.color("State:", :cyan)
- object_fields << s['state']
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
- end
- def confirm_action(question)
- return true if locate_config_value(:yes)
- result = ui.ask_question(question, :default => "Y" )
- if result == "Y" || result == "y" then
- return true
- else
- return false
+ puts ui.list(server_list, :uneven_columns_across, output_column_count)
+
end
end
-
end
-end
+end
\ No newline at end of file
diff --git a/lib/chef/knife/cs_server_reboot.rb b/lib/chef/knife/cs_server_reboot.rb
deleted file mode 100644
index ba5bddb..0000000
--- a/lib/chef/knife/cs_server_reboot.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: KC Braunschweig ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsServerReboot < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- require 'chef/api_client'
- require 'chef/knife'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server reboot SERVER_NAME [SERVER_NAME ...] (options)"
-
- def run
- validate_base_options
-
- @name_args.each do |hostname|
- server = connection.get_server(hostname)
-
- if !server then
- ui.error("Server '#{hostname}' not found")
- next
- end
-
- rules = connection.list_port_forwarding_rules
-
- show_object_details(server, connection, rules)
-
- result = confirm_action("Do you really want to reboot this server")
-
- if result
- print "#{ui.color("Rebooting", :magenta)}"
- connection.reboot_server(hostname)
- puts "\n"
- ui.msg("Rebooted server #{hostname}")
- end
- end
- end
-
- def show_object_details(s, connection, rules)
- return if locate_config_value(:yes)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << s['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << (connection.get_server_public_ip(s, rules) || '')
- object_fields << ui.color("Service:", :cyan)
- object_fields << s['serviceofferingname'].to_s
- object_fields << ui.color("Template:", :cyan)
- object_fields << s['templatename']
- object_fields << ui.color("Domain:", :cyan)
- object_fields << s['domain']
- object_fields << ui.color("Zone:", :cyan)
- object_fields << s['zonename']
- object_fields << ui.color("State:", :cyan)
- object_fields << s['state']
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
- end
-
- def confirm_action(question)
- return true if locate_config_value(:yes)
- result = ui.ask_question(question, :default => "Y" )
- if result == "Y" || result == "y" then
- return true
- else
- return false
- end
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_server_remove_nic.rb b/lib/chef/knife/cs_server_remove_nic.rb
deleted file mode 100644
index efa1ea6..0000000
--- a/lib/chef/knife/cs_server_remove_nic.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-#
-# Author:: John E. Vincent ()
-# Copyright:: Copyright (c) 2013 John E. Vincent
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require 'chef/knife/cs_base'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsServerRemoveNic < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
- include Chef::Knife::KnifeCloudstackBaseList
-
- deps do
- require 'knife-cloudstack/connection'
- require 'chef/knife'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server remove nic SERVERID NICID"
-
-
- def run
- validate_base_options
-
- @server_id, @nic_id = name_args
-
- if @server_id.nil? || @nic_id.nil?
- show_usage
- ui.fatal("You must provide both a nic id and a server id")
- exit(1)
- end
-
-
- object_list = []
- if locate_config_value(:fields)
- locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) }
- else
- object_list << ui.color('Server', :bold)
- object_list << ui.color('Network', :bold)
- object_list << ui.color('Type', :bold)
- object_list << ui.color('Default', :bold)
- object_list << ui.color('Address', :bold)
- object_list << ui.color('Gateway', :bold)
- object_list << ui.color('Netmask', :bold)
- object_list << ui.color('ID', :bold)
- end
-
- columns = object_list.count
-
- connection_result = connection.remove_nic_from_vm(
- @nic_id,
- @server_id
- )
-
- output_format(connection_result)
-
- object_list << connection_result['name']
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- object_list << ''
- if connection_result['nic']
- connection_result['nic'].each do |r|
- if locate_config_value(:fields)
- locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') }
- else
- object_list << ''
- object_list << r['networkname'].to_s
- object_list << r['type'].to_s
- object_list << (r['isdefault'] ? r['isdefault'].to_s : 'false')
- object_list << (r['ipaddress'] || '')
- object_list << (r['gateway'] || '')
- object_list << (r['netmask'] || '')
- object_list << (r['networkid'] || '')
- end
- end
- puts ui.list(object_list, :uneven_columns_across, columns)
- list_object_fields(connection_result) if locate_config_value(:fieldlist)
- else
- ui.error("No nics returned in response")
- end
- end
- end
-end
diff --git a/lib/chef/knife/cs_server_start.rb b/lib/chef/knife/cs_server_start.rb
deleted file mode 100644
index ea3277a..0000000
--- a/lib/chef/knife/cs_server_start.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: KC Braunschweig ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsServerStart < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'chef/knife'
- require 'knife-cloudstack/connection'
- require 'chef/api_client'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server start SERVER_NAME [SERVER_NAME ...] (options)"
-
- def run
- validate_base_options
-
- @name_args.each do |hostname|
- server = connection.get_server(hostname)
-
- if !server then
- ui.error("Server '#{hostname}' not found")
- next
- end
-
- rules = connection.list_port_forwarding_rules
-
- show_object_details(server, connection, rules)
-
- result = confirm_action("Do you really want to start this server")
- if result
- print "#{ui.color("Waiting for startup", :magenta)}"
- connection.start_server(hostname)
- puts "\n"
- ui.msg("Started server #{hostname}")
- end
- end
-
- end
-
- def show_object_details(s, connection, rules)
- return if locate_config_value(:yes)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << s['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << (connection.get_server_public_ip(s, rules) || '')
- object_fields << ui.color("Service:", :cyan)
- object_fields << s['serviceofferingname'].to_s
- object_fields << ui.color("Template:", :cyan)
- object_fields << s['templatename']
- object_fields << ui.color("Domain:", :cyan)
- object_fields << s['domain']
- object_fields << ui.color("Zone:", :cyan)
- object_fields << s['zonename']
- object_fields << ui.color("State:", :cyan)
- object_fields << s['state']
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
- end
-
- def confirm_action(question)
- return true if locate_config_value(:yes)
- result = ui.ask_question(question, :default => "Y" )
- if result == "Y" || result == "y" then
- return true
- else
- return false
- end
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_server_stop.rb b/lib/chef/knife/cs_server_stop.rb
deleted file mode 100644
index 609cef0..0000000
--- a/lib/chef/knife/cs_server_stop.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: KC Braunschweig ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsServerStop < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- require 'chef/api_client'
- require 'chef/knife'
- Chef::Knife.load_deps
- end
-
- banner "knife cs server stop SERVER_NAME [SERVER_NAME ...] (options)"
-
- option :cloudstack_force_stop,
- :long => "--force",
- :description => "Force stop the VM. The caller knows the VM is stopped.",
- :boolean => true
-
- def run
- validate_base_options
-
- @name_args.each do |hostname|
- server = connection.get_server(hostname)
-
- if !server then
- ui.error("Server '#{hostname}' not found")
- next
- end
-
- rules = connection.list_port_forwarding_rules
-
- show_object_details(server, connection, rules)
-
- if config[:cloudstack_force_stop]
- result = confirm_action("Do you really want to force stop this server")
- if result
- print "#{ui.color("Forcefully stopping", :magenta)}"
- connection.stop_server(hostname,config[:cloudstack_force_stop])
- puts "\n"
- ui.msg("Stopped server #{hostname}")
- end
- else
- result = confirm_action("Do you really want to stop this server")
- if result
- print "#{ui.color("Stopping", :magenta)}"
- connection.stop_server(hostname)
- puts "\n"
- ui.msg("Stopped server #{hostname}")
- end
- end
- end
- end
-
- def show_object_details(s, connection, rules)
- return if locate_config_value(:yes)
-
- object_fields = []
- object_fields << ui.color("Name:", :cyan)
- object_fields << s['name'].to_s
- object_fields << ui.color("Public IP:", :cyan)
- object_fields << (connection.get_server_public_ip(s, rules) || '')
- object_fields << ui.color("Service:", :cyan)
- object_fields << s['serviceofferingname'].to_s
- object_fields << ui.color("Template:", :cyan)
- object_fields << s['templatename']
- object_fields << ui.color("Domain:", :cyan)
- object_fields << s['domain']
- object_fields << ui.color("Zone:", :cyan)
- object_fields << s['zonename']
- object_fields << ui.color("State:", :cyan)
- object_fields << s['state']
-
- puts "\n"
- puts ui.list(object_fields, :uneven_columns_across, 2)
- puts "\n"
- end
-
- def confirm_action(question)
- return true if locate_config_value(:yes)
- result = ui.ask_question(question, :default => "Y" )
- if result == "Y" || result == "y" then
- return true
- else
- return false
- end
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_service_list.rb b/lib/chef/knife/cs_service_list.rb
deleted file mode 100644
index f0dc393..0000000
--- a/lib/chef/knife/cs_service_list.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsServiceList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs service list (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Specify servicename to list"
-
- option :keyword,
- :long => "--keyword NAME",
- :description => "Specify part of servicename to list"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Memory :memory',
- 'CPUs :cpunumber',
- 'CPU Speed :cpuspeed',
- 'Created :created'
- ]
-
- params = { 'command' => "listServiceOfferings" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "serviceoffering")
-
- result.each do |r|
- r['memory'] = human_memory(r['memory']) if r['memory']
- end
-
- list_object(columns, result)
- end
-
- def human_memory n
- count = 0
- while n >= 1024 and count < 2
- n /= 1024.0
- count += 1
- end
- format("%.0f", n) + %w(MB GB TB)[count]
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_stack_create.rb b/lib/chef/knife/cs_stack_create.rb
deleted file mode 100644
index 08f0dd1..0000000
--- a/lib/chef/knife/cs_stack_create.rb
+++ /dev/null
@@ -1,310 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsStackCreate < Chef::Knife
-
- attr_accessor :current_stack
-
- include Chef::Knife::KnifeCloudstackBase
- include Chef::Knife::KnifeCloudstackBaseList
-
- deps do
- require 'chef/json_compat'
- require 'chef/mash'
- require 'chef/search/query'
- require 'chef/knife/node_run_list_remove'
- require 'net/ssh'
- require 'net/ssh/multi'
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- Chef::Knife::Ssh.load_deps
- Chef::Knife::NodeRunListRemove.load_deps
- KnifeCloudstack::CsServerCreate.load_deps
- end
-
- banner "knife cs stack create JSON_FILE (options)"
-
- option :ssh_user,
- :short => "-x USERNAME",
- :long => "--ssh-user USERNAME",
- :description => "The ssh username"
-
- option :ssh_password,
- :short => "-P PASSWORD",
- :long => "--ssh-password PASSWORD",
- :description => "The ssh password"
-
- option :identity_file,
- :short => "-i IDENTITY_FILE",
- :long => "--identity-file IDENTITY_FILE",
- :description => "The SSH identity file used for authentication"
-
- def run
- validate_base_options
- if @name_args.first.nil?
- ui.error "Please specify json file eg: knife cs stack create JSON_FILE"
- exit 1
- end
- file_path = File.expand_path(@name_args.first)
- unless File.exist?(file_path) then
- ui.error "Stack file '#{file_path}' not found. Please check the path."
- exit 1
- end
-
- data = File.read file_path
- stack = Chef::JSONCompat.from_json data
- create_stack stack
- end
-
- def create_stack(stack)
- @current_stack = Mash.new(stack)
- current_stack[:servers].each do |server|
- if server[:name]
- # create server(s)
- names = server[:name].split(/[\s,]+/)
- names.each do |n|
- s = Mash.new(server)
- s[:name] = n
- create_server(s)
- end
-
- end
-
- # execute actions
- run_actions server[:actions]
- end
-
- print_local_hosts
- end
-
- def create_server(server)
-
- cmd = KnifeCloudstack::CsServerCreate.new([server[:name]])
- # configure and run command
- # TODO: validate parameters
- cmd.config[:cloudstack_url] = config[:cloudstack_url]
- cmd.config[:cloudstack_api_key] = config[:cloudstack_api_key]
- cmd.config[:cloudstack_secret_key] = config[:cloudstack_secret_key]
- cmd.config[:cloudstack_proxy] = config[:cloudstack_proxy]
- cmd.config[:cloudstack_no_ssl_verify] = config[:cloudstack_no_ssl_verify]
- cmd.config[:cloudstack_project] = config[:cloudstack_project]
- cmd.config[:ssh_user] = config[:ssh_user]
- cmd.config[:ssh_password] = config[:ssh_password]
- cmd.config[:ssh_port] = config[:ssh_port] || "22" # Chef::Config[:knife][:ssh_port]
- cmd.config[:identity_file] = config[:identity_file]
- cmd.config[:keypair] = server[:keypair]
- cmd.config[:cloudstack_template] = server[:template] if server[:template]
- cmd.config[:cloudstack_service] = server[:service] if server[:service]
- cmd.config[:cloudstack_zone] = server[:zone] if server[:zone]
- server.has_key?(:public_ip) ? cmd.config[:public_ip] = server[:public_ip] : cmd.config[:no_public_ip] = true
- cmd.config[:ik_private_ip] = server[:private_ip] if server[:private_ip]
- cmd.config[:bootstrap] = server[:bootstrap] if server.has_key?(:bootstrap)
- cmd.config[:bootstrap_protocol] = server[:bootstrap_protocol] || "ssh"
- cmd.config[:distro] = server[:distro] || "chef-full"
- cmd.config[:template_file] = server[:template_file] if server.has_key?(:template_file)
- cmd.config[:no_host_key_verify] = server[:no_host_key_verify] if server.has_key?(:no_host_key_verify)
- cmd.config[:cloudstack_networks] = server[:networks].split(/[\s,]+/) if server[:networks]
- cmd.config[:run_list] = server[:run_list].split(/[\s,]+/) if server[:run_list]
- cmd.config[:port_rules] = server[:port_rules].split(/[\s,]+/) if server[:port_rules]
- if current_stack[:environment]
- cmd.config[:environment] = current_stack[:environment]
- Chef::Config[:environment] = current_stack[:environment]
- end
-
- cmd.run_with_pretty_exceptions
- end
-
- def run_actions(actions)
- puts "\n"
- ui.msg("Processing actions...")
- sleep 1 # pause for e.g. chef solr indexing
- actions ||= []
- actions.each do |cmd|
- cmd ||= {}
- cmd.each do |name, args|
- case name
- when 'knife_ssh'
- knife_ssh_action(*args)
- when 'http_request'
- http_request(args)
- when 'run_list_remove'
- run_list_remove(*args)
- when 'sleep'
- dur = args || 5
- sleep dur
- end
- end
- end
-
- end
-
- def search_nodes(query, attribute=nil)
- if get_environment
- query = "(#{query})" + " AND chef_environment:#{get_environment}"
- end
-
- Chef::Log.debug("Searching for nodes: #{query}")
-
- q = Chef::Search::Query.new
- nodes = Array(q.search(:node, query))
-
- # the array of nodes is the first item in the array returned by the search
- if nodes.length > 1
- nodes = nodes.first || []
- end
-
- # return attribute values instead of nodes
- if attribute
- nodes.map do |node|
- node[attribute.to_s]
- end
- else
- nodes
- end
- end
-
- def knife_ssh(host_list, command)
-
- ssh = Chef::Knife::Ssh.new
- ssh.name_args = [host_list, command]
- ssh.config[:ssh_user] = config[:ssh_user]
- ssh.config[:ssh_password] = config[:ssh_password]
- ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
- ssh.config[:identity_file] = config[:identity_file]
- ssh.config[:manual] = true
- ssh.config[:no_host_key_verify] = config[:no_host_key_verify]
- ssh
- end
-
- def knife_ssh_with_password_auth(host_list, command)
- ssh = knife_ssh(host_list, command)
- ssh.config[:identity_file] = nil
- ssh.config[:ssh_password] = ssh.get_password
- ssh
- end
-
- def knife_ssh_action(query, command)
-
- public_ips = find_public_ips(query)
- return if public_ips.nil? || public_ips.empty?
- host_list = public_ips.join(' ')
-
- ssh = knife_ssh(host_list, command)
- begin
- ssh.run
- rescue Net::SSH::AuthenticationFailed
- unless config[:ssh_password]
- puts "Failed to authenticate #{config[:ssh_user]} - trying password auth"
- ssh = knife_ssh_with_password_auth(host_list, command)
- ssh.run
- end
- end
-
- end
-
- def http_request(url)
- match_data = /\$\{([a-zA-Z0-9-]+)\}/.match url
- if match_data
- server_name = match_data[1]
- ip = public_ip_for_host(server_name)
- url = url.sub(/\$\{#{server_name}\}/, ip)
- end
-
-
- puts "HTTP Request: #{url}"
- puts `curl -s -m 5 #{url}`
- end
-
- def run_list_remove(query, entry)
- nodes = search_nodes(query)
- return unless nodes
-
- nodes.each do |n|
- cmd = Chef::Knife::NodeRunListRemove.new([n.name, entry])
- cmd.run_with_pretty_exceptions
- end
- end
-
- def find_public_ips(query)
- hostnames = search_nodes(query, 'hostname')
- puts "Found hostnames: #{hostnames.inspect}"
- ips = hostnames.map { |h|
- public_ip_for_host h
- }
- ips.compact.uniq
- end
-
- def public_ip_for_host(name)
- return nil unless name
- @public_ip_cache ||= {}
-
- if !@public_ip_cache[name] then
- server = connection.get_server(name)
- return nil unless server
-
- ip = connection.get_server_public_ip(server)
- @public_ip_cache[name] = ip if ip
- end
-
- @public_ip_cache[name]
- end
-
- def get_environment
- current_stack[:environment]
- end
-
- def destroy_all(domain, excludes=[])
- servers = connection.list_servers || []
- servers.each do |s|
- excluded = false
- excludes.each { |val|
- if s['name'] =~ /#{val}/ then
- excluded = true
- next
- end
- }
- next if excluded
- nodename = "#{s['name']}.#{domain}"
- system "knife cs server delete #{s['name']} -y"
- system "knife client delete #{nodename} -y"
- system "knife node delete #{nodename} -y"
- end
- end
-
- def print_local_hosts
- hosts = []
- current_stack[:servers].each do |server|
- next unless server[:local_hosts]
- name = server[:name].split(' ').first
- ip = public_ip_for_host(name)
- server[:local_hosts].each { |host|
- hostname = host.sub(/\$\{environment\}/, get_environment)
- hosts << "#{ip} #{hostname}"
- }
- end
- unless hosts.empty?
- puts "\nAdd this to your /etc/hosts file:"
- puts hosts.join("\n")
- end
- end
- end
-end
diff --git a/lib/chef/knife/cs_stack_delete.rb b/lib/chef/knife/cs_stack_delete.rb
deleted file mode 100644
index a1f21e5..0000000
--- a/lib/chef/knife/cs_stack_delete.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsStackDelete < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'chef/json_compat'
- require 'chef/mash'
- require 'knife-cloudstack/connection'
- require 'chef/knife'
- Chef::Knife.load_deps
- KnifeCloudstack::CsServerDelete.load_deps
- end
-
- banner "knife cs stack delete JSON_FILE (options)"
-
- def run
- if @name_args.first.nil?
- ui.error "Please specify json file eg: knife cs stack delete JSON_FILE"
- exit 1
- end
- file_path = File.expand_path(@name_args.first)
- unless File.exist?(file_path) then
- ui.error "Stack file '#{file_path}' not found. Please check the path."
- exit 1
- end
-
- data = File.read file_path
- stack = Chef::JSONCompat.from_json data
- delete_stack stack
-
- end
-
- def delete_stack(stack)
- current_stack = Mash.new(stack)
- current_stack[:servers].each do |server|
- if server[:name]
-
- # delete server(s)
- names = server[:name].split(/[\s,]+/)
- names.each do |name|
- delete_server(name)
- end
-
- end
-
- end
- end
-
- def delete_server(server_name)
- cmd = KnifeCloudstack::CsServerDelete.new([server_name])
- cmd.config[:yes] = true
- cmd.config[:expunge] = true
- cmd.run_with_pretty_exceptions
- end
-
- end
-
-end
diff --git a/lib/chef/knife/cs_template_create.rb b/lib/chef/knife/cs_template_create.rb
deleted file mode 100644
index f66e07a..0000000
--- a/lib/chef/knife/cs_template_create.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Author:: Frank Breedijk ()
-# Copyright:: Copyright (c) 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsTemplateCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs template create NAME (options)"
-
- option :displaytext,
- :short => "-T 'DISPLAY TEXT' ",
- :long => "--displaytext 'DISPLAY TEXT'",
- :description => "The display text of the template",
- :required => true,
- :on => :head
-
- option :name,
- :long => "--name NAME",
- :description => "Specify templatename (without format checking)"
-
- option :ostypeid,
- :long => "--ostypeid ID",
- :description => "Specify OS type ID",
- :required => true,
- :on => :head
-
- option :volumeid,
- :long => "--volumeid=ID",
- :description => "Specify volume ID",
- :required => true,
- :on => :head
-
- option :ispublic,
- :long => "--[no-]public",
- :description => "Make the template public after creation",
- :boolean => true,
- :default => false
-
- option :isfeatured,
- :long => "--[no-]featured",
- :description => "Make the template featured after creation",
- :boolean => true,
- :default => false
-
- option :passwordenabled,
- :long => "--[no-]passwordenabled",
- :description => "Make the template password reset enabled after creation",
- :boolean => true,
- :default => true
-
- option :extractable,
- :logn => "--[no-]extractable",
- :description => "Make the template extractable after creation",
- :boolean => "true",
- :default => false
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate hostname and options")
- if locate_config_value(:name)
- templatename = locate_config_value(:name)
- else
- templatename = @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9_\-#]*$/.match templatename then
- ui.error "Invalid templatename. Please specify a simple name without any spaces"
- exit 1
- end
- end
-
- print "#{ui.color("Creating template: #{templatename}", :magenta)}\n"
-
- params = {
- 'command' => 'createTemplate',
- 'name' => templatename,
- 'displaytext' => locate_config_value(:displaytext),
- 'ostypeid' => locate_config_value(:ostypeid),
- 'volumeid' => locate_config_value(:volumeid),
- }
- params['ispublic'] = locate_config_value(:ispublic) if locate_config_value(:ispublic)
- params['isfeatured'] = locate_config_value(:isfeatured) if locate_config_value(:isfeatured)
- params['passwordenabled'] = locate_config_value(:passwordenabled) if locate_config_value(:passwordenabled)
- params['extractable'] = locate_config_value(:extractable) if locate_config_value(:extractable)
- json = connection.send_request(params)
-
- if ! json then
- ui.error("Unable to create template")
- exit 1
- end
-
- print "Template #{json['id']} is being created in the background\n";
-
- return json['id']
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_template_extract.rb b/lib/chef/knife/cs_template_extract.rb
deleted file mode 100644
index f01cc4a..0000000
--- a/lib/chef/knife/cs_template_extract.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-#
-# Author:: Frank Breedijk ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsTemplateExtract < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs template extract NAME (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Name of template to extract (without format checking)"
-
- option :zone,
- :long => "--zone NAME",
- :description => "Name of the zone to extract the template in"
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate template name")
- if locate_config_value(:name)
- templatename = locate_config_value(:name)
- else
- templatename = @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9_\-# ]*$/.match templatename then
- ui.error "Invalid templatename."
- exit 1
- end
- end
-
- zonename = locate_config_value(:zone)
- if ! zonename
- then
- ui.error "No zone specified"
- exit 1
- end
-
- print "#{ui.color("Extracting template: #{templatename}", :magenta)}\n"
-
- Chef::Log.debug("Getting zone")
-
- zone = connection.get_zone(
- zonename,
- )
- if ! zone then
- ui.error "Zone #{zonename} not found"
- exit 1
- end
-
- Chef::Log.debug("Getting template")
-
- template = connection.get_template(
- templatename,
- )
- if ! template then
- ui.error "Template #{templatename} not found"
- exit 1
- end
-
- Chef::Log.debug("Extracting template")
- params = {
- 'command' => 'extractTemplate',
- 'id' => template["id"],
- 'mode' => "HTTP_DOWNLOAD",
- 'zoneid' => zone["id"]
- }
- json = connection.send_async_request(params)
-
- if json then
- url = json["template"]["url"]
- print "\n#{url}\n"
- else
- ui.error "Template extraction failed.\n"
- exit 1
- end
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_template_list.rb b/lib/chef/knife/cs_template_list.rb
deleted file mode 100644
index a8c436d..0000000
--- a/lib/chef/knife/cs_template_list.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsTemplateList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs template list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all templates",
- :boolean => true
-
- option :index,
- :long => "--index",
- :description => "Add index numbers to the output",
- :boolean => true
-
- option :templatefilter,
- :long => "--templatefilter FILTER",
- :description => "Default: 'featured'. Options: 'self','selfexecutable','sharedexecutable','executable','community'",
- :default => "featured"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Size :size',
- 'Zone :zonename',
- 'Public :ispublic',
- 'Created :created'
- ]
-
- params = { 'command' => "listTemplates" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- if ['all','featured','self','selfexecutable','sharedexecutable','executable','community'].include?(locate_config_value(:templatefilter))
- params['templatefilter'] = locate_config_value(:templatefilter)
- else
- params['templatefilter'] = 'featured'
- end
-
- result = connection.list_object(params, "template")
-
- result.each do |r|
- r['size'] = human_file_size(r['size']) if r['size']
- end
-
- list_object(columns, result)
- end
-
- def human_file_size n
- count = 0
- while n >= 1024 and count < 4
- n /= 1024.0
- count += 1
- end
- format("%.0f", n) + %w(B KB MB GB TB)[count]
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_template_register.rb b/lib/chef/knife/cs_template_register.rb
deleted file mode 100644
index ff21be8..0000000
--- a/lib/chef/knife/cs_template_register.rb
+++ /dev/null
@@ -1,187 +0,0 @@
-#
-# Author:: Frank Breedijk ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsTemplateRegister < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs template register NAME (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "Name of template to register (without format checking)"
-
- option :displaytext,
- :long => "--displaytext DESCRIPTION",
- :description => "Description of the template as shown in CloudStack"
-
- option :format,
- :long => "--format FORMAT",
- :description => "Format of the template file QCOW2, RAW or VHD (default)",
- :default => "VHD"
-
- option :hypervisor,
- :long => "--hypervisor NAME",
- :description => "Target hypervisor for the template (default XEN)",
- :default => "XenServer"
-
- option :ostypeid,
- :long => '--ostypeid OSTYPEID',
- :description => "The ID of the OS Type that best represents the OS of this template"
-
- option :url,
- :long => '--url URL',
- :description => "The URL of where the template is hosted. Including http:// and https://"
-
- option :zone,
- :long => "--zone NAME",
- :description => "Name of the zone to register the template in. Default: All zones",
- :default => -1
-
- option :bits,
- :long => "--bits 32|64",
- :description => "32 or 64 bits support, defaults to 64",
- :default => 64
-
- option :isextractable,
- :long => "--[no-]isextractable",
- :description => "Is the template extractable. Default: NO",
- :boolean => true,
- :default => false
-
- option :isdynamicallyscalable,
- :long => "--isdynamicallyscalable",
- :description => "Is the template dynamically scalable. Default: NO",
- :boolean => true,
- :default => false
-
- option :featured,
- :long => "--[no-]featured",
- :description => "Is the tempalte featured? Default: NO",
- :boolean => true,
- :default => false
-
- option :public,
- :long => "--[no-]public",
- :description => "Is the template public? Default: NO",
- :boolean => true,
- :default => false
-
- option :passwordenabled,
- :long => "--[no-]passwordenabled",
- :description => "Is the password reset feature enabled, Default: YES",
- :boolean => true,
- :default => true
-
- option :requireshvm,
- :long => "--[no-]requireshvm",
- :description => "Does the template require HVM? Default: NO",
- :boolean => true,
- :default => false
-
- option :sshkeyenabled,
- :long => "--[no-]sshkeyenabled",
- :description => "Does this tempalte support the sshkey upload feature? Default: NO",
- :boolean => true,
- :default => false
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate template name")
- if locate_config_value(:name)
- templatename = locate_config_value(:name)
- else
- templatename = @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9_\-# ]*$/.match templatename then
- ui.error "Invalid templatename."
- exit 1
- end
- end
-
- unless locate_config_value(:ostypeid) then
- ui.error "No os type id specified"
- exit 1
- end
-
- unless /^http(s)?\:\/\//.match locate_config_value(:url) then
- ui.error "URL (#{locate_config_value(:url)}) is not a well formatted url"
- exit 1
- end
-
- unless (locate_config_value(:bits) == 64 or locate_config_value(:bits) == 32 ) then
- ui.error "Bits must be 32 or 64"
- exit 1
- end
-
- if (locate_config_value(:zone) == -1)
- zoneid = -1
- else
- Chef::Log.debug("Resolving zone #{locate_config_value(:zone)}\n")
-
- zone = connection.get_zone(locate_config_value(:zone))
-
- if ! zone then
- ui.error "Unable to resolve zone #{locate_config_value(:zone)}\n"
- exit 1
- end
- zoneid = zone['id']
- end
-
- print "#{ui.color("Registring template: #{templatename}", :magenta)}\n"
-
- params = {
- 'command' => 'registerTemplate',
- 'name' => templatename,
- 'displaytext' => locate_config_value(:displaytext),
- 'format' => locate_config_value(:format),
- 'hypervisor' => locate_config_value(:hypervisor),
- 'ostypeid' => locate_config_value(:ostypeid),
- 'url' => locate_config_value(:url),
- 'zoneid' => zoneid,
- 'bits' => locate_config_value(:bits),
- }
- params['isdynamicallyscalable'] = locate_config_value(:isdynamicallyscalable) if locate_config_value(:isdynamicallyscalable)
- params['isextractable'] = locate_config_value(:isextractable) if locate_config_value(:isextractable)
- params['ispublic'] = locate_config_value(:public) if locate_config_value(:public)
- params['isfeatured'] = locate_config_value(:featured) if locate_config_value(:featured)
- params['passwordenabled'] = locate_config_value(:passwordenabled) if locate_config_value(:passwordenabled)
- params['sshkeyenabled'] = locate_config_value(:sshkeyenabled) if locate_config_value(:sshkeyenabled)
- params['requireshvm'] = locate_config_value(:requireshvm) if locate_config_value(:requireshvm)
-
- json = connection.send_request(params)
-
- if ! json then
- ui.error "Template #{templatename} not registered\n"
- exit 1
- end
-
- print "TemplateId #{json['template'][0]['id']} is being created\n"
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_user_list.rb b/lib/chef/knife/cs_user_list.rb
deleted file mode 100644
index 48cddd4..0000000
--- a/lib/chef/knife/cs_user_list.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsUserList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs user list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all users",
- :boolean => true
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Account :account',
- 'Type :accounttype',
- 'State :state',
- 'Domain :domain',
- 'Username :username',
- 'First :firstname',
- 'Last :lastname'
- ]
-
- params = { 'command' => "listUsers" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "user")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_volume_create.rb b/lib/chef/knife/cs_volume_create.rb
deleted file mode 100644
index 4d12efc..0000000
--- a/lib/chef/knife/cs_volume_create.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-#
-# Author:: Jeremy Baumont ()
-# Copyright:: Copyright (c) Schuberg Philis 2013
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife/cs_base'
-
-module KnifeCloudstack
- class CsVolumeCreate < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBase
-
- deps do
- require 'knife-cloudstack/connection'
- Chef::Knife.load_deps
- end
-
- banner "knife cs volume create NAME (options)"
-
- option :name,
- :long => "--name NAME",
- :description => "The name of the disk volume.",
- :required => true,
- :on => :head
-
- option :account,
- :long => "--account ACCOUNT_NAME",
- :description => "The account associated with the disk volume. Must be used with the domainId parameter."
-
- option :diskofferingid,
- :long => "--diskofferingid ID",
- :description => "The ID of the disk offering. Either diskOfferingId or snapshotId must be passed in."
-
- option :domainid,
- :long => "--domainid ID",
- :description => "The domain ID associated with the disk offering. If used with the account parameter returns the disk volume associated with the account for the specified domain."
-
- option :size,
- :long => "--size SIZE",
- :description => "Arbitrary volume size."
-
- option :snapshotid,
- :long => "--snapshotid ID",
- :description => "The snapshot ID for the disk volume. Either diskOfferingId or snapshotId must be passed in."
-
- option :zoneid,
- :long => "--zoneid ID",
- :description => "The ID of the availability zone.",
- :required => true,
- :on => :head
-
-
- def run
- validate_base_options
-
- Chef::Log.debug("Validate hostname and options")
- if locate_config_value(:name)
- volumename = locate_config_value(:name)
- else
- volumename = @name_args.first
- unless /^[a-zA-Z0-9][a-zA-Z0-9_\-#]*$/.match volumename then
- ui.error "Invalid volumename. Please specify a simple name without any spaces"
- exit 1
- end
- end
-
- print "#{ui.color("Creating volume: #{volumename}", :magenta)}\n"
-
- params = {
- 'command' => 'createVolume',
- 'name' => volumename,
- }
-
- params['account'] = locate_config_value(:account) if locate_config_value(:account)
- params['diskofferingid'] = locate_config_value(:diskofferingid) if locate_config_value(:diskofferingid)
- params['domainid'] = locate_config_value(:domainid) if locate_config_value(:domainid)
- params['projectid'] = locate_config_value(:projectid) if locate_config_value(:projectid)
- params['size'] = locate_config_value(:size) if locate_config_value(:size)
- params['snapshotid'] = locate_config_value(:snapshotid) if locate_config_value(:snapshotid)
- params['zoneid'] = locate_config_value(:zoneid) if locate_config_value(:zoneid)
-
- json = connection.send_request(params)
-
- if ! json then
- ui.error("Unable to create volume")
- exit 1
- end
-
- print "Volume #{json['id']} is being created in the background\n";
-
- return json['id']
- end
-
- end # class
-end
diff --git a/lib/chef/knife/cs_volume_list.rb b/lib/chef/knife/cs_volume_list.rb
deleted file mode 100644
index ac354a0..0000000
--- a/lib/chef/knife/cs_volume_list.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-#
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsVolumeList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs volume list (options)"
-
- option :listall,
- :long => "--listall",
- :description => "List all volumes",
- :boolean => true
-
- option :name,
- :long => "--name NAME",
- :description => "Specify volume name to list"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Account :account',
- 'Domain :domain',
- 'State :state',
- 'VMName :vmname',
- 'VMState :vmstate'
- ]
-
- params = { 'command' => "listVolumes" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
- params['name'] = locate_config_value(:name) if locate_config_value(:name)
-
- result = connection.list_object(params, "volume")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/chef/knife/cs_zone_list.rb b/lib/chef/knife/cs_zone_list.rb
deleted file mode 100644
index 56aa093..0000000
--- a/lib/chef/knife/cs_zone_list.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: Sander Botman ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# Copyright:: Copyright (c) 2013 Sander Botman.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/knife'
-require 'chef/knife/cs_baselist'
-
-module KnifeCloudstack
- class CsZoneList < Chef::Knife
-
- include Chef::Knife::KnifeCloudstackBaseList
-
- banner "knife cs zone list (options)"
-
- option :keyword,
- :long => "--keyword KEY",
- :description => "List by keyword"
-
- def run
- validate_base_options
-
- columns = [
- 'Name :name',
- 'Network Type :networktype',
- 'Security Groups :securitygroupsenabled'
- ]
-
- params = { 'command' => "listZones" }
- params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
- params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
-
- result = connection.list_object(params, "zone")
- list_object(columns, result)
- end
-
- end
-end
diff --git a/lib/knife-cloudstack/connection.rb b/lib/knife-cloudstack/connection.rb
deleted file mode 100644
index 6ef9035..0000000
--- a/lib/knife-cloudstack/connection.rb
+++ /dev/null
@@ -1,949 +0,0 @@
-#
-# Author:: Ryan Holmes ()
-# Author:: KC Braunschweig ()
-# Author:: Sander Botman ()
-# Author:: Frank Breedijk ()
-# Author:: Sander van Harmelen ()
-# Copyright:: Copyright (c) 2011 Edmunds, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'rubygems'
-require 'base64'
-require 'openssl'
-require 'uri'
-require 'cgi'
-require 'net/http'
-require 'json'
-require 'highline/import'
-
-class String
- def to_regexp
- return nil unless self.strip.match(/\A\/(.*)\/(.*)\Z/mx)
- regexp , flags = $1 , $2
- return nil if !regexp || flags =~ /[^xim]/m
-
- x = /x/.match(flags) && Regexp::EXTENDED
- i = /i/.match(flags) && Regexp::IGNORECASE
- m = /m/.match(flags) && Regexp::MULTILINE
-
- Regexp.new regexp , [x,i,m].inject(0){|a,f| f ? a+f : a }
- end
-
- def is_uuid?
- self.strip =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ ? true : false
- end
-end
-
-module CloudstackClient
- class Connection
-
- ASYNC_POLL_INTERVAL = 5.0
- ASYNC_TIMEOUT = 600
-
- def initialize(api_url, api_key, secret_key, project_name=nil, no_ssl_verify=false, api_proxy=nil)
- @api_url = api_url
- @api_key = api_key
- @secret_key = secret_key
- @no_ssl_verify = no_ssl_verify
- @project_id = get_project_id(project_name) if project_name || nil
- @api_proxy = api_proxy
- end
-
- ##
- # Get project id
- def get_project_id(name)
- project = get_project(name)
- if !project then
- puts "Project #{project_name} does not exist"
- exit 1
- end
- project['id']
- end
-
- ##
- # Finds the server with the specified name.
-
- def get_server(name)
- params = {
- 'command' => 'listVirtualMachines',
- 'name' => name
- }
- json = send_request(params)
- machines = json['virtualmachine']
-
- if !machines || machines.empty? then
- return nil
- end
- machine = machines.select { |item| name == item['name'] }
- machine.first
- end
-
- ##
- # Finds the public ip for a server
-
- def get_server_public_ip(server, cached_rules=nil, cached_nat=nil)
- return nil unless server
- # find the public ip
- nic = get_server_default_nic(server)
-
- ssh_rule = get_ssh_port_forwarding_rule(server, cached_rules)
- return ssh_rule['ipaddress'] if ssh_rule
-
- winrm_rule = get_winrm_port_forwarding_rule(server, cached_rules)
- return winrm_rule['ipaddress'] if winrm_rule
-
- #check for static NAT
- if cached_nat
- ip_addr = cached_nat.find {|v| v['virtualmachineid'] == server['id']}
- else
- ip_addr = list_public_ip_addresses.find {|v| v['virtualmachineid'] == server['id']}
- end
- if ip_addr
- return ip_addr['ipaddress']
- end
- nic['ipaddress'] || []
- end
-
- ##
- # Returns the fully qualified domain name for a server.
-
- def get_server_fqdn(server)
- return nil unless server
-
- nic = get_server_default_nic(server) || {}
- networks = list_networks || {}
-
- id = nic['networkid']
- network = networks.select { |net|
- net['id'] == id
- }.first
- return nil unless network
-
- "#{server['name']}.#{network['networkdomain']}"
- end
-
- def get_server_default_nic(server)
- server['nic'].each do |nic|
- return nic if nic['isdefault']
- end
- end
-
- ##
- # List all the objects based on the command that is specified.
-
- def list_object(params, json_result)
- json = send_request(params)
- Chef::Log.debug("JSON (list_object) result: #{json}")
-
- result = json["#{json_result}"] || []
- result = data_filter(result, params['filter']) if params['filter']
- result
- end
-
- ##
- # Lists all the servers in your account.
-
- def list_servers
- params = {
- 'command' => 'listVirtualMachines'
- }
- json = send_request(params)
- json['virtualmachine'] || []
- end
-
- ##
- # Deploys a new server using the specified parameters.
-
- def create_server(host_name, service_name, template_name, disk_name=nil, zone_name=nil, network_names=[], extra_params)
-
- if host_name then
- if get_server(host_name) then
- puts "\nError: Server '#{host_name}' already exists."
- exit 1
- end
- end
-
- service = get_service_offering(service_name)
- if !service then
- puts "\nError: Service offering '#{service_name}' is invalid"
- exit 1
- end
-
- template = get_template(template_name, zone_name)
- template = get_iso(template_name, zone_name) unless template
-
- if !template then
- puts "\nError: Template / ISO name: '#{template_name}' is invalid"
- exit 1
- end
-
- if disk_name then
- disk = get_disk_offering(disk_name)
- if !disk then
- puts "\nError: Disk offering '#{disk_name}' is invalid"
- exit 1
- end
- end
-
- zone = zone_name ? get_zone(zone_name) : get_default_zone
- if !zone then
- msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
- puts "\nError: #{msg}"
- exit 1
- end
-
- if zone['networktype'] != 'Basic' then
- # If this is a Basic zone no networkids are needed in the params
-
- networks = []
- if network_names.nil? then
- networks << get_default_network(zone['id'])
- else
- network_names.each do |name|
- network = get_network(name)
- if !network then
- puts "\nError: Network '#{name}' not found"
- end
- networks << get_network(name)
- end
- end
-
- if networks.empty? then
- networks << get_default_network(zone['id'])
- end
- if networks.empty? then
- puts "\nError: No default network found"
- exit 1
- end
- network_ids = networks.map { |network|
- network['id']
- }
-
- params = {
- 'command' => 'deployVirtualMachine',
- 'serviceOfferingId' => service['id'],
- 'templateId' => template['id'],
- 'zoneId' => zone['id'],
- 'networkids' => network_ids.join(',')
- }
-
- else
-
- params = {
- 'command' => 'deployVirtualMachine',
- 'serviceOfferingId' => service['id'],
- 'templateId' => template['id'],
- 'zoneId' => zone['id']
- }
-
- end
-
- params.merge!(extra_params) if extra_params
-
- params['name'] = host_name if host_name
- params['diskOfferingId'] = disk['id'] if disk
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Deletes the server with the specified name.
- #
-
- def delete_server(name, expunge)
- server = get_server(name)
- if !server || !server['id'] then
- puts "\nError: Virtual machine '#{name}' does not exist"
- exit 1
- end
-
- params = {
- 'command' => 'destroyVirtualMachine',
- 'id' => server['id'],
- 'expunge' => expunge
- }
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Stops the server with the specified name.
- #
-
- def stop_server(name, forced=nil)
- server = get_server(name)
- if !server || !server['id'] then
- puts "\nError: Virtual machine '#{name}' does not exist"
- exit 1
- end
-
- params = {
- 'command' => 'stopVirtualMachine',
- 'id' => server['id']
- }
- params['forced'] = true if forced
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Start the server with the specified name.
- #
-
- def start_server(name)
- server = get_server(name)
- if !server || !server['id'] then
- puts "\nError: Virtual machine '#{name}' does not exist"
- exit 1
- end
-
- params = {
- 'command' => 'startVirtualMachine',
- 'id' => server['id']
- }
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Reboot the server with the specified name.
- #
-
- def reboot_server(name)
- server = get_server(name)
- if !server || !server['id'] then
- puts "\nError: Virtual machine '#{name}' does not exist"
- exit 1
- end
-
- params = {
- 'command' => 'rebootVirtualMachine',
- 'id' => server['id']
- }
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Finds the service offering with the specified name.
-
- def get_service_offering(name)
-
- # TODO: use name parameter
- # listServiceOfferings in CloudStack 2.2 doesn't seem to work
- # when the name parameter is specified. When this is fixed,
- # the name parameter should be added to the request.
- params = {
- 'command' => 'listServiceOfferings'
- }
- json = send_request(params)
-
- services = json['serviceoffering']
- return nil unless services
-
- services.each { |s|
- if name.is_uuid? then
- return s if s['id'] == name
- else
- return s if s['name'] == name
- end
- }
- nil
- end
-
- ##
- # Lists all available service offerings.
-
- def list_service_offerings
- params = {
- 'command' => 'listServiceOfferings'
- }
- json = send_request(params)
- json['serviceoffering'] || []
- end
-
- def list_security_groups
- params = {
- 'command' => 'listSecurityGroups'
- }
- json = send_request(params)
- json['securitygroups'] || []
- end
-
-
- ##
- # Finds the template with the specified name.
-
- def get_template(name, zone_name=nil)
-
- # TODO: use name parameter
- # listTemplates in CloudStack 2.2 doesn't seem to work
- # when the name parameter is specified. When this is fixed,
- # the name parameter should be added to the request.
-
- zone = zone_name ? get_zone(zone_name) : get_default_zone
-
- params = {
- 'command' => 'listTemplates',
- 'templateFilter' => 'executable',
- }
- params['zoneid'] = zone['id'] if zone
-
- json = send_request(params)
-
- templates = json['template']
- return nil unless templates
-
- templates.each { |t|
- if name.is_uuid? then
- return t if t['id'] == name
- else
- return t if t['name'] == name
- end
- }
- nil
- end
-
- ##
- # Finds the iso with the specified name.
-
- def get_iso(name, zone_name=nil)
- zone = zone_name ? get_zone(zone_name) : get_default_zone
-
- params = {
- 'command' => 'listIsos',
- 'isoFilter' => 'executable',
- }
- params['zoneid'] = zone['id'] if zone
-
- json = send_request(params)
- iso = json['iso']
- return nil unless iso
-
- iso.each { |i|
- if name.is_uuid? then
- return i if i['id'] == name
- else
- return i if i['name'] == name
- end
- }
- nil
- end
-
-
-
- ##
- # Finds the disk offering with the specified name.
-
- def get_disk_offering(name)
- params = {
- 'command' => 'listDiskOfferings',
- }
- json = send_request(params)
- disks = json['diskoffering']
-
- return nil if !disks
-
- disks.each { |d|
- return d if d['name'] == name
- }
- nil
- end
-
- ##
- # Lists all templates that match the specified filter.
- #
- # Allowable filter values are:
- #
- # * featured - templates that are featured and are public
- # * self - templates that have been registered/created by the owner
- # * self-executable - templates that have been registered/created by the owner that can be used to deploy a new VM
- # * executable - all templates that can be used to deploy a new VM
- # * community - templates that are public
-
- def list_templates(filter)
- filter ||= 'featured'
- params = {
- 'command' => 'listTemplates',
- 'templateFilter' => filter
- }
- json = send_request(params)
- json['template'] || []
- end
-
- #Fetch project with the specified name
- def get_project(name)
- params = {
- 'command' => 'listProjects',
- 'listall' => true
- }
-
- json = send_request(params)
- projects = json['project']
- return nil unless projects
-
- projects.each { |n|
- if name.is_uuid? then
- return n if n['id'] == name
- else
- return n if n['name'] == name
- end
- }
- nil
- end
-
- ##
- # Filter data on regex or just on string
-
- def data_filter(data, filters)
- filters.split(',').each do |filter|
- field = filter.split(':').first.strip.downcase
- search = filter.split(':').last.strip
- if search =~ /^\/.*\/?/
- data = data.find_all { |k| k["#{field}"].to_s =~ search.to_regexp } if field && search
- else
- data = data.find_all { |k| k["#{field}"].to_s == "#{search}" } if field && search
- end
- end
- data
- end
-
-
- ##
- # Finds the network with the specified name.
-
- def get_network(name)
- params = {
- 'command' => 'listNetworks'
- }
- json = send_request(params)
-
- networks = json['network']
- return nil unless networks
-
- networks.each { |n|
- if name.is_uuid? then
- return n if n['id'] == name
- else
- return n if n['name'] == name
- end
- }
- nil
- end
-
- ##
- # Finds the default network.
-
- def get_default_network(zone)
- params = {
- 'command' => 'listNetworks',
- 'isDefault' => true,
- 'zoneid' => zone
- }
- json = send_request(params)
-
- networks = json['network']
- return nil if !networks || networks.empty?
-
- default = networks.first
- return default if networks.length == 1
-
- networks.each { |n|
- if n['type'] == 'Direct' then
- default = n
- break
- end
- }
-
- default
- end
-
- ##
- # Lists all available networks.
-
- def list_networks
- params = {
- 'command' => 'listNetworks'
- }
- json = send_request(params)
- json['network'] || []
- end
-
- ##
- # Finds the zone with the specified name.
-
- def get_zone(name)
- params = {
- 'command' => 'listZones',
- 'available' => 'true'
- }
- json = send_request(params)
-
- networks = json['zone']
- return nil unless networks
-
- networks.each { |z|
- if name.is_uuid? then
- return z if z['id'] == name
- else
- return z if z['name'] == name
- end
- }
- nil
- end
-
- def add_nic_to_vm(network_id, server_id, ipaddr=nil)
- params = {
- 'command' => 'addNicToVirtualMachine',
- 'networkid' => network_id,
- 'virtualmachineid' => server_id,
- }
-
- unless ipaddr.nil?
- params['ipaddress'] = ipaddr
- end
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- def remove_nic_from_vm(nic_id, server_id)
- params = {
- 'command' => 'removeNicFromVirtualMachine',
- 'nicid' => nic_id,
- 'virtualmachineid' => server_id,
- }
-
- json = send_async_request(params)
- json['virtualmachine']
- end
-
- ##
- # Finds the default zone for your account.
-
- def get_default_zone
- params = {
- 'command' => 'listZones',
- 'available' => 'true'
- }
- json = send_request(params)
-
- zones = json['zone']
- return nil unless zones
- # zones.sort! # sort zones so we always return the same zone
- # !this gives error in our production environment so need to retest this
- zones.first
- end
-
- ##
- # Lists all available zones.
-
- def list_zones
- params = {
- 'command' => 'listZones',
- 'available' => 'true'
- }
- json = send_request(params)
- json['zone'] || []
- end
-
- ##
- # Finds the public ip address for a given ip address string.
-
- def get_public_ip_address(ip_address)
- params = {
- 'command' => 'listPublicIpAddresses',
- 'ipaddress' => ip_address
- }
- json = send_request(params)
- return nil unless json['publicipaddress']
- json['publicipaddress'].first
- end
-
- def list_public_ip_addresses(listall=false)
- params = { 'command' => 'listPublicIpAddresses' }
- params['listall'] = listall
-
- json = send_request(params)
- return json['publicipaddress'] || []
- end
- ##
- # Acquires and associates a public IP to an account.
-
- def associate_ip_address(zone_id, networks)
- params = {
- 'command' => 'associateIpAddress',
- 'zoneId' => zone_id
- }
- #Choose the first network from the list
- if networks.nil? || networks.empty?
- default_network = get_default_network(zone_id)
- params['networkId'] = default_network['id']
- else
- params['networkId'] = get_network(networks.first)['id']
- end
- Chef::Log.debug("associate ip params: #{params}")
- json = send_async_request(params)
- json['ipaddress']
- end
-
- def enable_static_nat(ipaddress_id, virtualmachine_id)
- params = {
- 'command' => 'enableStaticNat',
- 'ipAddressId' => ipaddress_id,
- 'virtualmachineId' => virtualmachine_id
- }
- send_request(params)
- end
-
- def disable_static_nat(ipaddress)
- params = {
- 'command' => 'disableStaticNat',
- 'ipAddressId' => ipaddress['id']
- }
- send_async_request(params)
- end
-
- def create_ip_fwd_rule(ipaddress_id, protocol, start_port, end_port)
- params = {
- 'command' => 'createIpForwardingRule',
- 'ipaddressId' => ipaddress_id,
- 'protocol' => protocol,
- 'startport' => start_port,
- 'endport' => end_port
- }
-
- send_async_request(params)
- end
-
- def create_firewall_rule(ipaddress_id, protocol, param3, param4, cidr_list)
- if protocol == "ICMP"
- params = {
- 'command' => 'createFirewallRule',
- 'ipaddressId' => ipaddress_id,
- 'protocol' => protocol,
- 'icmptype' => param3,
- 'icmpcode' => param4,
- 'cidrlist' => cidr_list
- }
- else
- params = {
- 'command' => 'createFirewallRule',
- 'ipaddressId' => ipaddress_id,
- 'protocol' => protocol,
- 'startport' => param3,
- 'endport' => param4,
- 'cidrlist' => cidr_list
- }
- end
- send_async_request(params)
- end
-
- ##
- # Disassociates an ip address from the account.
- #
- # Returns true if successful, false otherwise.
-
- def disassociate_ip_address(id)
- params = {
- 'command' => 'disassociateIpAddress',
- 'id' => id
- }
- json = send_async_request(params)
- json['success']
- end
-
- ##
- # Lists all port forwarding rules.
-
- def list_port_forwarding_rules(ip_address_id=nil, listall=false)
- params = { 'command' => 'listPortForwardingRules' }
- params['ipAddressId'] = ip_address_id if ip_address_id
- params['listall'] = listall
- json = send_request(params)
- json['portforwardingrule']
- end
-
- ##
- # Gets the SSH port forwarding rule for the specified server.
-
- def get_ssh_port_forwarding_rule(server, cached_rules=nil)
- rules = cached_rules || list_port_forwarding_rules || []
- rules.find_all { |r|
- r['virtualmachineid'] == server['id'] &&
- r['privateport'] == '22'&&
- r['publicport'] == '22'
- }.first
- end
-
- ##
- # Gets the WINRM port forwarding rule for the specified server.
-
- def get_winrm_port_forwarding_rule(server, cached_rules=nil)
- rules = cached_rules || list_port_forwarding_rules || []
- rules.find_all { |r|
- r['virtualmachineid'] == server['id'] &&
- (r['privateport'] == '5985' &&
- r['publicport'] == '5985') ||
- (r['privateport'] == '5986' &&
- r['publicport'] == '5986')
- }.first
- end
-
- ##
- # Creates a port forwarding rule.
-
- def create_port_forwarding_rule(ip_address_id, private_port, protocol, public_port, virtual_machine_id)
- params = {
- 'command' => 'createPortForwardingRule',
- 'ipAddressId' => ip_address_id,
- 'privatePort' => private_port,
- 'protocol' => protocol,
- 'publicPort' => public_port,
- 'virtualMachineId' => virtual_machine_id
- }
- json = send_async_request(params)
- json['portforwardingrule']
- end
-
- def http_client_builder
- http_proxy = proxy_uri
- if http_proxy.nil?
- Net::HTTP
- else
- Chef::Log.debug("Using #{http_proxy.host}:#{http_proxy.port} for proxy")
- user = http_proxy.user if http_proxy.user
- pass = http_proxy.password if http_proxy.password
- Net::HTTP.Proxy(http_proxy.host, http_proxy.port, user, pass)
- end
- end
-
- def proxy_uri
- return nil if @api_proxy.nil?
- result = URI.parse(@api_proxy)
- return result unless result.host.nil? || result.host.empty?
- nil
- end
-
- ##
- # Sends a synchronous request to the CloudStack API and returns the response as a Hash.
- #
- # The wrapper element of the response (e.g. mycommandresponse) is discarded and the
- # contents of that element are returned.
-
- def send_request(params)
- if @project_id
- params['projectId'] = @project_id
- end
- params['response'] = 'json'
- params['apiKey'] = @api_key
-
- params_arr = []
- params.sort.each { |elem|
- params_arr << elem[0].to_s + '=' + CGI.escape(elem[1].to_s).gsub('+', '%20').gsub(' ','%20')
- }
- data = params_arr.join('&')
- signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
- signature = Base64.encode64(signature).chomp
- signature = CGI.escape(signature)
-
- if @api_url.nil? || @api_url.empty?
- puts "Error: Please specify a valid API URL."
- exit 1
- end
-
- url = "#{@api_url}?#{data}&signature=#{signature}"
- Chef::Log.debug("URL: #{url}")
- uri = URI.parse(url)
-
- http = http_client_builder.new(uri.host, uri.port)
-
- if uri.scheme == "https"
- http.use_ssl = true
- # Still need to do some testing on SSL, so will fix this later
- if @no_ssl_verify
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- else
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- end
- end
- request = Net::HTTP::Get.new(uri.request_uri)
- response = http.request(request)
-
- if !response.is_a?(Net::HTTPOK) then
- case response.code
- when "432"
- puts "\n"
- puts "Error #{response.code}: Your account does not have the right to execute this command is locked or the command does not exist."
- else
- puts "Error #{response.code}: #{response.message}"
- puts JSON.pretty_generate(JSON.parse(response.body))
- puts "URL: #{url}"
- end
- exit 1
- end
-
- json = JSON.parse(response.body)
- json[params['command'].downcase + 'response']
- end
-
- ##
- # Sends an asynchronous request and waits for the response.
- #
- # The contents of the 'jobresult' element are returned upon completion of the command.
-
- def send_async_request(params)
-
- json = send_request(params)
-
- params = {
- 'command' => 'queryAsyncJobResult',
- 'jobId' => json['jobid']
- }
-
- max_tries = (ASYNC_TIMEOUT / ASYNC_POLL_INTERVAL).round
- max_tries.times do
- json = send_request(params)
- status = json['jobstatus']
-
- print "."
-
- if status == 1 then
- print "\n"
- return json['jobresult']
- elsif status == 2 then
- print "\n"
- puts "Request failed (#{json['jobresultcode']}): #{json['jobresult']}"
- exit 1
- end
-
- STDOUT.flush
- sleep ASYNC_POLL_INTERVAL
- end
-
- print "\n"
- puts "Error: Asynchronous request timed out"
- exit 1
- end
-
- end # class
-end
-
diff --git a/lib/knife-cs/version.rb b/lib/knife-cs/version.rb
new file mode 100644
index 0000000..47e1cdb
--- /dev/null
+++ b/lib/knife-cs/version.rb
@@ -0,0 +1,5 @@
+module Knife
+ module Cloudstack
+ VERSION = "0.1.0"
+ end
+end