knife-proxmox 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,6 +1,14 @@
1
1
  Author: Jorge Moratilla
2
2
  Date: 2012-10-07
3
3
 
4
+ [2013-05-07]
5
+ Version: 0.0.19
6
+ * knife proxmox server destroy now includes option -y to avoid confirmation (used for scripting)
7
+
8
+ [2013-05-03]
9
+ Version: 0.0.18
10
+ * knife proxmox server list now sorts output by vmid (default) and by field (vmid, node, name)
11
+
4
12
  [2013-04-29]
5
13
  Version: 0.0.17
6
14
  * knife proxmox server destroy now requests confirmation to delete a server
data/README.md CHANGED
@@ -38,10 +38,10 @@ Then install your ruby language (recommended ruby-1.9.3-xxx)
38
38
  ### List servers
39
39
  $ knife proxmox server list
40
40
  Id Node Name Type Status
41
- 104 node-1 tetatet.example.com openvz down
42
- 470 node-2 sg-node1.example.com openvz up
43
41
  102 node-1 test qemu down
42
+ 104 node-1 tetatet.example.com openvz down
44
43
  202 node-2 chef-client1 openvz down
44
+ 470 node-2 sg-node1.example.com openvz up
45
45
 
46
46
  ### Get info for a server
47
47
  $ knife proxmox server info -H tetatet.example.com -P ip
@@ -133,7 +133,7 @@ Then install your ruby language (recommended ruby-1.9.3-xxx)
133
133
 
134
134
 
135
135
  ### Destroy a server
136
- $ knife proxmox server destroy -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -N vm-node1 -VV
136
+ $ knife proxmox server destroy -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -N vm-node1 -VV -P
137
137
  DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
138
138
  node to destroy: vm-node1 [vmid: 200]
139
139
  Continue? (Y/N) y
@@ -141,6 +141,9 @@ Then install your ruby language (recommended ruby-1.9.3-xxx)
141
141
  Result: 200
142
142
  ..............................
143
143
  Result: 200
144
+ WARNING: Deleted node vm-node1
145
+ WARNING: Deleted client vm-node1
146
+
144
147
 
145
148
  ## Installation
146
149
 
@@ -173,6 +176,12 @@ If you want to alter some variable by command line then you can use the followin
173
176
  -p --password <pass> Same for password
174
177
  -r --realm <realm> Same for the realm used to authenticate
175
178
 
179
+ There is a script in extra/set_environment_variables.sh that creates the
180
+ set of variables needed for knife-proxmox. Just answer the questions and
181
+ paste the output into your profile file.
182
+
183
+
184
+
176
185
  ### ABOUT CHEF AND PROXMOX
177
186
 
178
187
  To bootstrap a newly created VM, you should apply the patch inside the extra directory. Otherwise you must
@@ -167,14 +167,15 @@ class Chef
167
167
  else
168
168
  result = "NOK: error code = " + response.code.to_s
169
169
  end
170
- taskid = JSON.parse(response.body)['data']
171
- waitfor(taskid)
170
+ ui.msg(result)
171
+ taskid = JSON.parse(response.body)['data'] || nil
172
+ waitfor(taskid) unless taskid.nil?
172
173
  Chef::Log.debug("Action: #{action}, Result: #{result}\n")
173
174
  rescue Exception => msg
174
175
  result = "An exception ocurred. Use -VV to show it"
175
- Chef::Log.debug("Action: #{action}, Result: #{msg}\n")
176
+ Chef::Log.debug("Task ID: " + taskid.to_s + ", Class: " + taskid.class)
177
+ Chef::Log.debug("Action: #{action}, Return code: #{response.code}, Exception: #{msg}\n")
176
178
  end
177
- ui.msg(result)
178
179
  end
179
180
 
180
181
  # waitfor end of the task, need the taskid and the timeout
@@ -190,6 +191,7 @@ class Chef
190
191
  end
191
192
  end
192
193
 
194
+ # server_start: Starts the server
193
195
  def server_start(vmid)
194
196
  node = vmid_to_node(vmid)
195
197
  ui.msg("Starting VM #{vmid} on node #{node}....")
@@ -208,25 +210,55 @@ class Chef
208
210
  # take the response and extract the taskid
209
211
  action_response("server stop",response)
210
212
  end
213
+ # TODO: check with server_get_data the status/current/status of the vmid to send the umount command
211
214
  rescue Exception => e
212
215
  ui.warn("The VMID does not match any node")
213
216
  exit 1
214
217
  end
215
218
 
219
+ # server_unmount: Unmounts the server's filesystem
220
+ def server_umount(vmid)
221
+ node = vmid_to_node(vmid)
222
+ ui.msg("Unmounting VM #{vmid} on node #{node}...")
223
+ @connection["nodes/#{node}/openvz/#{vmid}/status/umount"].post "", @auth_params do |response, request, result, &block|
224
+ # take the response and extract the taskid
225
+ action_response("server umount",response)
226
+ end
227
+ rescue Exception => e
228
+ ui.warn("The VMID does not match any node")
229
+ exit 1
230
+ end
231
+
232
+
233
+ # server_create: Sends a vm_definition to proxmox for creation
216
234
  def server_create(vmid,vm_definition)
217
235
  ui.msg("Creating VM #{vmid}...")
218
236
  @connection["nodes/#{Chef::Config[:knife][:pve_node_name]}/openvz"].post "#{vm_definition}", @auth_params do |response, request, result, &block|
219
237
  action_response("server create",response)
220
238
  end
221
239
  end
222
-
223
- # server_get_address: Returns the IP Address of the machine to chef
224
- # field is a string, and if it doesn't exist, it will return nil
240
+
241
+ # server_modify: Sends a vm_definition to a running VM
242
+ # data:
243
+ # PUT /api2/json/nodes/esxi-2/openvz/170/config
244
+ # {
245
+ # memory=>2048
246
+ # swap=>512
247
+ # disk=>16
248
+ # cpus=>4
249
+ # }
250
+ # Definition must be a JSON
251
+ def server_modify(vmid,vm_definition)
252
+ ui.msg("Modifying VM #{vmid}...")
253
+ @connection["nodes/#{Chef::Config[:knife][:pve_node_name]}/openvz/#{vmid}/config"].put "#{vm_definition}", @auth_params do |response, request, result, &block|
254
+ action_response("server modify",response)
255
+ end
256
+ end
257
+
258
+ # server_get_data: Returns the parameter requested, or all
225
259
  def server_get_data(vmid,field)
226
260
  node = vmid_to_node(vmid)
227
261
  @connection["nodes/#{node}/openvz/#{vmid}/status/current"].get @auth_params do |response, request, result, &block|
228
- #action_response("server get data",response)
229
- # (field.match('all'))?JSON.parse(response.body)['data'].to_json : JSON.parse(response.body)['data'][field]
230
262
  if (field == 'all') then
231
263
  JSON.parse(response.body)['data']
232
264
  else
@@ -26,6 +26,11 @@ class Chef
26
26
  :long => "--vmid number",
27
27
  :description => "The numeric identifier of the VM"
28
28
 
29
+ option :force,
30
+ :short => "-y",
31
+ :long => "--yes",
32
+ :description => "Force answer to yes (useful for scripting)"
33
+
29
34
  def run
30
35
  # Needed
31
36
  connection
@@ -39,7 +44,9 @@ class Chef
39
44
  name = config[:chef_node_name]
40
45
  vm_id = server_name_to_vmid(name)
41
46
  puts "Server to destroy: #{name} [vmid: #{vm_id}]"
42
- ui.confirm("Continue")
47
+ if (config[:force].nil?) then
48
+ ui.confirm("Continue")
49
+ end
43
50
  else
44
51
  vm_id = config[:vm_id]
45
52
  end
@@ -0,0 +1,71 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProxmoxServerModify < Knife
6
+
7
+ include Knife::ProxmoxBase
8
+
9
+ banner "knife proxmox server modify (options)"
10
+
11
+ # TODO: parameters for openvz should be in other object
12
+ option :vm_hostname,
13
+ :short => "-H hostname",
14
+ :long => "--hostname hostname",
15
+ :description => "VM instance hostname"
16
+
17
+ option :vm_cpus,
18
+ :short => "-C CPUs",
19
+ :long => "--cpus number",
20
+ :description => "Number of cpus of the VM instance"
21
+
22
+ option :vm_memory,
23
+ :short => "-M MB",
24
+ :long => "--mem MB",
25
+ :description => "Memory in MB"
26
+
27
+ option :vm_swap,
28
+ :short => "-SW",
29
+ :long => "--swap MB",
30
+ :description => "Memory in MB for swap"
31
+
32
+ option :vm_vmid,
33
+ :short => "-I id",
34
+ :long => "--vmid id",
35
+ :description => "Id for the VM"
36
+
37
+ option :vm_disk,
38
+ :short => "-D disk",
39
+ :long => "--disk GB",
40
+ :description => "Disk space in GB"
41
+
42
+ def run
43
+ # Needed
44
+ connection
45
+
46
+ vm_config = Hash.new
47
+
48
+ vm_config[:id] = config[:vm_vmid] || nil
49
+ vm_config[:hostname] = config[:vm_hostname] || nil
50
+ vm_config[:cpus] = config[:vm_cpus] || nil #server_get_data(vm_id,"cpus")
51
+ vm_config[:memory] = config[:vm_memory] || nil #server_get_data(vm_id,"memory")
52
+ vm_config[:disk] = config[:vm_disk] || nil #server_get_data(vm_id,"disk")
53
+ vm_config[:swap] = config[:vm_swap] || nil #server_get_data(vm_id,"swap")
54
+
55
+ vm_mod_op = vm_config.keys.select { |v| vm_config[v] }
56
+ vm_definition = []
57
+ vm_mod_op.each do |k|
58
+ # volver a usar el inject
59
+ vm_definition << "#{k.to_s}=#{vm_config[k].to_i}" unless k == :id
60
+ end
61
+ vm_modification = vm_definition.join('&').to_s
62
+
63
+
64
+ Chef::Log.debug(vm_modification)
65
+ server_modify(vm_config[:id],vm_modification)
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -7,7 +7,7 @@ class Chef
7
7
 
8
8
  include Knife::ProxmoxBase
9
9
 
10
- banner "knife proxmox server start (options)"
10
+ banner "knife proxmox server stop (options)"
11
11
 
12
12
  option :vm_id,
13
13
  :short => "-I number",
@@ -25,4 +25,4 @@ class Chef
25
25
  end
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Proxmox
3
- VERSION = "0.0.18"
3
+ VERSION = "0.0.19"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-03 00:00:00.000000000 Z
13
+ date: 2013-12-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chef
@@ -82,6 +82,7 @@ files:
82
82
  - lib/chef/knife/proxmox_server_create.rb
83
83
  - lib/chef/knife/template.rb
84
84
  - lib/chef/knife/proxmox_template_available.rb
85
+ - lib/chef/knife/proxmox_server_modify.rb
85
86
  - lib/chef/knife/connection.rb
86
87
  - lib/chef/knife/proxmox_server_list.rb
87
88
  - lib/knife-proxmox/version.rb