VMware {code} Community
StephenEngle
Contributor
Contributor

Expanding a VMDK File via API

I note that Virtual Center 2.5 allows you to increase the size of a VMDK file on a powered down VM. Does anyone know of a way to do this with an API call?

0 Kudos
9 Replies
akutz
Hot Shot
Hot Shot

StephenEngle
Contributor
Contributor

Thanks! That's just about what I needed, though I think ExtendVirtualDisk_Task is what I'm looking for in this case.

Unfortunately, this brings me to my next question. I'm not terribly familiar with Perl though I'm learning as I go. How do I create an instance of the VirtualDiskManager object?

0 Kudos
akutz
Hot Shot
Hot Shot

VirtualDiskManager is a member of ServiceContent. To access it in Perl this code should work.

my $o_vim_svc = Vim::get_vim_service();

my $o_vim_svc_content = Vim::get_service_content();

my $o_vdiskmgr = $o_vim_svc_content->virtualDiskManager;

StephenEngle
Contributor
Contributor

I gave it a whirl. Accoring to your code and the documentation, it should work fine. Unfortunately, it does not. I learned how to use the dumper in Perl and come to find out that the object that should be under the service content is evidently not there (VirtualDiskManager). All of the other properties appear to be in the object, but not that one. I guess I'll have to see if VMWare has a patch for this or something (I verified that I had the current download according to VMWare's download pages).

Thanks for all your help though. It's been a good learning experience (though frustrating).

Message was edited by: StephenEngle

0 Kudos
akutz
Hot Shot
Hot Shot

The VirtualDiskManager is only available if you have upgraded to ESX 3.5 and VC 2.5.

0 Kudos
StephenEngle
Contributor
Contributor

I'm on ESX3.5 and VC2.5. I don't know why it isn't showing. We did a clean load of VC2.5 and ESX3.5. Maybe VMWare will shed some light on it for me, but if you have any other ideas I can check, I'd sure appreciate it.

Thanks.

0 Kudos
stumpr
Virtuoso
Virtuoso

I'm not getting a managed object reference to the virtualDiskManager as well. Fresh install of VC 2.5/3.5.0u1 here as well.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
akutz
Hot Shot
Hot Shot

Okay, I've got it working. I'll post the code and then reveal the (stupid) secret:

---

#!/usr/bin/perl -w

use strict;

use warnings;

use FindBin;

use lib "$FindBin::Bin/../";

use VMware::VIRuntime;

use AppUtil::VMUtil;

$SIG=sub;

$Util::script_version = "1.0";

my %opts = (

);

Opts::add_options(%opts);

Opts::parse();

Opts::validate();

Util::connect();

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;

my $m_o_view_vdiskmgr = Vim::get_view( mo_ref => $m_o_vdiskmgr, type => "VirtualDiskManager" );

print Dumper $m_o_view_vdiskmgr;

Util::disconnect();

---

This prints out:

---

akutz@amends:general$ ./test.pl --server 192.168.0.40 --username root --password 'HAHA'

$VAR1 = bless( {

'mo_ref' => bless( {

'value' => 'ha-vdiskmanager',

'type' => 'VirtualDiskManager'

}, 'ManagedObjectReference' ),

'vim' => bless( {

'service_url' => 'https://192.168.0.40/sdk/webService',

'vim_service' => bless( {

'vim_soap' => bless( {

'user_agent' => bless( {

'max_redirect' => 7,

'protocols_forbidden' => undef,

'no_proxy' => [],

'protocols_allowed' => [

'http',

'https'

],

'use_eval' => 1,

'requests_redirectable' => [

'GET',

'HEAD'

],

'from' => undef,

'timeout' => 180,

'agent' => 'libwww-perl/5.805',

'cookie_jar' => bless( {

'ignore_discard' => 1,

'COOKIES' => {

'192.168.0.40' => {

'/' => {

'vmware_soap_session' => [

0,

'"523be872-8f56-f7ad-6c32-e750064fd1e0"',

undef,

1,

undef,

undef,

1

]

}

}

}

}, 'HTTP::Cookies' ),

'def_headers' => undef,

'parse_head' => 1,

'proxy' => {},

'max_size' => undef

}, 'LWP::UserAgent' ),

'url' => 'https://192.168.0.40/sdk/webService'

}, 'SoapClient' )

}, 'VimService' ),

'service_content' => bless( {

'accountManager' => bless( {

'value' => 'ha-localacctmgr',

'type' => 'HostLocalAccountManager'

}, 'ManagedObjectReference' ),

'fileManager' => bless( {

'value' => 'ha-nfc-file-manager',

'type' => 'FileManager'

}, 'ManagedObjectReference' ),

'eventManager' => bless( {

'value' => 'ha-eventmgr',

'type' => 'EventManager'

}, 'ManagedObjectReference' ),

'rootFolder' => bless( {

'value' => 'ha-folder-root',

'type' => 'Folder'

}, 'ManagedObjectReference' ),

'perfManager' => bless( {

'value' => 'ha-perfmgr',

'type' => 'PerformanceManager'

}, 'ManagedObjectReference' ),

'diagnosticManager' => bless( {

'value' => 'ha-diagnosticmgr',

'type' => 'DiagnosticManager'

}, 'ManagedObjectReference' ),

'setting' => bless( {

'value' => 'HostAgentSettings',

'type' => 'OptionManager'

}, 'ManagedObjectReference' ),

'searchIndex' => bless( {

'value' => 'ha-searchindex',

'type' => 'SearchIndex'

}, 'ManagedObjectReference' ),

'sessionManager' => bless( {

'value' => 'ha-sessionmgr',

'type' => 'SessionManager'

}, 'ManagedObjectReference' ),

'viewManager' => bless( {

'value' => 'ViewManager',

'type' => 'ViewManager'

}, 'ManagedObjectReference' ),

'licenseManager' => bless( {

'value' => 'ha-license-manager',

'type' => 'LicenseManager'

}, 'ManagedObjectReference' ),

'propertyCollector' => bless( {

'value' => 'ha-property-collector',

'type' => 'PropertyCollector'

}, 'ManagedObjectReference' ),

'authorizationManager' => bless( {

'value' => 'ha-authmgr',

'type' => 'AuthorizationManager'

}, 'ManagedObjectReference' ),

'taskManager' => bless( {

'value' => 'ha-taskmgr',

'type' => 'TaskManager'

}, 'ManagedObjectReference' ),

'about' => bless( {

'fullName' => 'VMware ESX Server 3.5.0 build-64607',

'version' => '3.5.0',

'apiVersion' => '2.5.0',

'name' => 'VMware ESX Server',

'localeBuild' => '000',

'build' => '64607',

'localeVersion' => 'INTL',

'apiType' => 'HostAgent',

'osType' => 'vmnix-x86',

'productLineId' => 'esx',

'vendor' => 'VMware, Inc.'

}, 'AboutInfo' ),

'virtualDiskManager' => $VAR1->{'mo_ref'},

'userDirectory' => bless( {

'value' => 'ha-user-directory',

'type' => 'UserDirectory'

}, 'ManagedObjectReference' )

}, 'ServiceContent' )

}, 'Vim' )

}, 'VirtualDiskManager' );

---

The secret is ... wait for it ... you apparently cannot run this code against the VC server. It comes back with UNDEF when you try to get a reference to the virtual disk manager. However, it works fine directly against the ESX servers. I think we just found a bug! Or if not a bug, certainly a caveat that should be clearly documented in the SDK reference pages at VirtualDiskManager.

0 Kudos
stumpr
Virtuoso
Virtuoso

Great find! I agree with you, sounds like a bug but at least you found the work around.

I may actually need this soon for large relocation of my vmdks, so this will play a role with shrink being reintroduced in the tools.

Thanks, akutz.

r.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos