From 1ae0427d4e8f2d0a3f18b33a191fc407fdc0757c Mon Sep 17 00:00:00 2001 From: Chrrrles Paul Date: Tue, 1 Sep 2015 10:55:10 -0500 Subject: [PATCH] Revert "Add 2.0 docs - Revert "add virtual floppy to VMware guest"" --- .../modules/cloud/vmware/vsphere_guest.py | 68 ++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vsphere_guest.py b/lib/ansible/modules/cloud/vmware/vsphere_guest.py index c04df7f1c76..82a1cbd7d47 100644 --- a/lib/ansible/modules/cloud/vmware/vsphere_guest.py +++ b/lib/ansible/modules/cloud/vmware/vsphere_guest.py @@ -184,9 +184,12 @@ EXAMPLES = ''' num_cpus: 2 osid: centos64Guest scsi: paravirtual - vm_cdrom: - type: "iso" - iso_path: "DatastoreName/cd-image.iso" + vm_cdrom: + type: "iso" + iso_path: "DatastoreName/cd-image.iso" + vm_floppy: + type: "image" + image_path: "DatastoreName/floppy-image.flp" esxi: datacenter: MyDatacenter hostname: esx001.mydomain.local @@ -379,6 +382,44 @@ def add_cdrom(module, s, config_target, config, devices, default_devs, type="cli devices.append(cd_spec) +def add_floppy(module, s, config_target, config, devices, default_devs, type="image", vm_floppy_image_path=None): + # Add a floppy + # Make sure the datastore exists. + if vm_floppy_image_path: + image_location = vm_floppy_image_path.split('/', 1) + datastore, ds = find_datastore( + module, s, image_location[0], config_target) + image_path = image_location[1] + + floppy_spec = config.new_deviceChange() + floppy_spec.set_element_operation('add') + floppy_ctrl = VI.ns0.VirtualFloppy_Def("floppy_ctrl").pyclass() + + if type == "image": + image = VI.ns0.VirtualFloppyImageBackingInfo_Def("image").pyclass() + ds_ref = image.new_datastore(ds) + ds_ref.set_attribute_type(ds.get_attribute_type()) + image.set_element_datastore(ds_ref) + image.set_element_fileName("%s %s" % (datastore, image_path)) + floppy_ctrl.set_element_backing(image) + floppy_ctrl.set_element_key(3) + floppy_spec.set_element_device(floppy_ctrl) + elif type == "client": + client = VI.ns0.VirtualFloppyRemoteDeviceBackingInfo_Def( + "client").pyclass() + client.set_element_deviceName("/dev/fd0") + floppy_ctrl.set_element_backing(client) + floppy_ctrl.set_element_key(3) + floppy_spec.set_element_device(floppy_ctrl) + else: + s.disconnect() + module.fail_json( + msg="Error adding floppy of type %s to vm spec. " + " floppy type can either be image or client" % (type)) + + devices.append(floppy_spec) + + def add_nic(module, s, nfmor, config, devices, nic_type="vmxnet3", network_name="VM Network", network_type="standard"): # add a NIC # Different network card types are: "VirtualE1000", @@ -954,6 +995,27 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest, # Add a CD-ROM device to the VM. add_cdrom(module, vsphere_client, config_target, config, devices, default_devs, cdrom_type, cdrom_iso_path) + if 'vm_floppy' in vm_hardware: + floppy_image_path = None + floppy_type = None + try: + floppy_type = vm_hardware['vm_floppy']['type'] + except KeyError: + vsphere_client.disconnect() + module.fail_json( + msg="Error on %s definition. floppy type needs to be" + " specified." % vm_hardware['vm_floppy']) + if floppy_type == 'image': + try: + floppy_image_path = vm_hardware['vm_floppy']['image_path'] + except KeyError: + vsphere_client.disconnect() + module.fail_json( + msg="Error on %s definition. floppy image_path needs" + " to be specified." % vm_hardware['vm_floppy']) + # Add a floppy to the VM. + add_floppy(module, vsphere_client, config_target, config, devices, + default_devs, floppy_type, floppy_image_path) if vm_nic: for nic in sorted(vm_nic.iterkeys()): try: