Quantcast
Channel: VMware Communities : Unanswered Discussions - vSphere™ vNetwork
Viewing all articles
Browse latest Browse all 1365

How to use pysphere to edit NIC( VirtualE1000 ) to toggle between plugged and unplugged state

$
0
0

What I am trying to accomplish is to connect to an existing VMware VM and then access the virtual eth connections. Once a particular NIC is found, I want to toggle its state from UNPLUGGED to PLUGGED and vice versa.

To accomplish that I use the following code to create a new eth connection to play with:

#Invoke ReconfigVM_Task
request
= VI.ReconfigVM_TaskRequestMsg()
_this
= request.new__this(vm._mor)
_this
.set_attribute_type(vm._mor.get_attribute_type())
request
.set_element__this(_this)
spec
= request.new_spec()

#Add a NIC.
dev_change
= spec.new_deviceChange()
dev_change
.set_element_operation("add")
nic_ctlr
= VI.ns0.VirtualE1000_Def("nic_ctlr").pyclass()
nic_backing
= VI.ns0.VirtualEthernetCardNetworkBackingInfo_Def("nic_backing").pyclass()
nic_backing
.set_element_deviceName(label)
nic_ctlr
.set_element_addressType("generated")
nic_ctlr
.set_element_backing(nic_backing)
nic_ctlr
.set_element_key(4)
dev_change
.set_element_device(nic_ctlr)

spec
.set_element_deviceChange([dev_change])
request
.set_element_spec(spec)
ret
= hostcon._proxy.ReconfigVM_Task(request)._returnval

#Wait for the task to finish
task
=VITask(ret, hostcon)
status
= task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])
if status == task.STATE_SUCCESS:
  
print"VM %s successfully reconfigured"% vm
elif status == task.STATE_ERROR:
  
print"Error reconfiguring vm: %s"% vm, task.get_error_message()


As a result of the above code, I see the following gets created:

eth3  :1Gb/s TP UNPLUGGED|UP  --None--   -NoIPv6-

But now I am stuck at trying to change this UNPLUGGED field. Can this even be changed at the VM level? or this part needs to be changed at virtual switch level? Asking because I found online that the "PLUGGED/UNPLUGGED" information comes from the virtual switch entry? Is that true?


Viewing all articles
Browse latest Browse all 1365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>