knife-xapi 0.4.6 → 0.5.0.rc3
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/lib/chef/knife/xapi_base.rb
CHANGED
@@ -507,6 +507,38 @@ class Chef::Knife
|
|
507
507
|
task_ref = get_task_ref(task)
|
508
508
|
end
|
509
509
|
|
510
|
+
|
511
|
+
def get_host_ref(hostname)
|
512
|
+
xapi.host.get_all.each do |ref|
|
513
|
+
name = xapi.host.get_name_label ref
|
514
|
+
return ref if hostname == name
|
515
|
+
end
|
516
|
+
nil
|
517
|
+
end
|
518
|
+
|
519
|
+
def start(vm_ref, host=nil)
|
520
|
+
if host
|
521
|
+
host_ref = get_host_ref(host)
|
522
|
+
unless host_ref
|
523
|
+
ui.msg "Host not found #{host}"
|
524
|
+
exit 1
|
525
|
+
end
|
526
|
+
ui.msg( "Starting #{vm_ref} on #{host}" )
|
527
|
+
task = xapi.Async.VM.start_on(vm_ref, host_ref, false, true)
|
528
|
+
else
|
529
|
+
ui.msg( "Starting #{vm_ref} " )
|
530
|
+
task = xapi.Async.VM.start(vm_ref, false, true)
|
531
|
+
end
|
532
|
+
wait_on_task(task)
|
533
|
+
ui.msg( "#{ h.color "OK!", :green}" )
|
534
|
+
end
|
535
|
+
|
536
|
+
def stop(vm_ref)
|
537
|
+
ui.msg( "Stopping #{vm_ref}" )
|
538
|
+
task = xapi.Async.VM.clean_shutdown(vm_ref)
|
539
|
+
wait_on_task(task)
|
540
|
+
ui.msg( "#{ h.color "OK!", :green}" )
|
541
|
+
end
|
510
542
|
|
511
543
|
end
|
512
544
|
end
|
@@ -37,7 +37,7 @@ class Chef
|
|
37
37
|
:xapi_disk_size => "8g",
|
38
38
|
:xapi_cpus => "1",
|
39
39
|
:xapi_mem => "1g",
|
40
|
-
:bootstrap_template => "
|
40
|
+
:bootstrap_template => "chef-full",
|
41
41
|
:template_file => false,
|
42
42
|
:run_list => [],
|
43
43
|
:json_attributes => {}
|
@@ -320,9 +320,7 @@ class Chef
|
|
320
320
|
provisioned = xapi.VM.provision(vm_ref)
|
321
321
|
|
322
322
|
ui.msg "Starting new Guest #{h.color( provisioned, :cyan)} "
|
323
|
-
|
324
|
-
wait_on_task(task)
|
325
|
-
ui.msg( "#{ h.color "OK!", :green}" )
|
323
|
+
start(vm_ref)
|
326
324
|
|
327
325
|
exit 0 unless locate_config_value(:run_list)
|
328
326
|
rescue Exception => e
|
@@ -333,8 +331,10 @@ class Chef
|
|
333
331
|
fail(vm_ref)
|
334
332
|
end
|
335
333
|
|
336
|
-
if locate_config_value(:run_list).empty?
|
337
|
-
|
334
|
+
if locate_config_value(:run_list).empty?
|
335
|
+
unless ( locate_config_value(:template_file) or locate_config_value(:bootstrap_template) )
|
336
|
+
exit 0
|
337
|
+
end
|
338
338
|
end
|
339
339
|
|
340
340
|
guest_addr = wait_for_guest_ip(vm_ref)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jesse Nelson <spheromak@gmail.com>
|
3
|
+
# Author:: Seung-jin/Sam Kim (<seungjin.kim@me.comm>)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright (c) 2012 Jesse Nelson
|
6
|
+
#
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
require 'chef/knife/xapi_base'
|
22
|
+
require 'chef/knife/xapi_vmselect'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class XapiGuestStart < Knife
|
27
|
+
include Chef::Knife::XapiBase
|
28
|
+
|
29
|
+
banner "knife xapi guest start"
|
30
|
+
|
31
|
+
include Chef::Knife::XapiVmSelect
|
32
|
+
|
33
|
+
def run
|
34
|
+
vm = select_vm(@name_args[0])
|
35
|
+
|
36
|
+
if vm.is_a? Array
|
37
|
+
vm.each { |vm| start(vm) }
|
38
|
+
else
|
39
|
+
start(vm)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jesse Nelson <spheromak@gmail.com>
|
3
|
+
# Author:: Seung-jin/Sam Kim (<seungjin.kim@me.comm>)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright (c) 2012 Jesse Nelson
|
6
|
+
#
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
require 'chef/knife/xapi_base'
|
22
|
+
require 'chef/knife/xapi_vmselect'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class XapiGuestStop < Knife
|
27
|
+
include Chef::Knife::XapiBase
|
28
|
+
|
29
|
+
banner "knife xapi guest stop"
|
30
|
+
|
31
|
+
include Chef::Knife::XapiVmSelect
|
32
|
+
|
33
|
+
def run
|
34
|
+
vm = select_vm(@name_args[0])
|
35
|
+
|
36
|
+
if vm.is_a? Array
|
37
|
+
vm.each { |vm| stop(vm) }
|
38
|
+
else
|
39
|
+
stop(vm)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
class Chef::Knife
|
3
|
+
module XapiVmSelect
|
4
|
+
|
5
|
+
def self.included(includer)
|
6
|
+
includer.class_eval do
|
7
|
+
option :uuid,
|
8
|
+
:short => "-U",
|
9
|
+
:long => "--uuid",
|
10
|
+
:description => "Treat the label as a UUID not a name label"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def select_vm(name)
|
15
|
+
if name.nil?
|
16
|
+
ui.msg "Must Provide VM Name"
|
17
|
+
ui.msg "Usage: " + banner
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
vms = []
|
22
|
+
if config[:uuid]
|
23
|
+
vms << xapi.VM.get_by_uuid(name).flatten
|
24
|
+
else
|
25
|
+
vms << xapi.VM.get_by_name_label(name).flatten
|
26
|
+
end
|
27
|
+
vms.flatten!
|
28
|
+
|
29
|
+
if vms.empty?
|
30
|
+
ui.msg ui.color "could not find vm named #{name}", :red
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
if vms.length > 1
|
35
|
+
vm = user_select(vms)
|
36
|
+
if vm == :all
|
37
|
+
return vms
|
38
|
+
end
|
39
|
+
else
|
40
|
+
vm = vms.first
|
41
|
+
end
|
42
|
+
vm
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/knife-xapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-xapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0.rc3
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jesse Nelson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -71,11 +71,14 @@ files:
|
|
71
71
|
- lib/chef/knife/xapi_guest_create.rb
|
72
72
|
- lib/chef/knife/xapi_guest_delete.rb
|
73
73
|
- lib/chef/knife/xapi_guest_list.rb
|
74
|
+
- lib/chef/knife/xapi_guest_start.rb
|
75
|
+
- lib/chef/knife/xapi_guest_stop.rb
|
74
76
|
- lib/chef/knife/xapi_vdi_attach.rb
|
75
77
|
- lib/chef/knife/xapi_vdi_create.rb
|
76
78
|
- lib/chef/knife/xapi_vdi_delete.rb
|
77
79
|
- lib/chef/knife/xapi_vdi_detach.rb
|
78
80
|
- lib/chef/knife/xapi_vdi_list.rb
|
81
|
+
- lib/chef/knife/xapi_vmselect.rb
|
79
82
|
- lib/knife-xapi/version.rb
|
80
83
|
- lib/xenapi/README
|
81
84
|
- lib/xenapi/xen_api.rb
|
@@ -100,12 +103,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
104
|
none: false
|
102
105
|
requirements:
|
103
|
-
- - ! '
|
106
|
+
- - ! '>'
|
104
107
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
108
|
+
version: 1.3.1
|
106
109
|
requirements: []
|
107
110
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.23
|
109
112
|
signing_key:
|
110
113
|
specification_version: 3
|
111
114
|
summary: Xen API Support for Chef's Knife Command
|