Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

connect nic to a different netork #58

Open
pkirklewski opened this issue Sep 11, 2012 · 8 comments
Open

connect nic to a different netork #58

pkirklewski opened this issue Sep 11, 2012 · 8 comments

Comments

@pkirklewski
Copy link

Hi there,
Do I really need to remove a NIC in order to be able to connect it to a different network ?

device.add_net /xyz/networks/DevPoolX works fine but I would like to have the ability to change the NICs network without removing it.

Warmest regards,
Peter

@pkirklewski
Copy link
Author

Bump

@rkeene
Copy link

rkeene commented Dec 21, 2013

Patch

diff -uNr rvc-1.7.0/lib/rvc/modules/device.rb rvc-1.7.0-1updatenet/lib/rvc/modules/device.rb
--- rvc-1.7.0/lib/rvc/modules/device.rb 2013-12-21 12:55:40.506485026 -0500
+++ rvc-1.7.0-1updatenet/lib/rvc/modules/device.rb  2013-12-20 18:41:55.298777340 -0500
@@ -102,6 +102,37 @@
   )
 end

+opts :update_net do
+  summary "Update a network adapter"
+  arg :vm, nil, :lookup => VIM::VirtualMachine
+  arg :network, nil, :lookup => VIM::Network
+  arg :device, nil, :lookup => VIM::VirtualDevice
+end
+
+def update_net vm, network, device
+  device = device.dup
+
+  case network
+  when VIM::DistributedVirtualPortgroup
+    switch, pg_key = network.collect 'config.distributedVirtualSwitch', 'key'
+    port = VIM.DistributedVirtualSwitchPortConnection(
+      :switchUuid => switch.uuid,
+      :portgroupKey => pg_key)
+    summary = network.name
+    backing = VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(:port => port)
+  when VIM::Network
+    summary = network.name
+    backing = VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => network.name)
+  else fail
+  end
+
+  device.deviceInfo.summary = summary
+  device.backing = backing
+
+  _update_device vm, nil, device
+end
+
+
 opts :add_disk do
   summary "Add a hard drive to a virtual machine"
   arg :vm, nil, :lookup => VIM::VirtualMachine
@@ -272,6 +303,19 @@
   end
 end

+def _update_device vm, fileOp, dev
+  spec = {
+    :deviceChange => [
+      { :operation => :edit, :fileOperation => fileOp, :device => dev },
+    ]
+  }
+  task = vm.ReconfigVM_Task(:spec => spec)
+  result = progress([task])[task]
+  if result == nil
+    puts "Updated device #{dev.name}"
+  end
+end
+
 def change_devices_connectivity devs, connected
   if dev = devs.find { |dev| dev.connectable.nil? }
     err "#{dev.name} is not connectable."

@cdickmann
Copy link
Contributor

There is a command now called device.reconfig_net. Does that address the use case?

@rkeene
Copy link

rkeene commented Dec 22, 2013

The latest version of RVC that runs (1.7.0) does not have this command

@cdickmann
Copy link
Contributor

1.8 was released a few days ago.

@rkeene
Copy link

rkeene commented Dec 23, 2013

Version 1.8 has hundreds of syntax errors and does not run.

@cdickmann
Copy link
Contributor

Did you upgrade to rbvmomi 1.8.1? What errors are you getting?
On Dec 23, 2013 9:11 PM, "rkeene" [email protected] wrote:

Version 1.8 has hundreds of syntax errors and does not run.


Reply to this email directly or view it on GitHubhttps://github.com//issues/58#issuecomment-31141170
.

@rkeene
Copy link

rkeene commented Dec 23, 2013

Installed Ruby gems:

$ gem list

*** LOCAL GEMS ***

backports (3.3.5)
builder (3.2.2)
highline (1.6.20)
mini_portile (0.5.2)
nokogiri (1.5.9)
rbvmomi (1.8.1)
rvc (1.8.0)
terminal-table (1.4.5)
trollop (2.0)
zip (2.0.2)

First syntax error:

$ rvc
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/util.rb:78: warning: don't put space before argument parentheses
Install the "ffi" gem for better tab completion.
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/syslog.rb:103:in `load_code': compile error (SyntaxError)
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/syslog.rb:57: syntax error, unexpected ')'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:104:in `load_module_dir'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:92:in `foreach'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:92:in `load_module_dir'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:228:in `reload_modules'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:227:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:227:in `reload_modules'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/bin/rvc:63
    from /usr/bin/rvc:19:in `load'
    from /usr/bin/rvc:19

Relevant section of code:

 54   hosts_props = pc.collectMultiple(hosts,
 55     'name',
 56     'runtime.connectionState',
 57   )

Syntax error is a dangling "," on line 56, if we remove that we get further, to the next set of syntax errors:

$ rvc
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/util.rb:78: warning: don't put space before argument parentheses
Install the "ffi" gem for better tab completion.
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:719:in `load_code': compile error (SyntaxError)
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:657: syntax error, unexpected ')'
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:696: syntax error, unexpected ':', expecting ')'
    changeMode: 'modify',
               ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:696: syntax error, unexpected ',', expecting kEND
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:698: syntax error, unexpected ':', expecting ')'
      portgroup: [
                ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:700: syntax error, unexpected ':', expecting ')'
          changeOperation: 'remove',
                          ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:700: syntax error, unexpected ',', expecting kEND
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:702: syntax error, unexpected ')', expecting kEND
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:706: syntax error, unexpected ':', expecting ')'
          changeOperation: 'edit',
                          ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:706: syntax error, unexpected ',', expecting kEND
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:708: syntax error, unexpected ':', expecting '='
          portgroup: src_pg.spec.name,
                    ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:709: syntax error, unexpected ':', expecting '='
          spec: VIM::HostVirtualNicSpec(
               ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:710: syntax error, unexpected ':', expecting ')'
...       distributedVirtualPort: VIM::DistributedVirtualSwitch...
                              ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:711: syntax error, unexpected ':', expecting ')'
              portgroupKey: portgroup.key,
                           ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:712: syntax error, unexpected ':', expecting '='
              switchUuid: portgroup.config.distributedV...
                         ^
/usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/modules/vds.rb:713: syntax error, unexpected ')', expecting kEND
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:104:in `load_module_dir'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:92:in `foreach'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/namespace.rb:92:in `load_module_dir'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:228:in `reload_modules'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:227:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/lib/rvc/shell.rb:227:in `reload_modules'
    from /usr/lib/ruby/gems/1.8/gems/rvc-1.8.0/bin/rvc:63
    from /usr/bin/rvc:19:in `load'
    from /usr/bin/rvc:19

And this keeps going for a while. RVC 1.8.0 does not run.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants