knife-proxmox 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,155 @@
1
+ Author: Jorge Moratilla
2
+ Date: 2012-10-07
3
+ [2013-01-23]
4
+ Version: 0.0.10
5
+ * knife proxmox server create can bootstrap a server, enabled by default
6
+
7
+ [2013-01-21]
8
+ Version: 0.0.9
9
+ * Added IP field to server list command
10
+
11
+ [2012-12-21]
12
+ Version: 0.0.8
13
+ * Added a patch for proxmox that allows me to fetch the IP of the guess
14
+ * Working with the PVE API
15
+
16
+ [2012-12-13]
17
+ Version: 0.0.6
18
+ * Added new field in proxmox server list to show the node the vm is in
19
+ * Now you can start, stop, destroy a server without to specify the node
20
+
21
+ [2012-12-12]
22
+ Version: 0.0.5
23
+ * Improved problems with selection of the node of the cluster
24
+ * Better checking of task status
25
+ * Solved problem #3 catching from exceptions
26
+
27
+ [2012-11-12]
28
+
29
+ Added an option to knife proxmox server create that allows the user to specify the ipaddress. If not, then the VM will be created with DHCP enabled.
30
+ Created a very basic task control for creating and deleting servers. Great refactoring needed.
31
+ Now, I'm using bitbucket issue control center to keep control of issues. Please use this link to add control keys in pushes
32
+ https://confluence.atlassian.com/display/BITBUCKET/Automatically+Resolving+Issues+when+Users+Push+Code
33
+
34
+ [2012-11-06]
35
+
36
+ Added server start and stop commands
37
+ $ knife proxmox server start --vmid 401
38
+ Starting VM 401....
39
+ Result: 200
40
+
41
+ $ knife proxmox server stop --vmid 103
42
+ Stoping VM 103....
43
+ Result: 200
44
+
45
+
46
+ [2012-11-05]
47
+
48
+ First refactor, ProxmoxBase has now all the common parameters
49
+ Added proxmox server list to show current servers
50
+ Example:
51
+ $ knife proxmox server list
52
+ Id Name Type Status
53
+ 104 tetatet.jnlabs.isp openvz down
54
+ 470 sg-node1.jnlabs.isp openvz up
55
+ 102 test qemu down
56
+ 202 chef-client1 openvz down
57
+
58
+ [2012-10-24]
59
+
60
+ Improved knife commands. Needs refactor internally
61
+ Examples:
62
+
63
+ List templates installed
64
+ $ knife proxmox template list -U https://localhost:8006/api2/json/ -n localhost -u test -p test123 -R pve -VV
65
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
66
+ Id Name Size
67
+ 0 local:vztmpl/debian-6.0-request-tracker_3.8.8-2_i386.tar.gz 171 MB
68
+ 1 local:vztmpl/old_ubuntu-11.10-x86_64.tar.gz 124 MB
69
+ 2 local:vztmpl/ubuntu-10.04-standard_10.04-4_i386.tar.gz 135 MB
70
+ 3 local:vztmpl/ubuntu-11.10-x86_64-jorge1-.tar.gz 124 MB
71
+ 4 local:vztmpl/ubuntu-11.10-x86_64-jorge2-.tar.gz 154 MB
72
+
73
+
74
+ List templates available to download
75
+ $ knife proxmox template available -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -VV
76
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
77
+ Name Operating System
78
+ debian-6-turnkey-concrete5_12.0-1_i386.tar.gz debian-6
79
+ ubuntu-10.04-turnkey-prestashop_11.3-1_i386.tar.gz ubuntu-10.04
80
+ debian-6-turnkey-joomla25_12.0-1_i386.tar.gz debian-6
81
+ debian-6-turnkey-tomcat-apache_12.0-1_i386.tar.gz debian-6
82
+ debian-6.0-wordpress_3.4.2-1_i386.tar.gz debian-6.0 .....
83
+
84
+
85
+ Create a server
86
+ $ knife proxmox server create -U https://localhost:8006/api2/json/ -n localhost -u test -p test123 -R pve -N vm-node1 --template 4 -VV
87
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
88
+ DEBUG: vmid=303&hostname=vm-node1&storage=local&password=pve123&ostemplate=local%3Avztmpl%2Fubuntu-11.10-x86_64-jorge2-.tar.gz&memory=512&swap=512&disk=4&cpus=1&netif=ifname%3Deth0%2Cbridge%3Dvmbr0
89
+ Result: 200
90
+ ..............................
91
+ Starting VM 303....
92
+ Result: 200
93
+
94
+ Destroy a server
95
+ $ knife proxmox server destroy -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -N vm-node1 -VV
96
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
97
+ node to destroy: vm-node1
98
+ Stopping VM 303....
99
+ Result: 200
100
+ ..............................
101
+ Result: 200
102
+
103
+
104
+ [2012-10-17]
105
+
106
+ First preliminar version is working, but only as separate knife plugin files.
107
+
108
+ In order to work, these files must be copied to your ~/.chef/plugins/knife directory. If it
109
+ doesn't exist, then you must create it.
110
+
111
+ Actions implemented
112
+
113
+ proxmox server create
114
+ proxmox server destroy
115
+ proxmox template available
116
+ proxmox template list
117
+
118
+ Next steps
119
+
120
+ R.E.F.A.C.T.O.R
121
+
122
+ Options in command line for each action
123
+
124
+
125
+ [2012-10-07]
126
+
127
+ This project is a plugin for knife that allows a user to list templates, create and delete
128
+ proxmox virtual machines (openvz instances mainly)
129
+
130
+ I've two ways to do this:
131
+ A) Create a knife plugin directly using command line tools (pvesh and pvesm)
132
+ B) Create a provider for fog (github.com/fog/fog) and then create the knife plugin based on fog
133
+
134
+ Thoughts:
135
+ Option A is the easy quick and dirty solution for me now.
136
+ Option B is the proper way to do it. Unfortunately, I'm not able to afford it. It's too complex.
137
+
138
+ Actions:
139
+ Option A)
140
+
141
+ . knife proxmox template list
142
+ |- pvesh get /nodes/SERVER_NAME/storage/STORAGE/content
143
+ |--{
144
+ "content" : "vztmpl",
145
+ "format" : "tgz",
146
+ "size" : 161655654,
147
+ "volid" : "local:vztmpl/ubuntu-11.10-x86_64-jorge2-.tar.gz"
148
+ },
149
+
150
+ . knife proxmox server create
151
+ |- pvesh create /nodes/localhost/openvz -ostemplate local:vztmpl/ubuntu-11.10-x86_64-jorge2-.tar.gz -vmid 106 -cpus 1 -memory 1024 -disk 4 -hostname jorge_test
152
+
153
+ . knife proxmox server destroy
154
+ |- pvesh destroy 106
155
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-proxmox.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ knife-proxmox (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ knife-proxmox!
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README ADDED
@@ -0,0 +1,127 @@
1
+ Authors: Jorge Moratilla, Sergio Galvan
2
+ Date: 2012-10-07
3
+
4
+ This knife plugin allows to access Proxmox Virtualization Environment (Proxmox VE or PVE) through its API.
5
+ It allows you to lists templates installed on the server/cluster (like images or amis), create a server or
6
+ destroy it.
7
+
8
+ Currently it only supports management of openVZ instances, but KVM instances will be able too.
9
+
10
+
11
+ Actions implemented
12
+
13
+ proxmox server list
14
+ proxmox server create
15
+ proxmox server start
16
+ proxmox server stop
17
+ proxmox server destroy
18
+ proxmox template available
19
+ proxmox template list
20
+
21
+ Some Examples
22
+
23
+ List servers
24
+ $ knife proxmox server list
25
+ Id Node Name Type Status
26
+ 104 node-1 tetatet.jnlabs.isp openvz down
27
+ 470 node-2 sg-node1.jnlabs.isp openvz up
28
+ 102 node-1 test qemu down
29
+ 202 node-2 chef-client1 openvz down
30
+
31
+ List templates installed
32
+ $ knife proxmox template list -U https://localhost:8006/api2/json/ -n localhost -u test -p test123 -R pve -VV
33
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
34
+ Id Name Size
35
+ 0 local:vztmpl/debian-6.0-request-tracker_3.8.8-2_i386.tar.gz 171 MB
36
+ 1 local:vztmpl/old_ubuntu-11.10-x86_64.tar.gz 124 MB
37
+ 2 local:vztmpl/ubuntu-10.04-standard_10.04-4_i386.tar.gz 135 MB
38
+ 3 local:vztmpl/ubuntu-11.10-x86_64-jorge1-.tar.gz 124 MB
39
+ 4 local:vztmpl/ubuntu-11.10-x86_64-jorge2-.tar.gz 154 MB
40
+
41
+
42
+ List templates available to download
43
+ $ knife proxmox template available -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -VV
44
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
45
+ Name Operating System
46
+ debian-6-turnkey-concrete5_12.0-1_i386.tar.gz debian-6
47
+ ubuntu-10.04-turnkey-prestashop_11.3-1_i386.tar.gz ubuntu-10.04
48
+ debian-6-turnkey-joomla25_12.0-1_i386.tar.gz debian-6
49
+ debian-6-turnkey-tomcat-apache_12.0-1_i386.tar.gz debian-6
50
+ debian-6.0-wordpress_3.4.2-1_i386.tar.gz debian-6.0 .....
51
+
52
+
53
+ Create a server
54
+ $ knife proxmox server create -n ankh -r "recipe[java]" -C 2 -M 1024 -H example-server -P test123 -T 4
55
+ Creating VM 473...
56
+ ..............OK
57
+ Preparing the server to start
58
+ Starting VM 473 on node ankh....
59
+ ..OK
60
+ New Server 473 has IP Address: 10.0.2.19
61
+ done
62
+ Bootstrapping Chef on 10.0.2.19
63
+ 10.0.2.19 --2013-01-23 01:27:20-- http://opscode.com/chef/install.sh
64
+ 10.0.2.19 Resolving opscode.com...
65
+ 10.0.2.19 184.106.28.83
66
+ 10.0.2.19 Connecting to opscode.com|184.106.28.83|:80...
67
+ 10.0.2.19 connected.
68
+ 10.0.2.19 HTTP request sent, awaiting response...
69
+ 10.0.2.19 301 Moved Permanently
70
+ 10.0.2.19 Location: http://www.opscode.com/chef/install.sh [following]
71
+ 10.0.2.19 --2013-01-23 01:27:21-- http://www.opscode.com/chef/install.sh
72
+ 10.0.2.19 Resolving www.opscode.com...
73
+ 10.0.2.19 184.106.28.83
74
+ 10.0.2.19 Reusing existing connection to opscode.com:80.
75
+ 10.0.2.19 HTTP request sent, awaiting response...
76
+ 10.0.2.19 200 OK
77
+
78
+
79
+ Starting a server
80
+ $ knife proxmox server start --vmid 401
81
+ Starting VM 401....
82
+ Result: 200
83
+
84
+
85
+ Stopping a server
86
+ $ knife proxmox server stop --vmid 103
87
+ Stoping VM 103....
88
+ Result: 200
89
+
90
+
91
+ Destroy a server
92
+ $ knife proxmox server destroy -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -N vm-node1 -VV
93
+ DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
94
+ node to destroy: vm-node1
95
+ Stopping VM 303....
96
+ Result: 200
97
+ ..............................
98
+ Result: 200
99
+
100
+ This gem must be installed on your system using the command
101
+
102
+ $ gem install knife-proxmox
103
+
104
+ If you want to read values from the environment variables modify your knife.rb:
105
+
106
+ knife[:pve_cluster_url] ||= "#{ENV['PVE_CLUSTER_URL']}"
107
+ knife[:pve_user_name] ||= "#{ENV['PVE_USER_NAME']}"
108
+ knife[:pve_node_name] ||= "#{ENV['PVE_NODE_NAME']}"
109
+ knife[:pve_user_realm] ||= "#{ENV['PVE_USER_REALM']}"
110
+
111
+ However I don't recommend to have the user password as a environment variable.
112
+ knife[:pve_user_password] = "#{ENV['PVE_CLUSTER_URL']}"
113
+
114
+ Environment Variables
115
+
116
+ PVE_CLUSTER_URL = https://<proxmox_server>:8006/api2/json/
117
+ PVE_USER_NAME = <user>
118
+ PVE_PASSWORD_NAME = <password>
119
+ PVE_USER_REALM = <pam|pve|others>
120
+ PVE_NODE_NAME = <nodename>
121
+
122
+ If you want to alter some variable by command line then you can use the following options:
123
+ -n --node <node> If in a cluster, this argument will specify which node of the cluster will do the action
124
+ -U --pve_cluster_url <http://localhost...> Will change the cluster to access to
125
+ -u --username <user> Same for user
126
+ -p --password <pass> Same for password
127
+ -r --realm <realm> Same for the realm used to authenticate