knife-vsphere 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,7 +38,7 @@ class Chef
38
38
  :description => "The password for vsphere"
39
39
 
40
40
  option :vsphere_host,
41
- :long => "--vshost",
41
+ :long => "--vshost HOST",
42
42
  :description => "The vsphere host"
43
43
 
44
44
  option :vsphere_dc,
@@ -167,7 +167,6 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
167
167
  show_usage
168
168
  fatal_exit("You must specify a virtual machine name")
169
169
  end
170
- config[:fqdn] = vmname unless config[:fqdn]
171
170
  config[:chef_node_name] = vmname unless config[:chef_node_name]
172
171
  config[:vmname] = vmname
173
172
 
@@ -204,6 +203,8 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
204
203
  end
205
204
 
206
205
  if get_config(:bootstrap)
206
+ sleep 2 until vm.guest.ipAddress
207
+ config[:fqdn] = vm.guest.ipAddress unless config[:fqdn]
207
208
  print "Waiting for sshd..."
208
209
  print "." until tcp_test_ssh(config[:fqdn])
209
210
  puts "done"
@@ -0,0 +1,68 @@
1
+
2
+ # Author:: Ian Delahorne (<ian@delahorne.com>)
3
+ # License:: Apache License, Version 2.0
4
+
5
+ require 'chef/knife'
6
+ require 'chef/knife/BaseVsphereCommand'
7
+ require 'rbvmomi'
8
+ require 'netaddr'
9
+
10
+ class Chef::Knife::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
11
+ banner "knife vsphere vm execute VMNAME COMMAND ARGS"
12
+
13
+ option :exec_user,
14
+ :long => "--exec-user USER",
15
+ :description => "User to execute as",
16
+ :required => true
17
+
18
+ option :exec_passwd,
19
+ :long => "--exec-passwd PASSWORD",
20
+ :description => "Password for execute user",
21
+ :required => true
22
+
23
+ option :exec_dir,
24
+ :long => "--exec-dir DIRECTORY",
25
+ :description => "Working directory to execute in"
26
+
27
+ get_common_options
28
+
29
+ def run
30
+ $stdout.sync = true
31
+ vmname = @name_args[0]
32
+ if vmname.nil?
33
+ show_usage
34
+ fatal_exit("You must specify a virtual machine name")
35
+ end
36
+ command = @name_args[1]
37
+ if command.nil?
38
+ show_usage
39
+ fatal_exit("You must specify a command to execute")
40
+ end
41
+
42
+ args = @name_args[2]
43
+ if args.nil?
44
+ args = ""
45
+ end
46
+
47
+ vim = get_vim_connection
48
+
49
+ dcname = get_config(:vsphere_dc)
50
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
51
+ folder = find_folder(get_config(:folder)) || dc.vmFolder
52
+
53
+ vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
54
+ abort "VM #{vmname} not found"
55
+
56
+ gom = vim.serviceContent.guestOperationsManager
57
+
58
+ guest_auth = RbVmomi::VIM::NamePasswordAuthentication(:interactiveSession => false,
59
+ :username => config[:exec_user],
60
+ :password => config[:exec_passwd])
61
+ prog_spec = RbVmomi::VIM::GuestProgramSpec(:programPath => command,
62
+ :arguments => args,
63
+ :workingDirectory => get_config(:exec_dir))
64
+
65
+ gom.processManager.StartProgramInGuest(:vm => vm, :auth => guest_auth, :spec => prog_spec)
66
+
67
+ end
68
+ end
@@ -1,4 +1,4 @@
1
1
  module KnifeVsphere
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-14 00:00:00.000000000 -05:00
12
+ date: 2012-10-18 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: netaddr
17
- requirement: &70275405040840 !ruby/object:Gem::Requirement
17
+ requirement: &70142499693560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70275405040840
25
+ version_requirements: *70142499693560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: chef
28
- requirement: &70275405038940 !ruby/object:Gem::Requirement
28
+ requirement: &70142499693040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.10.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70275405038940
36
+ version_requirements: *70142499693040
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rbvmomi
39
- requirement: &70275405038180 !ruby/object:Gem::Requirement
39
+ requirement: &70142499692440 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.5.1
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70275405038180
47
+ version_requirements: *70142499692440
48
48
  description: VMware vSphere Support for Chef's Knife Command
49
49
  email: ezra@cpan.org
50
50
  executables: []
@@ -59,6 +59,7 @@ files:
59
59
  - lib/chef/knife/vsphere_vlan_list.rb
60
60
  - lib/chef/knife/vsphere_vm_clone.rb
61
61
  - lib/chef/knife/vsphere_vm_delete.rb
62
+ - lib/chef/knife/vsphere_vm_execute.rb
62
63
  - lib/chef/knife/vsphere_vm_list.rb
63
64
  - lib/chef/knife/vsphere_vm_state.rb
64
65
  - lib/knife-vsphere/version.rb