Git Product home page Git Product logo

pyvmomi's People

Contributors

acidgo avatar

pyvmomi's Issues

test

define adapter

adaptermaps = []

guest_map = vim.vm.customization.AdapterMapping()

guest_map.adapter = vim.vm.customization.IPSettings()

guest_map.adapter.ip = vim.vm.customization.FixedIp()

guest_map.adapter.ip.ipAddress = str(setip)

guest_map.adapter.subnetMask = "255.255.255.0"

guest_map.adapter.gateway = "10.10.10.254"

adaptermaps.append(guest_map)

EOF define adapter

ident = vim.vm.customization.LinuxPrep()

ident.hostName = vim.vm.customization.FixedName()

ident.hostName.name = "testname"

globalip = vim.vm.customization.GlobalIPSettings()

relocate_spec = vim.vm.RelocateSpec()
relocate_spec.datastore = ondatastore
relocate_spec.host = onhost
relocate_spec.pool = oncluster.resourcePool

vmconf_spec = vim.vm.ConfigSpec()
vmconf_spec.cpuHotAddEnabled = True
vmconf_spec.memoryHotAddEnabled = True

devices_change = []

customization

custom_spec = vim.vm.customization.Specification()

custom_spec.nicSettingMap = adaptermaps

custom_spec.identity = ident

custom_spec.globalIPSettings = globalip

EOF customization

nic_spec = vim.vm.device.VirtualDeviceSpec()
nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
for dev in target.config.hardware.device:
if isinstance(dev, vim.vm.device.VirtualEthernetCard):
break
else:
raise Exception()

nic_spec.device = dev
nic_spec.device.wakeOnLanEnabled = True
nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic_spec.device.connectable.allowGuestControl = True

========== This!!! ==========

nic_spec.device.connectable.startConnected = True

nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
target_network = get_network_by_name(service_instance, "10.10.10.x")
nic_spec.device.backing.network = target_network
nic_spec.device.backing.deviceName = target_network.name

devices_change.append(nic_spec)
vmconf_spec.deviceChange = devices_change

clone_spec = vim.vm.CloneSpec()

clone_spec.powerOn = False
clone_spec.location = relocate_spec
clone_spec.config = vmconf_spec

clone_spec.customization = custom_spec

task = target.Clone(folder=onfolder, name=setname, spec=clone_spec)

How to enable virtualethernetcard startconected and customization when I am cloning the template with pyvmomi?

For convenience, I recently wrote a set of tools about VMware using pyvmomi.
I want to clone the template and then customize the IP of the cloned virtual machine.
However, it was found that the startconnected could not be enable.
Here is the summary code for this module:

# define adapter
adaptermaps = []
guest_map = vim.vm.customization.AdapterMapping()
guest_map.adapter = vim.vm.customization.IPSettings()
guest_map.adapter.ip = vim.vm.customization.FixedIp()
guest_map.adapter.ip.ipAddress = str(setip)
guest_map.adapter.subnetMask = "255.255.255.0"
guest_map.adapter.gateway = "10.10.10.254"
adaptermaps.append(guest_map)
# EOF define adapter

ident = vim.vm.customization.LinuxPrep()
ident.hostName = vim.vm.customization.FixedName()
ident.hostName.name = "testname"

globalip = vim.vm.customization.GlobalIPSettings()

relocate_spec = vim.vm.RelocateSpec()
relocate_spec.datastore = ondatastore
relocate_spec.host = onhost
relocate_spec.pool = oncluster.resourcePool

vmconf_spec = vim.vm.ConfigSpec()
vmconf_spec.cpuHotAddEnabled = True
vmconf_spec.memoryHotAddEnabled = True

devices_change = []
# customization
custom_spec = vim.vm.customization.Specification()
custom_spec.nicSettingMap = adaptermaps
custom_spec.identity = ident
custom_spec.globalIPSettings = globalip
# EOF customization

nic_spec = vim.vm.device.VirtualDeviceSpec()
nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
for dev in target.config.hardware.device:
    if isinstance(dev, vim.vm.device.VirtualEthernetCard):
        break
else:
    raise Exception()

nic_spec.device = dev
nic_spec.device.wakeOnLanEnabled = True
nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic_spec.device.connectable.allowGuestControl = True
# ========== This!!! ==========
nic_spec.device.connectable.startConnected = True

nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
target_network = get_network_by_name(service_instance, "10.10.10.x")
nic_spec.device.backing.network = target_network
nic_spec.device.backing.deviceName = target_network.name

devices_change.append(nic_spec)
vmconf_spec.deviceChange = devices_change

clone_spec = vim.vm.CloneSpec()

clone_spec.powerOn = False
clone_spec.location = relocate_spec
clone_spec.config = vmconf_spec

clone_spec.customization = custom_spec
task = target.Clone(folder=onfolder, name=setname, spec=clone_spec)

After testing, the startconnected status can be set to enable when I cancel the customization.As shown below.

# define adapter
# adaptermaps = []
# guest_map = vim.vm.customization.AdapterMapping()
# guest_map.adapter = vim.vm.customization.IPSettings()
# guest_map.adapter.ip = vim.vm.customization.FixedIp()
# guest_map.adapter.ip.ipAddress = str(setip)
# guest_map.adapter.subnetMask = "255.255.255.0"
# guest_map.adapter.gateway = "10.10.10.254"
# adaptermaps.append(guest_map)
# EOF define adapter

# ident = vim.vm.customization.LinuxPrep()
# ident.hostName = vim.vm.customization.FixedName()
# ident.hostName.name = "testname"

# globalip = vim.vm.customization.GlobalIPSettings()

relocate_spec = vim.vm.RelocateSpec()
relocate_spec.datastore = ondatastore
relocate_spec.host = onhost
relocate_spec.pool = oncluster.resourcePool

vmconf_spec = vim.vm.ConfigSpec()
vmconf_spec.cpuHotAddEnabled = True
vmconf_spec.memoryHotAddEnabled = True

devices_change = []
# customization
# custom_spec = vim.vm.customization.Specification()
# custom_spec.nicSettingMap = adaptermaps
# custom_spec.identity = ident
# custom_spec.globalIPSettings = globalip
# EOF customization

nic_spec = vim.vm.device.VirtualDeviceSpec()
nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
for dev in target.config.hardware.device:
    if isinstance(dev, vim.vm.device.VirtualEthernetCard):
        break
else:
    raise Exception()

nic_spec.device = dev
nic_spec.device.wakeOnLanEnabled = True
nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic_spec.device.connectable.allowGuestControl = True
# ========== This!!! ==========
nic_spec.device.connectable.startConnected = True

nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
target_network = get_network_by_name(service_instance, "10.10.10.x")
nic_spec.device.backing.network = target_network
nic_spec.device.backing.deviceName = target_network.name

devices_change.append(nic_spec)
vmconf_spec.deviceChange = devices_change

clone_spec = vim.vm.CloneSpec()

clone_spec.powerOn = False
clone_spec.location = relocate_spec
clone_spec.config = vmconf_spec

# clone_spec.customization = custom_spec
task = target.Clone(folder=onfolder, name=setname, spec=clone_spec)

So, how can I enable startconnected during the cloning process instead of performing additional tasks?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.