Hi Karthik, Yes, you can create the RDM also with the same method, although I have not tried it myself, but it is possible. As far as assigning the vmdk to the VMs you can easily do so using ...
See more...
Hi Karthik, Yes, you can create the RDM also with the same method, although I have not tried it myself, but it is possible. As far as assigning the vmdk to the VMs you can easily do so using the VI Client. You can also use the below sample code snippet for the same to do it programmatically. >.# $vm_view =====> Virtual Machine Managed Object >.# $disk_file ===> Complete path of the vmdk file. like "[datasore-1] diskLibrary/disk.vmdk" >my @device_config_specs = (); >my $devices = $vm_view->config->hardware->device; >foreach my $device (@$devices) { if ($device->deviceInfo->label eq "SCSI Controller 0") { $controller = $device; last; } >} >unless ($controller) { Util::trace(0, "Controller not found.\n"); return; >} >my $disk_backing_info = VirtualDiskFlatVer2BackingInfo->new(diskMode => "persistent" , fileName => $disk_file); >my $disk = VirtualDisk->new(controllerKey => $controller->key, unitNumber => 2, key => -1, backing => $disk_backing_info, capacityInKB => 2048); # capacityInKB doesn't really matter while adding an existing vmdk, but the parameter is required so you need to specify >my $devspec = VirtualDeviceConfigSpec->new(operation => VirtualDeviceConfigSpecOperation->new('add'), device => $disk); >@device_config_specs = (@device_config_specs, $devspec); >my $vmspec = VirtualMachineConfigSpec->new(deviceChange => \@device_config_specs); >eval { $vm_view->ReconfigVM( spec => $vmspec ); Util::trace(0,"\nVirtual machine '" . $vm_view->name . "' is reconfigured successfully.\n"); >}; >if ($@) { Util::trace(0, "\nReconfiguration failed: "); if (ref($@) eq 'SoapFault') { if (ref($@->detail) eq 'TooManyDevices') { Util::trace(0, "\nNumber of virtual devices exceeds " . "the maximum for a given controller.\n"); } elsif (ref($@->detail) eq 'InvalidDeviceSpec') { Util::trace(0, "The Device configuration is not valid\n"); Util::trace(0, "\nFollowing is the detailed error: \n\n$@"); } elsif (ref($@->detail) eq 'FileAlreadyExists') { Util::trace(0, "\nOperation failed because file already exists"); } else { Util::trace(0, "\n" . $@ . "\n"); } } else { Util::trace(0, "\n" . $@ . "\n"); } >} Hope the above helps. ~ Sidharth