...
- name: pyvss1 pyvss2
- source_template: Uuid Moref or UUId of the template
- built process: template
- billing department: VSS
- description: virtual machine deployed from vss
- usage: Testing
- networks: any available network in your account
- folder: any folder available in your account
...
Import VssManager and Create a VssManager instance:
Code Block from pyvss.manager import VssManager vss = VssManager()
Refer to the official docs or use the help built in function to display what parameters are required by the deploy_vms_from_template function:
Code Block help(vss.deploy_vms_from_template)
Get source template Moref or Uuid, target folder, networks to mount for the installation
Code Block source_templatetemplates = vss.get_templates(namefilter="ubuntuname,like,%ubuntu-16.04_x64x64%") source_template = source_templatetemplates[0]['uuidmoref'] networks = vss.get_networks(namefilter='1102name,like,%1102%') # filtering by name networks = [{'network': net.get('moref')} for net in networks] folders = vss.get_folders(namefilter='APIDemoname,like,%APIDemo%') # filtering by name folder = folders[0].get('moref') description = 'virtual machine deployed from vss'
Create custom specifications for each network interface and for the whole virtual machines:
Warning New custom specification has been introduced in version v0.9.3 which supports customizing multiple Network Interfaces on resulting virtual machines.
Code Block # custom specification for each interface in a list pyvss1_cspec_interfaces = [vss.get_custom_spec_interface(dhcp=False, ip='128.100.102.226', mask='255.255.255.0', gateway=['128.100.102.224'])] # custom specification for the VM pyvss1_cspec = vss.get_custom_spec(hostname='pyvss1', domain='eis.utoronto.ca', dns=['128.100.102.1', '128.100.20.3'], interfaces=pyvss1_cspec_interfaces) # custom specification for each interface in a list pyvss2_cspec_interfaces = [vss.get_custom_spec_interface(dhcp=False, ip='128.100.102.227', mask='255.255.255.0', gateway=['128.100.102.224'])] pyvss2_cspec = vss.get_custom_spec(hostname='pyvss2', domain='eis.utoronto.ca', dns=['128.100.102.1', '128.100.20.3'], interfaces=pyvss2_cspec_interfaces)
Submit New VM requests
Code Block pyvss1 = vss.deploy_vms_from_template(source_template=source_template, description=description, count=1, name='pyvss1', custom_spec=pyvss1_cspec, networks=networks, folder=folder, power_on=True) pyvss2 = vss.deploy_vms_from_template(source_template=source_template, description=description, count=1, name='pyvss2', custom_spec=pyvss2_cspec, networks=networks, folder=folder, power_on=True)
Wait until VM is deployed:
Code Block pyvss1_uuidid = vss.wait_for_request(pyvss1.get('_links').get('requests')[0], 'vm_uuidmoref', 'Processed') pyvss2_uuidid = vss.wait_for_request(pyvss2.get('_links').get('requests')[0], 'vm_uuidmoref', 'Processed')
Once you get the both UUIDs, power on the VMS
Code Block for uuid in [pyvss1_uuid, pyvss2_uuid]: vss.power_on_vm(uuid)
Validate new VM state:
Code Block for uuidvm_id in [pyvss1_uuidid, pyvss2_uuidid]: print(vss.get_vm_state(uuidvm_id).get('powerStatepower_state'))
Obtain guest operating system IP addresses or ping target ip addresses:
Code Block for uuidvm_id in [pyvss1_uuidid, pyvss2_uuidid]: print( vss.get_vm_guest_ip(uuidvm_id)[0].get('ipAddressip_address'))
Code Block ping 128.100.102.226 PING 128.100.102.226 (128.100.102.226): 56 data bytes 64 bytes from 128.100.102.226: icmp_seq=0 ttl=64 time=0.519 ms 64 bytes from 128.100.102.226: icmp_seq=1 ttl=64 time=0.364 ms ping 128.100.102.227 PING 128.100.102.227 (128.100.102.227): 56 data bytes 64 bytes from 128.100.102.227: icmp_seq=0 ttl=64 time=0.617 ms 64 bytes from 128.100.102.227: icmp_seq=1 ttl=64 time=0.455 ms
Launch a one time virtual machine console to confirm hostname changed:vSphere client link and access the VMs console.
Code Block for uuidvm_id in [pyvss1_uuidid, pyvss2_uuidid]: print(vss.get_vm_vsphere_consolelink(uuidvm_id))
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...