VMware {code} Community
Humphry
Contributor
Contributor

issue expanding virtual disk

Hi, I have an issue trying to expand the virtual disk of a VM. First of all, I define the new virtual disk configuration modifying only the disk size:

 
$disk = VirtualDisk->new
(
	key => DEVICE_VDISK_ID,
	capacityInKB => $disksize
);

$disk_vm_dev_conf_spec = VirtualDeviceConfigSpec->new
(
	operation => VirtualDeviceConfigSpecOperation->new('edit'),
	device => $disk
);

Finally, I call ReconfigVM method:

my @vm_devices = ();
push(@vm_devices, $disk_vm_dev_conf_spec);
$vm_config_spec->deviceChange(\@vm_devices);

$$vm_views[0]->ReconfigVM(spec => $vm_config_spec);

But I'm getting this error:

Invalid configuration for device '0'

I don't know which is the invalid configuration, because I'm just trying to change the disk size, keeping the rest of options as they are. Can anybody help me??

Thanks in advance.

Tags (3)
Reply
0 Kudos
6 Replies
lamw
Community Manager
Community Manager

I think you can also use ExtendVirtualDisk_Task() through the VirtualDiskManager MOR

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.VirtualDiskManager.htm...

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Reply
0 Kudos
Humphry
Contributor
Contributor

Thanks for your answer lamw. But I'm having another proble. How can I get the VirtualDiskManager??

I'm using the following code:

my $m_o_vim_svc = Vim::get_vim_service();
my $m_o_vim_svc_content = Vim::get_service_content();
my $m_o_vdiskmgr = $m_o_vim_svc_content->virtualDiskManager;

But the virtualDiskManager is not in the $m_o_vim_svc_content list!!! The value of $m_o_vim_svc_content is

$VAR1 = bless( {
                 'fileManager' => bless( {
                                           'value' => 'FileManager',
                                           'type' => 'FileManager'
                                         }, 'ManagedObjectReference' ),
                 'scheduledTaskManager' => bless( {
                                                    'value' => 'ScheduledTaskManager',
                                                    'type' => 'ScheduledTaskManager'
                                                  }, 'ManagedObjectReference' ),
                 'eventManager' => bless( {
                                            'value' => 'EventManager',
                                            'type' => 'EventManager'
                                          }, 'ManagedObjectReference' ),
                 'rootFolder' => bless( {
                                          'value' => 'group-d1',
                                          'type' => 'Folder'
                                        }, 'ManagedObjectReference' ),
                 'alarmManager' => bless( {
                                            'value' => 'AlarmManager',
                                            'type' => 'AlarmManager'
                                          }, 'ManagedObjectReference' ),
                 'searchIndex' => bless( {
                                           'value' => 'SearchIndex',
                                           'type' => 'SearchIndex'
                                         }, 'ManagedObjectReference' ),
                 'authorizationManager' => bless( {
                                                    'value' => 'AuthorizationManager',
                                                    'type' => 'AuthorizationManager'
                                                  }, 'ManagedObjectReference' ),
                 'taskManager' => bless( {
                                           'value' => 'TaskManager',
                                           'type' => 'TaskManager'
                                         }, 'ManagedObjectReference' ),
                 'about' => bless( {
                                     'fullName' => 'VMware VirtualCenter 2.5.0 build-147633',
                                     'version' => '2.5.0',
                                     'apiVersion' => '2.5u2',
                                     'name' => 'VMware VirtualCenter',
                                     'localeBuild' => '000',
                                     'build' => '147633',
                                     'localeVersion' => 'INTL',
                                     'apiType' => 'VirtualCenter',
                                     'osType' => 'win32-x86',
                                     'productLineId' => 'vpx',
                                     'vendor' => 'VMware, Inc.'
                                   }, 'AboutInfo' ),
                 'customFieldsManager' => bless( {
                                                   'value' => 'CustomFieldsManager',
                                                   'type' => 'CustomFieldsManager'
                                                 }, 'ManagedObjectReference' ),
                 'perfManager' => bless( {
                                           'value' => 'PerfMgr',
                                           'type' => 'PerformanceManager'
                                         }, 'ManagedObjectReference' ),
                 'diagnosticManager' => bless( {
                                                 'value' => 'DiagMgr',
                                                 'type' => 'DiagnosticManager'
                                               }, 'ManagedObjectReference' ),
                 'setting' => bless( {
                                       'value' => 'VpxSettings',
                                       'type' => 'OptionManager'
                                     }, 'ManagedObjectReference' ),
                 'viewManager' => bless( {
                                           'value' => 'ViewManager',
                                           'type' => 'ViewManager'
                                         }, 'ManagedObjectReference' ),
                 'sessionManager' => bless( {
                                              'value' => 'SessionManager',
                                              'type' => 'SessionManager'
                                            }, 'ManagedObjectReference' ),
                 'extensionManager' => bless( {
                                                'value' => 'ExtensionManager',
                                                'type' => 'ExtensionManager'
                                              }, 'ManagedObjectReference' ),
                 'licenseManager' => bless( {
                                              'value' => 'LicenseManager',
                                              'type' => 'LicenseManager'
                                            }, 'ManagedObjectReference' ),
                 'propertyCollector' => bless( {
                                                 'value' => 'propertyCollector',
                                                 'type' => 'PropertyCollector'
                                               }, 'ManagedObjectReference' ),
                 'virtualizationManager' => bless( {
                                                     'value' => 'VirtualizationManager',
                                                     'type' => 'VirtualizationManager'
                                                   }, 'ManagedObjectReference' ),
                 'userDirectory' => bless( {
                                             'value' => 'UserDirectory',
                                             'type' => 'UserDirectory'
                                           }, 'ManagedObjectReference' ),
                 'customizationSpecManager' => bless( {
                                                        'value' => 'CustomizationSpecManager',
                                                        'type' => 'CustomizationSpecManager'
                                                      }, 'ManagedObjectReference' )
               }, 'ServiceContent' );

Reply
0 Kudos
lamw
Community Manager
Community Manager

You'll need to pass in a MOR of a VM that you're looking to expand the disk and get the disk paths to pass into this function

Here is a quick snippet of code from one of my script:

foreach my $vm (@$vm_views) {
#skip if vm is disconnected
next if(!defined($vm->layout));
my $disks = $vm->layout->disk;
my $vdm_mgr = Vim::get_view(mo_ref => Vim::get_service_content()->virtualDiskManager);
    foreach(@$disks) {
    	my $disk_files = $_->diskFile;
		my $disk_string = "";
        foreach(@$disk_files) {
        	eval { $vdm_mgr->QueryVirtualDiskFragmentation(name => $_); };
			if(!$@) {
				my $disk_frag = $vdm_mgr->QueryVirtualDiskFragmentation(name => $_);
				my $disk_geom = $vdm_mgr->QueryVirtualDiskGeometry(name => $_);
				my $disk_uuid = $vdm_mgr->QueryVirtualDiskUuid(name => $_);
				if(!defined($disk_frag)) { $disk_frag = "N/A"; }
					print REPORT_OUTPUT "<tr><td>",$vm->config->name,"</td><td>".$disk_frag."</td><td>".$_."</td><td>".$disk_geom->cylinder."</td><td>".$disk_geom->head."</td><td>".$disk_geom->sector."</td><td>".$disk_uuid."</td>","</tr>\n";
				}
     	    }
     	}
}

Here I'm querying for the disk fragmentation and geometry, but you should get an idea on how to get the VirtualDiskManager. The VI API page also tells which params is required for the function call

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Reply
0 Kudos
Humphry
Contributor
Contributor

Hi, lamw. The problem is that the function Vim::get_service_content() doesn't return a virtualDiskManager, as you can see in my previous message. I'm getting all the managers except the virtualDiskManager. So, do you know what is the problem retrieving the virtualDiskManager?? Do you know any other way to retrieve it??

Reply
0 Kudos
admin
Immortal
Immortal

The virtual disk manager had been introduced since VI API 2.5. If you are running this on a server prior to ESX 3.5, you will not be able to retrieve this managed object.

Reply
0 Kudos
Humphry
Contributor
Contributor

I'm using VMware ESX Server 3i, 3.5.0.

Nevertheless, can I expand the disk in any other way??? Maybe, using ReconfigVm??

Reply
0 Kudos