Quantcast
Channel: VMware Communities : Discussion List - vSphere SDK for Perl
Viewing all articles
Browse latest Browse all 1577

Adding a disk using SDRS

$
0
0

Hello,

 

I'm trying to add a disk to a VM using SDRS. Here's my piece of code:

 

    my ($vm, $sp, $controllerKey, $unit, $disksize) = @_

 

    my $disk_backing_info =

      VirtualDiskFlatVer2BackingInfo->new(diskMode => 'persistent', fileName => "");

 

    my $disk_spec = VirtualDisk->new(backing => $disk_backing_info,

                                controllerKey => $controllerKey,

                                key => $unit,

                                unitNumber => $unit,

                                capacityInKB => $disksize);

 

    my $disk_vm_dev_conf_spec = VirtualDeviceConfigSpec->new(device => $disk_spec,

                                   fileOperation => VirtualDeviceConfigSpecFileOperation->new('create'),

                                   operation => VirtualDeviceConfigSpecOperation->new('add'));

 

    my $storageMgr = Vim::get_view(mo_ref => Vim::get_service_content()->storageResourceManager);

    my $podSpec = StorageDrsPodSelectionSpec->new(storagePod => $sp->{mo_ref});

    my $configSpec = VirtualMachineConfigSpec->new(deviceChange => [$disk_vm_dev_conf_spec]);

    my $storageSpec = StoragePlacementSpec->new(type => 'reconfigure', podSelectionSpec => $podSpec, vm => $vm->{mo_ref}, configSpec => $configSpec);

    get_logger->debug("got storageSpec: ".Dumper($storageSpec));

 

    my $result = $storageMgr->RecommendDatastores(storageSpec => $storageSpec);

 

 

In my logfile, dumping the $storageSpec leads to this output:

 

2017/04/06 13:21:52 [DEBUG] XXX::YYY::VMDisks::create_disk_on_storagepod:359 - got storageSpec: $VAR1 = bless( {

                 'vm' => bless( {

                                  'value' => 'vm-236336',

                                  'type' => 'VirtualMachine'

                                }, 'ManagedObjectReference' ),

                 'configSpec' => bless( {

                                          'deviceChange' => [

                                                              bless( {

                                                                       'fileOperation' => bless( {

                                                                                                   'val' => 'create'

                                                                                                 }, 'VirtualDeviceConfigSpecFileOperation' ),

                                                                       'operation' => bless( {

                                                                                               'val' => 'add'

                                                                                             }, 'VirtualDeviceConfigSpecOperation' ),

                                                                       'device' => bless( {

                                                                                            'capacityInKB' => 139264,

                                                                                            'backing' => bless( {

                                                                                                                  'fileName' => '',

                                                                                                                  'diskMode' => 'persistent'

                                                                                                                }, 'VirtualDiskFlatVer2BackingInfo' ),

                                                                                            'unitNumber' => 4,

                                                                                            'controllerKey' => '1000',

                                                                                            'key' => 4

                                                                                          }, 'VirtualDisk' )

                                                                     }, 'VirtualDeviceConfigSpec' )

                                                            ]

                                        }, 'VirtualMachineConfigSpec' ),

                 'podSelectionSpec' => bless( {

                                                'storagePod' => bless( {

                                                                         'value' => 'group-p201254',

                                                                         'type' => 'StoragePod'

                                                                       }, 'ManagedObjectReference' )

                                              }, 'StorageDrsPodSelectionSpec' ),

                 'type' => 'reconfigure'

               }, 'StoragePlacementSpec' );

 

 

Right after that, calling RecommendDatastores throws this error:

 

2017/04/06 13:21:52 [ERROR] XXX::Mojo::Webvm::__ANON__:310 -

SOAP Fault:

-----------

Fault string: A specified parameter was not correct.

StoragePlacementSpec.podSelectionSpec.storagePod

Fault detail: InvalidArgumentFault

 

I don't get what's wrong here and I've tried many different ways of passing the storagePod mo_ref without any success so far. Years ago, the very same problem has been posted here Add VMDK to VM using SDRS recommendation  without getting any response.

 

VMWare SDK for Perl is 6.5.0 (but also tried with 6.0.0 before).

 

Could anyone give me any hint how to call RecommendDatastores correctly?

 

Regards, Andreas


Viewing all articles
Browse latest Browse all 1577

Trending Articles



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