knife-xapi 0.5.4 → 0.6.0

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.
@@ -8,9 +8,9 @@
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
10
10
  # You may obtain a copy of the License at
11
- #
11
+ #
12
12
  # http://www.apache.org/licenses/LICENSE-2.0
13
- #
13
+ #
14
14
  # Unless required by applicable law or agreed to in writing, software
15
15
  # distributed under the License is distributed on an "AS IS" BASIS,
16
16
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,6 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
-
22
21
  require 'chef/knife/xapi_base'
23
22
 
24
23
  class Chef
@@ -31,29 +30,29 @@ class Chef
31
30
  require 'chef/json_compat'
32
31
  end
33
32
 
34
- banner "knife xapi guest delete NAME_LABEL (options)"
33
+ banner 'knife xapi guest delete NAME_LABEL (options)'
35
34
 
36
35
  option :uuid,
37
- :short => "-U",
38
- :long => "--uuid",
39
- :description => "Treat the label as a UUID not a name label"
36
+ short: '-U',
37
+ long: '--uuid',
38
+ description: 'Treat the label as a UUID not a name label'
40
39
 
41
40
  option :keep_client,
42
- :short => "-C",
43
- :long => "--keep-client",
44
- :description => "Keep client info on the chef-server"
41
+ short: '-C',
42
+ long: '--keep-client',
43
+ description: 'Keep client info on the chef-server'
45
44
 
46
45
  option :keep_node,
47
- :short => "-N",
48
- :long => "--keep-node",
49
- :description => "Keep node info on the chef-server"
46
+ short: '-N',
47
+ long: '--keep-node',
48
+ description: 'Keep node info on the chef-server'
50
49
 
51
- def run
50
+ def run
52
51
  server_name = @name_args[0]
53
52
 
54
53
  if server_name.nil?
55
- puts "Error: No VM Name specified..."
56
- puts "Usage: " + banner
54
+ puts 'Error: No VM Name specified...'
55
+ puts 'Usage: ' + banner
57
56
  exit 1
58
57
  end
59
58
 
@@ -62,28 +61,28 @@ class Chef
62
61
  name = get_name_label(vm)
63
62
  end
64
63
 
65
- vms = []
64
+ vms = []
66
65
  if config[:uuid]
67
66
  vms << xapi.VM.get_by_uuid(server_name)
68
67
  else
69
68
  vms << xapi.VM.get_by_name_label(server_name)
70
69
  end
71
- vms.flatten!
70
+ vms.flatten!
72
71
 
73
- if vms.empty?
74
- puts "VM not found: #{h.color server_name, :red}"
72
+ if vms.empty?
73
+ puts "VM not found: #{h.color server_name, :red}"
75
74
  exit 1
76
75
  elsif vms.length > 1
77
- puts "Multiple VM matches found use guest list if you are unsure"
76
+ puts 'Multiple VM matches found use guest list if you are unsure'
78
77
  vm = user_select(vms)
79
- else
78
+ else
80
79
  vm = vms.first
81
80
  end
82
-
81
+
83
82
  # Cleanup the VM
84
83
  if vm == :all
85
- vms.each {|vm| cleanup(vm) }
86
- else
84
+ vms.each { |vm| cleanup(vm) }
85
+ else
87
86
  cleanup(vm)
88
87
  end
89
88
 
@@ -93,26 +92,25 @@ class Chef
93
92
  unless config[:keep_client]
94
93
  client_list = Chef::ApiClient.list
95
94
 
96
- if client_list.has_key?(name)
95
+ if client_list.key?(name)
97
96
  ui.msg "Removing client #{h.color name, :cyan} from chef"
98
97
  delete_object(Chef::ApiClient, name)
99
98
  else
100
- puts "Client not found on the chef server.. Nothing to delete.."
99
+ puts 'Client not found on the chef server.. Nothing to delete..'
101
100
  end
102
101
  end
103
102
 
104
103
  unless config[:keep_node]
105
104
  env = Chef::Config[:environment]
106
105
  node_list = env ? Chef::Node.list_by_environment(env) : Chef::Node.list
107
- if node_list.has_key?(name)
106
+ if node_list.key?(name)
108
107
  ui.msg "Removing node #{h.color name, :cyan} from chef "
109
108
  delete_object(Chef::Node, name)
110
109
  else
111
- puts "Node not found on the chef server.. Nothing to delete.."
110
+ puts 'Node not found on the chef server.. Nothing to delete..'
112
111
  end
113
112
  end
114
113
  end
115
-
116
114
  end
117
115
  end
118
116
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Jesse Nelson <spheromak@gmail.com>
2
+ # Author:: Jesse Nelson <spheromak@gmail.com>
3
3
  # Author:: Seung-jin/Sam Kim (<seungjin.kim@me.comm>)
4
4
  #
5
5
  # Copyright:: Copyright (c) 2012 Jesse Nelson
@@ -9,9 +9,9 @@
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
11
11
  # You may obtain a copy of the License at
12
- #
12
+ #
13
13
  # http://www.apache.org/licenses/LICENSE-2.0
14
- #
14
+ #
15
15
  # Unless required by applicable law or agreed to in writing, software
16
16
  # distributed under the License is distributed on an "AS IS" BASIS,
17
17
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,36 +25,34 @@ class Chef
25
25
  class XapiGuestList < Knife
26
26
  include Chef::Knife::XapiBase
27
27
 
28
- banner "knife xapi guest list"
29
-
30
- option :id,
31
- :short => "-i",
32
- :long => "--show-id",
33
- :description => "Enable printing of UUID and OpaqueRefs for vm"
28
+ banner 'knife xapi guest list'
34
29
 
30
+ option :id,
31
+ short: '-i',
32
+ long: '--show-id',
33
+ description: 'Enable printing of UUID and OpaqueRefs for vm'
35
34
 
36
35
  def run
37
36
  vms = xapi.VM.get_all
38
37
  if locate_config_value(:id)
39
- printf "%-25s %-12s %-16s %-46s %-36s \n", "Name Label", "State", "IP Address", "Ref", "UUID"
40
- else
41
- printf "%-25s %-12s %-16s\n", "Name Label", "State", "IP Address"
38
+ printf "%-25s %-12s %-16s %-46s %-36s \n", 'Name Label', 'State', 'IP Address', 'Ref', 'UUID'
39
+ else
40
+ printf "%-25s %-12s %-16s\n", 'Name Label', 'State', 'IP Address'
42
41
  end
43
42
 
44
43
  vms.each do |vm|
45
44
  record = xapi.VM.get_record(vm)
46
45
  ip_address = get_guest_ip(vm)
47
46
  # make sure you can't do bad things to these VM's
48
- next if record['is_a_template']
47
+ next if record['is_a_template']
49
48
  next if record['name_label'] =~ /control domain/i
50
49
  if locate_config_value(:id)
51
50
  printf "%-25s %-12s %-16s %46s %36s \n", record['name_label'], record['power_state'], ip_address, vm, record['uuid']
52
- else
51
+ else
53
52
  printf "%-25s %-12s %-16s\n", record['name_label'], record['power_state'], ip_address
54
53
  end
55
54
  end
56
55
  end
57
-
58
56
  end
59
57
  end
60
58
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Jesse Nelson <spheromak@gmail.com>
2
+ # Author:: Jesse Nelson <spheromak@gmail.com>
3
3
  # Author:: Seung-jin/Sam Kim (<seungjin.kim@me.comm>)
4
4
  #
5
5
  # Copyright:: Copyright (c) 2012 Jesse Nelson
@@ -9,9 +9,9 @@
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
11
11
  # You may obtain a copy of the License at
12
- #
12
+ #
13
13
  # http://www.apache.org/licenses/LICENSE-2.0
14
- #
14
+ #
15
15
  # Unless required by applicable law or agreed to in writing, software
16
16
  # distributed under the License is distributed on an "AS IS" BASIS,
17
17
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,8 +26,8 @@ class Chef
26
26
  class XapiGuestStart < Knife
27
27
  include Chef::Knife::XapiBase
28
28
 
29
- banner "knife xapi guest start"
30
-
29
+ banner 'knife xapi guest start'
30
+
31
31
  include Chef::Knife::XapiVmSelect
32
32
 
33
33
  def run
@@ -39,7 +39,6 @@ class Chef
39
39
  start(vm)
40
40
  end
41
41
  end
42
-
43
42
  end
44
43
  end
45
44
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Jesse Nelson <spheromak@gmail.com>
2
+ # Author:: Jesse Nelson <spheromak@gmail.com>
3
3
  # Author:: Seung-jin/Sam Kim (<seungjin.kim@me.comm>)
4
4
  #
5
5
  # Copyright:: Copyright (c) 2012 Jesse Nelson
@@ -9,9 +9,9 @@
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
11
11
  # You may obtain a copy of the License at
12
- #
12
+ #
13
13
  # http://www.apache.org/licenses/LICENSE-2.0
14
- #
14
+ #
15
15
  # Unless required by applicable law or agreed to in writing, software
16
16
  # distributed under the License is distributed on an "AS IS" BASIS,
17
17
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,7 @@ class Chef
26
26
  class XapiGuestStop < Knife
27
27
  include Chef::Knife::XapiBase
28
28
 
29
- banner "knife xapi guest stop"
29
+ banner 'knife xapi guest stop'
30
30
 
31
31
  include Chef::Knife::XapiVmSelect
32
32
 
@@ -38,10 +38,7 @@ class Chef
38
38
  else
39
39
  stop(vm)
40
40
  end
41
-
42
-
43
41
  end
44
-
45
42
  end
46
43
  end
47
44
  end
@@ -8,9 +8,9 @@
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
10
10
  # You may obtain a copy of the License at
11
- #
11
+ #
12
12
  # http://www.apache.org/licenses/LICENSE-2.0
13
- #
13
+ #
14
14
  # Unless required by applicable law or agreed to in writing, software
15
15
  # distributed under the License is distributed on an "AS IS" BASIS,
16
16
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,6 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
-
22
21
  require 'chef/knife/xapi_base'
23
22
  require 'pry'
24
23
  class Chef
@@ -26,19 +25,17 @@ class Chef
26
25
  class XapiNetList < Knife
27
26
  include Chef::Knife::XapiBase
28
27
 
29
- banner "knife xapi net list"
28
+ banner 'knife xapi net list'
30
29
 
31
- def run
32
- xapi.network.get_all_records.each do |k, net|
33
- color_kv "Name: ", net['name_label']
34
- color_kv " Info: ", net['name_description'], [:magenta, :cyan] unless net['name_description'].empty?
35
- color_kv " MTU: ", net['MTU'], [:magenta, :cyan]
36
- color_kv " UUID: ", net['uuid'], [:magenta, :cyan]
37
- ui.msg ""
30
+ def run
31
+ xapi.network.get_all_records.each do |_k, net|
32
+ color_kv 'Name: ', net['name_label']
33
+ color_kv ' Info: ', net['name_description'], [:magenta, :cyan] unless net['name_description'].empty?
34
+ color_kv ' MTU: ', net['MTU'], [:magenta, :cyan]
35
+ color_kv ' UUID: ', net['uuid'], [:magenta, :cyan]
36
+ ui.msg ''
38
37
  end
39
38
  end
40
-
41
39
  end
42
40
  end
43
41
  end
44
-
@@ -18,7 +18,6 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
-
22
21
  require 'chef/knife/xapi_base'
23
22
 
24
23
  class Chef
@@ -26,30 +25,30 @@ class Chef
26
25
  class XapiVdiAttach < Knife
27
26
  include Chef::Knife::XapiBase
28
27
 
29
- banner "knife xapi vdi attach VM_name VDI_name (options)"
28
+ banner 'knife xapi vdi attach VM_name VDI_name (options)'
30
29
 
31
30
  option :uuid,
32
- :short => "-U",
33
- :long => "--uuid",
34
- :description => "Treat the label as a UUID not a name label"
31
+ short: '-U',
32
+ long: '--uuid',
33
+ description: 'Treat the label as a UUID not a name label'
35
34
 
36
35
  option :boot,
37
- :long => "--boot",
38
- :default => false,
39
- :description => "Set the new disk as bootable (default: false)"
40
-
36
+ long: '--boot',
37
+ default: false,
38
+ description: 'Set the new disk as bootable (default: false)'
39
+
41
40
  def run
42
- vm_name = @name_args[0]
41
+ vm_name = @name_args[0]
43
42
  vdi_name = @name_args[1]
44
-
45
- # There is no matchs with VM and VDI's name label
46
- if vm_name.nil? or vdi_name.nil?
47
- ui.msg "Error: No VM Name or VDI Name specified..."
48
- ui.msg "Usage: " + banner
49
- exit 1
50
- end
51
43
 
52
- # Get VM's ref from its name label
44
+ # There is no matchs with VM and VDI's name label
45
+ if vm_name.nil? || vdi_name.nil?
46
+ ui.msg 'Error: No VM Name or VDI Name specified...'
47
+ ui.msg 'Usage: ' + banner
48
+ exit 1
49
+ end
50
+
51
+ # Get VM's ref from its name label
53
52
  vm_ref = xapi.VM.get_by_name_label(vm_name)
54
53
  if vm_ref.empty?
55
54
  ui.msg ui.color "Could not find a vm named #{vm_name}", :red
@@ -57,44 +56,38 @@ class Chef
57
56
  end
58
57
  vm_ref = vm_ref.shift
59
58
 
60
-
61
- # Get VDI's ref from its name label or UUID
62
- vdis = []
59
+ # Get VDI's ref from its name label or UUID
60
+ vdis = []
63
61
  if config[:uuid]
64
62
  vdis << xapi.VDI.get_by_uuid(vdi_name)
65
- else
63
+ else
66
64
  vdis = xapi.VDI.get_by_name_label(vdi_name)
67
65
  end
68
66
 
69
- if vdis.empty?
67
+ if vdis.empty?
70
68
  ui.msg "VDI not found: #{h.color vdi_name, :red}"
71
- exit 1
72
- # When multiple VDI matches
73
- Chef::Log.debug "VDI Length: #{vdis.inspect}\nType:#{vdi.class}"
74
- elsif vdis.length > 1
75
- ui.msg "Multiple VDI matches found use guest list if you are unsure"
76
- vdi_ref = user_select(vdis)
77
- else
78
- vdi_ref = vdis.first
79
- end
80
-
69
+ exit 1
70
+ # When multiple VDI matches
71
+ Chef::Log.debug "VDI Length: #{vdis.inspect}\nType:#{vdi.class}"
72
+ elsif vdis.length > 1
73
+ ui.msg 'Multiple VDI matches found use guest list if you are unsure'
74
+ vdi_ref = user_select(vdis)
75
+ else
76
+ vdi_ref = vdis.first
77
+ end
81
78
 
82
79
  position = xapi.VM.get_VBDs(vm_ref).length
83
80
 
84
81
  # Attach intended VDI to specific VM
85
82
  if vdi_ref == :all
86
83
  vdis.each do |vdi_ref|
87
- create_vbd(vm_ref, vdi_ref, position, config[:boot] )
84
+ create_vbd(vm_ref, vdi_ref, position, config[:boot])
88
85
  position += 1
89
86
  end
90
- else
87
+ else
91
88
  create_vbd(vm_ref, vdi_ref, position, config[:boot])
92
89
  end
93
-
94
- end
90
+ end
95
91
  end
96
92
  end
97
93
  end
98
-
99
-
100
-
@@ -18,7 +18,6 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
-
22
21
  require 'chef/knife/xapi_base'
23
22
 
24
23
  class Chef
@@ -27,31 +26,31 @@ class Chef
27
26
  require 'timeout'
28
27
  include Chef::Knife::XapiBase
29
28
 
30
- banner "knife xapi vdi create NAME (options)"
29
+ banner 'knife xapi vdi create NAME (options)'
31
30
 
32
31
  option :xapi_sr,
33
- :short => "-S Storage repo to provision VM from",
34
- :long => "--xapi-sr",
35
- :proc => Proc.new { |key| Chef::Config[:knife][:xapi_sr] = key },
36
- :description => "The Xen SR to use, If blank will use pool/hypervisor default"
32
+ short: '-S Storage repo to provision VM from',
33
+ long: '--xapi-sr',
34
+ proc: proc { |key| Chef::Config[:knife][:xapi_sr] = key },
35
+ description: 'The Xen SR to use, If blank will use pool/hypervisor default'
37
36
 
38
37
  option :xapi_disk_size,
39
- :short => "-D Size of disk. 1g 512m etc",
40
- :long => "--xapi-disk-size",
41
- :description => "The size of the root disk, use 'm' 'g' 't' if no unit specified assumes g",
42
- :proc => Proc.new { |key| Chef::Config[:knife][:xapi_disk_size] = key.to_s }
38
+ short: '-D Size of disk. 1g 512m etc',
39
+ long: '--xapi-disk-size',
40
+ description: "The size of the root disk, use 'm' 'g' 't' if no unit specified assumes g",
41
+ proc: proc { |key| Chef::Config[:knife][:xapi_disk_size] = key.to_s }
43
42
 
44
43
  def run
45
44
  disk_name = @name_args[0]
46
45
  if disk_name.nil?
47
- puts "Error: No Disk Name specified..."
48
- puts "Usage: " + banner
46
+ puts 'Error: No Disk Name specified...'
47
+ puts 'Usage: ' + banner
49
48
  exit 1
50
49
  end
51
50
 
52
51
  begin
53
52
  if locate_config_value(:xapi_sr)
54
- sr_ref = get_sr_by_name( locate_config_value(:xapi_sr) )
53
+ sr_ref = get_sr_by_name(locate_config_value(:xapi_sr))
55
54
  else
56
55
  sr_ref = find_default_sr
57
56
  end
@@ -61,30 +60,29 @@ class Chef
61
60
  end
62
61
  Chef::Log.debug "SR: #{h.color sr_ref, :cyan}"
63
62
 
64
- size = locate_config_value(:xapi_disk_size)
63
+ size = locate_config_value(:xapi_disk_size)
65
64
 
66
65
  vdi_record = {
67
- "name_label" => disk_name,
68
- "name_description" => "#{disk_name} created by #{ENV['USER']}",
69
- "SR" => sr_ref,
70
- "virtual_size" => input_to_bytes(size).to_s,
71
- "type" => "system",
72
- "sharable" => false,
73
- "read_only" => false,
74
- "other_config" => {},
66
+ 'name_label' => disk_name,
67
+ 'name_description' => "#{disk_name} created by #{ENV['USER']}",
68
+ 'SR' => sr_ref,
69
+ 'virtual_size' => input_to_bytes(size).to_s,
70
+ 'type' => 'system',
71
+ 'sharable' => false,
72
+ 'read_only' => false,
73
+ 'other_config' => {}
75
74
  }
76
75
 
77
76
  # Async create the VDI
78
77
  task = xapi.Async.VDI.create(vdi_record)
79
- ui.msg "waiting for VDI Create.."
78
+ ui.msg 'waiting for VDI Create..'
80
79
  vdi_ref = get_task_ref(task)
81
80
 
82
- ui.msg "Disk Name: #{ h.color( disk_name, :bold, :cyan)}"
83
- ui.msg "Disk Size: #{ h.color( size.to_s, :bold, :cyan)}"
81
+ ui.msg "Disk Name: #{ h.color(disk_name, :bold, :cyan)}"
82
+ ui.msg "Disk Size: #{ h.color(size.to_s, :bold, :cyan)}"
84
83
 
85
84
  end
86
85
  end
87
86
  end
88
87
  end
89
88
  end
90
-