knife-xapi 0.1.2 → 0.1.3

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.
@@ -21,7 +21,7 @@ Chef::Config[:knife][:xapi_kernel_params] :: Optional Boot paramaters to pass to
21
21
  Chef::Config[:knife][:xapi_bootstrap] :: Not implemented yet, but will be the bootstrap script to execute after guest create
22
22
 
23
23
  ==Usage
24
-
24
+ =Create
25
25
  Basic usage to create a VM from existing VM template:
26
26
  knife xapi guest create "NewBox" "public" --xapi-vm-template "MyBaseBox" --host http://sandbox/
27
27
 
@@ -39,4 +39,20 @@ More verbose example using a kickstart file and booting the Centos 5 default tem
39
39
  Use Knife builtin help schematic for more info
40
40
  knife xapi guest create --help
41
41
 
42
+ =Delete
43
+ Delete is pretty simple. When there are multiple vms with a name label you should be prompted to select one
44
+ knife xapi guest delete testing
45
+
46
+ If you know the UUID of the VM you can specify --uuid
47
+ knife xapi guest delete b461c0d2-d24d-bc02-3231-711101f57b8e --uuid
48
+
49
+ =List
50
+ List shows the vm's on the pool/host Ignoring Controll domains and templates. VM OpaqueRef and UUID are displayed which can be
51
+ knife xapi guest list
52
+ Name Label Ref UUID
53
+ test-server OpaqueRef:82065b80-55ff-63ce-ef89-6b33fb5fd272 9b0a0afa-5573-7875-b787-47fbfa2548a4
54
+ tester OpaqueRef:2d239fbd-bff6-4e60-f675-e1d2530199d2 de760651-2db8-6f81-0783-7b8364f591fd
55
+ test-client OpaqueRef:e4bbd801-c9be-e355-2a22-2ca468a90a81 35156957-45f4-02f8-6de9-6adbcd5e0c6d
56
+ test-client OpaqueRef:f5b562f8-a493-f535-335e-ae70b3177869 f46e4d6b-bd9e-e47b-5f0d-b849ff75c5ef
57
+
42
58
 
@@ -1,6 +1,8 @@
1
1
  # Xapi Base Module
2
2
  #
3
- # Description:: Setup the Session and auth for xapi
3
+ # Description:: Setup the Session and auth for xapi
4
+ # other common methods used for talking with the xapi
5
+ #
4
6
  # Author:: Jesse Nelson <spheromak@gmail.com>
5
7
  #
6
8
  # Copyright:: Copyright (c) 2012, Jesse Nelson
@@ -86,6 +88,7 @@ class Chef::Knife
86
88
  def get_template(template)
87
89
  xapi.VM.get_by_name_label(template).first
88
90
  end
91
+
89
92
  #
90
93
  # find a template matching what the user provided
91
94
  #
@@ -128,7 +131,24 @@ class Chef::Knife
128
131
  end
129
132
  return nil
130
133
  end
131
-
134
+
135
+ # present a list of options for a user to select
136
+ # return the selected item
137
+ def user_select(items)
138
+ choose do |menu|
139
+ menu.index = :number
140
+ menu.prompt = "Please Choose One:"
141
+ menu.select_by = :index_or_name
142
+ items.each do |item|
143
+ menu.choice item.to_sym do |command|
144
+ say "Using: #{command}"
145
+ selected = command.to_s
146
+ end
147
+ end
148
+ menu.choice :exit do exit 1 end
149
+ end
150
+ end
151
+
132
152
  # generate a random mac address
133
153
  def generate_mac
134
154
  ("%02x"%(rand(64)*4|2))+(0..4).inject(""){|s,x|s+":%02x"%rand(256)}
@@ -1,9 +1,6 @@
1
1
  #
2
2
  # Author:: Jesse Nelson (<spheromak@gmail.com>)
3
3
  #
4
- # Based on xapi plugin written by
5
- # Author:: Adam Jacob (<adam@opscode.com>)
6
- #
7
4
  # Copyright:: Copyright (c) 2012 Jesse Nelson
8
5
  #
9
6
  # License:: Apache License, Version 2.0
@@ -0,0 +1,74 @@
1
+ #
2
+ # Author:: Jesse Nelson (<spheromak@gmail.com>)
3
+ #
4
+ # Copyright:: Copyright (c) 2012 Jesse Nelson
5
+ #
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+
22
+ require 'chef/knife/xapi_base'
23
+
24
+ class Chef
25
+ class Knife
26
+ class XapiGuestDelete < Knife
27
+ include Chef::Knife::XapiBase
28
+
29
+ banner "knife xapi guest delete NAME_LABEL (options)"
30
+
31
+ option :uuid,
32
+ :short => "-U",
33
+ :long => "--uuid",
34
+ :description => "Treat the label as a UUID not a name label"
35
+
36
+ def run
37
+ server_name = @name_args[0]
38
+ $stdout.sync = true
39
+ vms = []
40
+ if config[:uuid]
41
+ vms << xapi.VM.get_by_uuid(server_name)
42
+ else
43
+ vms << xapi.VM.get_by_name_label(server_name)
44
+ end
45
+ vms.flatten!
46
+
47
+ if vms.empty?
48
+ ui.msg "VM not found: #{h.color server_name, :red}"
49
+ exit 1
50
+ elsif vms.length > 1
51
+ ui.msg "Multiple VM matches found use guest list if you are unsure"
52
+ vm = user_select(vms)
53
+ else
54
+ vm = vms.first
55
+ end
56
+
57
+ # shutdown and dest
58
+ unless xapi.VM.get_power_state(vm) == "Halted"
59
+ print "Shutting down Guest:"
60
+ task = xapi.Async.VM.hard_shutdown(vm)
61
+ wait_on_task(task)
62
+ print " #{h.color "Done", :green} \n"
63
+ end
64
+
65
+ print "Destroying Guest: #{h.color( server_name, :cyan)} "
66
+ task = xapi.Async.VM.destroy(vm)
67
+ wait_on_task(task)
68
+ print " #{h.color "Done", :green}\n"
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,44 @@
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
+
23
+ class Chef
24
+ class Knife
25
+ class XapiGuestList < Knife
26
+ include Chef::Knife::XapiBase
27
+
28
+ banner "knife xapi guest list"
29
+
30
+ def run
31
+ vms = xapi.VM.get_all
32
+ printf "%-25s %-46s %-36s \n", "Name Label", "Ref", "UUID"
33
+ vms.each do |vm|
34
+ record = xapi.VM.get_record(vm)
35
+ # make sure you can't do bad things to these VM's
36
+ next if record['is_a_template']
37
+ next if record['name_label'] =~ /control domain/i
38
+ printf "%-25s %46s %36s \n", record['name_label'], vm, record['uuid']
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module KnifeXenserver
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-xapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-06 00:00:00.000000000 Z
12
+ date: 2012-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -87,6 +87,8 @@ files:
87
87
  - README.rdoc
88
88
  - lib/chef/knife/xapi_base.rb
89
89
  - lib/chef/knife/xapi_guest_create.rb
90
+ - lib/chef/knife/xapi_guest_delete.rb
91
+ - lib/chef/knife/xapi_guest_list.rb
90
92
  - lib/knife-xapi/version.rb
91
93
  homepage: https://github.com/spheromak/knife-xapi
92
94
  licenses: []