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

Unable to Create Vapp via Perl SDk

$
0
0

my $v_pool = $resrc_pool->CreateVApp(name =>$$var{vname} , resSpec => $rspec , configSpec => $vspec );

 

O/p:

SOAP Fault:

-----------

Fault string: A specified parameter was not correct.

folder

Fault detail: InvalidArgumentFault

 

 

According to the Documentation vmfolder need not be set

vSphere Documentation Center


Error trying to clone a VM to a DataStoreCluser

$
0
0

Hey guys,

 

We are trying to utilize William's script, to clone to the datastorecluster (from here: vGhetto / Code / [r251] /scripts/datastoreClusterVMProvisioning.pl)

However we have an error we cant figure out what causes it:

Cloning "sdktemp1" to "del1000" onto "cl_ds1"

Error:

SOAP Fault:

-----------

Fault string: The operation is not supported on the object.

Fault detail: NotSupported

 

 

This is on vSphere 5.5 and SDK 5.5 as well.

 

One theory the System guy who deals with the VMware infrastructure has, is that it is related to not having the FullyAutomated setting, anywhere in the configuration specifications for the clone.

I have been looking hard into the objects related to the calls in your script, and their API reference, and I cant find any way this setting could be set in the relevant object (it doesnt exist in those objects).

 

 

Any ideas what could this be?

 

Thanks!

Not able to create Server side objects using Perl Sdk

$
0
0

Problem : They are Two scripts

             Script A : Scans for the propertires and stores in a disks

             Script B : loads the file and start's creating the objects ("not able to create objects");

 

If i remove storable perl library or disable any of the function related to the library objects are getting created

 

Code snippet :

     use Storable;

     use VMware::VIRuntime;

     

 

     my $url = "https://".$desip."/sdk/vimService";

 

 

     Util::connect($url , $desur, $despwd);

 

      my $hashref = retrieve('file');

  # Creating a Sample object

     my $cpu = ResourceAllocationInfo->new ();

 

 

 

o/p:

 

 

 

perl storable-error.pl
Undefined subroutine &ResourceAllocationInfo::new called at storable-error.pl line 27.

 

 

 

Even tried DBM:DEEP facing the same issue Could any one help me out with the issue Thank you

Did I find an API bug? : Adding multiple disks soap error

$
0
0

I am able to add the disks linearly like below:

  my $vmSpec = VirtualMachineConfigSpec->new(deviceChange => [$devSpecs[0]]);

  $vmView->ReconfigVM(spec => $vmSpec);

  my $vmSpec = VirtualMachineConfigSpec->new(deviceChange => [$devSpecs[1]]);

  $vmView->ReconfigVM(spec => $vmSpec);

  my $vmSpec = VirtualMachineConfigSpec->new(deviceChange => [$devSpecs[2]]);

  $vmView->ReconfigVM(spec => $vmSpec);

However, when I attempt to add all the disks at once I get a SOAP fault

  my $vmSpec = VirtualMachineConfigSpec->new(deviceChange => \@devSpecs);

  $vmView->ReconfigVM(spec => $vmSpec);

 

The Error:

 

SOAP Fault:

-----------

Fault string: Cannot complete the operation because the file or folder /vmfs/volumes/ba5e81fe-201a6c4e/paul-vm1/paul-vm1_0_3.vmdk already exists

Fault detail: FileAlreadyExistsPAULWORK>clear

 

Is there anyone out there that knows what is going on?

What is causing "toolsNotInstalled"?

$
0
0

I'm using Perl VMware::VIRuntime module to create VMs.

 

VM can be created, but upon "power on", toolsStatus shows "toolsNotInstalled".

 

I'm stuck, not knowing what caused this problem.

 

Advice is appreciated.

NEWBIE: Accessing Certain Pieces of Information -> Disk File

$
0
0

So I'm two days into using the SDK and VMWare in general.

 

I'm looking to pull some metrics from our VMWare.

I'm using loops to show our environment.

 

The goal:

1. To get the Hard Disks on Each VM

     a. To see their capacity

     b. The location of the disk file(so I can tell what storage they are on)

2. Would be nice to see the set provisioned space for the VM as well.

 

Below is the code I'm using. Again only two days in so please be kind.

 

###Begin datacenter loop#####
my $datacenter_views = Vim::find_entity_views(view_type => 'Datacenter',properties => [ 'name' ]);
foreach my $datacenter_view (@$datacenter_views) {  my $dcname = $datacenter_view->name;  #print $dcname."\n";
####BEGIN HOSTS SYSTEMS LOOP######
my $host_views = Vim::find_entity_views(view_type => 'HostSystem',begin_entity => $datacenter_view,properties => [ 'name']);  foreach my $host_view (@$host_views) {  my $hostname = $host_view->name;  #print "--".$hostname."\n";
####BEGIN VM LOOP########  my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine',begin_entity => $host_view,properties =>['guest','name','runtime','summary','config','datastore'],filter => { 'name' => 'XXXXX' } );  foreach my $vm_view(@$vm_views){  my $vmname = $vm_view->name;       my $guestdisk = $vm_view->guest->disk;  foreach my $vm_guestdisk(@$guestdisk){  print $vm_guestdisk->capacity." ".$vm_guestdisk->diskPath." ".$vm_guestdisk->freeSpace."\n";  }   my $dsurl = $vm_view->config->datastoreUrl;  foreach my $vm_dsurl(@$dsurl){  print $vm_dsurl->name." ".$vm_dsurl->url."\n";  }  my $tests = $vm_view->config->hardware->device;  foreach my $vm_devices(@$tests){  print $vm_devices->deviceInfo->label." ".$vm_devices->deviceInfo->summary."\n";  }   }  }
}

 

What I'm getting as the output is:

42842714112 C:\ 10801651712
21471686656 E:\ 21099692032
vmaxdisk:1A59 /vmfs/volumes/4ca0f6f2-fb57f650-744b-001a64d2838c
vmaxdisk:1A99 /vmfs/volumes/4cbc53d4-32fb64a5-4058-001a64d2838c
IDE 0 IDE 0
IDE 1 IDE 1
PS2 controller 0 PS2 controller 0
PCI controller 0 PCI controller 0
SIO controller 0 SIO controller 0
Keyboard  Keyboard
Pointing device Pointing device; Device
Video card  Video card
VMCI device Device on the virtual machine PCI bus that provides support for the virtual machine communication interface
SCSI controller 0 LSI Logic SAS
Hard disk 1 41,943,040 KB
Hard disk 2 20,971,520 KB
CD/DVD drive 1 Remote ATAPI /usr/lib/vmware/isoimages/windows.iso
Network adapter 1 dvPortGroup_vlan14
Floppy drive 1 Remote /dev/fd0

 

What I need is to tell where the Disk File is stored for each Hard Disk so that I can tell what type of storage it is hosted on.

 

Thanks

Rob

Why is update_view_properties() using so much cpu?

$
0
0

Hello community,

I've been writing an application using the VMWare vSphere API/SDK for perl. I'm really enjoying the well-written documentation and functionality of the SDK.

The application that I am writing is a simple HTTP web server that provides JSON encoded data from the vSphere API. I store this data in an array, and every 3 seconds I have a subroutine that will update the properties of each object in the array for each view object returned by find_entity_views() with a specific property set and using update_view_data().

 

Interestingly, update_view_data() seems to be consuming a great deal of CPU, around 1250MHz on average, even though it is only called once per virtual machine (about 7 in this case) every 3 seconds.

Is there a way we can speed up the update_view_data() stack? Below are some excerpts from a performance log, it seems that this is where the issue is coming from: VimService::deserialize_response -> ComplexType::deserialize -> XML::LibXML::Element::getChildrenByTagName

 

The excerpts below are from a NYTProf Performance Profile ran on my web script which ran for a total of 129s. If you'll notice, line 62 of VimService::deserialize_response (which was initiated by ViewBase::update_view_data -> VimService::RetrieveProperties) had an inclusive time 97.8s.

 

Has anyone else experienced an issue with this? Is there a simple solution that does not require me to modify the update interval and preserve CPU?

Any assistance would be greatly appreciated.

 

LineState
ments
Time
on line
CallsTime
in subs
Code

VimService::deserialize_response

51

 

# spent 97.9s (25.8ms+97.9) within VimService::deserialize_response which was called 837 times, avg 117ms/call: # 834 times (25.7ms+97.8s) by VimService::RetrieveProperties at line 6206, avg 117ms/call # once (33µs+13.4ms) by VimService::RetrieveServiceContent at line 2136 # once (28µs+1.72ms) by VimService::Login at line 2206 # once (13µs+11µs) by VimService::Logout at line 2226

 

sub deserialize_response {
52837794µs  my ($result, $fault, $class_name, $isarray) = @_;
538372.40ms8375.02ms  my $response = SoapResponse->new;

 

  # spent 5.02ms making 837 calls to SoapResponse::new, avg 6µs/call

 

54837740µs  if ($fault) {
55  my $soap_faut = new SoapFault($fault); 
56  $response->fault($soap_faut); 
57  } elsif ($result) {
58837382µs  if ($isarray) {
59834157µs  my @return_array;
608341.04ms  foreach (@$result) {
61864971µs  if ($class_name) {
628642.67ms86497.8s  my $obj = $class_name->deserialize($_);

 

  # spent 97.8s making 863 calls to ComplexType::deserialize, avg 113ms/call # spent 206µs making 1 call to UNIVERSAL::AUTOLOAD

 

63864881µs  push @return_array, $obj; 
64  } else {
65  if ($_) {
66  push @return_array, $_->textContent;
67  }
68  }
69  }

 

ComplexType::deserialize

23267777761.22s77777673.8s  my @child_nodes = $element_node->getChildrenByTagName($property_name);

 

  # spent 73.8s making 777776 calls to XML::LibXML::Element::getChildrenByTagName, avg 95µs/call

 

 

---

XML::LibXML::Element::getChildrenByTagName

1614

 

# spent 73.9s (51.5+22.4) within XML::LibXML::Element::getChildrenByTagName which was called 780292 times, avg 95µs/call: # 777776 times (51.4s+22.4s) by ComplexType::deserialize at line 2326 of VMware/VICommon.pm, avg 95µs/call # 837 times (59.0ms+13.5ms) by SoapClient::request at line 2210 of VMware/VICommon.pm, avg 87µs/call # 837 times (34.8ms+19.8ms) by SoapClient::request at line 2209 of VMware/VICommon.pm, avg 65µs/call # 837 times (13.3ms+6.68ms) by SoapClient::request at line 2221 of VMware/VICommon.pm, avg 24µs/call # once (43µs+28µs) by Vim::query_api_supported at line 486 of VMware/VICommon.pm # once (38µs+25µs) by Vim::query_api_supported at line 481 of VMware/VICommon.pm # once (35µs+26µs) by Vim::query_api_supported at line 485 of VMware/VICommon.pm # once (35µs+24µs) by Vim::query_api_supported at line 483 of VMware/VICommon.pm # once (30µs+23µs) by Vim::query_api_supported at line 479 of VMware/VICommon.pm

 

sub getChildrenByTagName {
1615780292312ms  my ( $node, $name ) = @_;
1616780292108ms  my @nodes;
161778029225.3s  if ($name eq '*') {
1618  @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() }
1619  $node->childNodes();
1620  } else {
1621746634834.5s746634818.1s  @nodes = grep { $_->nodeName eq $name } $node->childNodes();

 

  # spent 10.5s making 780292 calls to XML::LibXML::Node::childNodes, avg 13µs/call # spent 7.62s making 6686056 calls to XML::LibXML::Node::nodeName, avg 1µs/call

 

1622  }
16237802923.15s61370524.34s  return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);

 

  # spent 4.33s making 6135375 calls to XML::LibXML::Node::DESTROY, avg 706ns/call # spent 6.01ms making 1677 calls to XML::LibXML::NodeList::new_from_ref, avg 4µs/call

 

1624}

Adding new Static ISCSI target

$
0
0

Hi,

I am very new to the Perl SDK.

I want to add a new static target to the iscsi software adaptor.

The API i think i need is AddInternetScsiSendTargets

 

Now, there is a problem - i don't know how to create arrays.

Here is the code

my $storage = Vim::get_view(mo_ref => $host->configManager->storageSystem);

my $scan_hbas = get_hbas_to_be_scanned($storage->storageDeviceInfo);

foreach(@$scan_hbas) {

    my $hba = $_;

    my $target = HostInternetScsiHbaStaticTarget->new('10.1.13.191', '3260', 'iqn.2003-10.com.riverbed:sn.135022938');

    eval {

        $storage->AddInternetScsiSendTargets(hbaDevice => $hba,

                                             targets => [\$target, ]);    #############  This is a problem

    };

}

 

Basically I do not know how to create an array as required by this API.

Would be great if anyone could point it out.

 

Also, what is the best book/blog/documentation to get started with perl sdk ? Thanks for all you replies !


--server option?

$
0
0

I have a number of virtual servers and need to take an educated guess in my script which server to connect to (based on the vm name for example). This way the user who runs the script does not need to provide --server argument.

What variable should I use to set the server name? $VI_SERVER does not seem to be it...

VMA 5.5, VICredStore.pm and VIFP created credentials

$
0
0

Hello,

 

After several hours of research, I've come to the following discovery. Hopping it will help someone as much in distress as I was :

 

The VICredStore.pm module allows to use VIFP authentication and therefore avoid using hard-coded password for you Perl scripts.

 

If you want to use this module, you will have to point your script to the credential store which defaut location is in $HOME/.vmware/credstore/vicredentials.xml. However, if you registered your targets to VIFP using the vifp binary, the file created is in the same location (given that you use the vi-admin of vi-user accounts) but named vmacredentials.xml. Don't be fooled. Even though the two files have exactly the same structure, VICredStore.pm can't only desobfuscate password created through credstore_admin.pl add. Moreover this perl script will create the vicredentials.xml file in the home directory of the user, not the vi-admin and vi-user directories.

 

What's really misleading is that VICredStore::get_password() return the obfuscated password if you point it to the vmacredentials.xml file, not an error message.

 

Hopping you'll find this post if you are looking for a solution to this problem.

 

Regards,

 

Clement.

Support of Perl SDK's vmclone.pl for ESXi without vCenter

$
0
0

I'm looking to use vmclone.pl from the Perl SDK 5.5 release.  I have an ESXi server with VMs that I'd like to remotely clone.  However when I attempt to invoke the perl scipt, I get an error " Operation is not supported by the current agent".

I was lead to believe that the Perl SDK operates on ESXi without vCenter Server.  Is this accurate?  Is my error due to another reason?

Problem with network mapping when bulk creating VMs (vmcreate.pl based)

$
0
0

Hi,

 

I have a strange problem when trying to bulk create several VMs using a modified version of vmcreate.pl:

(per VM: 2 x VMXNET3 adapter_types, different network connected to them)

 

Creating the first VM succeeds, the second fails with error message "SoapFault -> NoPermission".

When deleting the first VM, I can create the second... but again only one single VM, the other still fails.

 

What I have found out is that one can find a strange configuration (seems to be a missing mapping),

but only when examining the VM in Windows vSphere client - the web client does not show anything wrong.

 

When in vSphere client and opening the VM configuration window for networking, the correct networks

are bound to the correct NICs, but the pull-down selection field in the right side of the window is still blank.

This is _impossible_ to achive using the vSphere client itself, because the network is selected using

this field which is blank now...

 

When reconfiguring both networks using the initially blank pull-down selection field for the first VM

(in vSphere Windows-Client), then I can create the second one, and so on.

 

The network selection Perl code (get_network) is the same as in the official vmcreate.pl example.

(only using VirtualVmxnet3->new() for the different network adapter types)

 

I am using the vSphere SDK for Perl 5.1.0-780721 library and VMware vCenter 5.1 U1.

 

Any idea what I am missing? Or is there an updated version or any bugfix available?

Currently I feel a bit lost, because I have no clue where to search further.

Creating VM with ISO mounted CDROM

$
0
0

Hell community!

 

I am working on vmcreate.pl script to add creation of CD-ROM with iso from datastore, but got stuck on error

 

'Invalid Device configuration: VirtualSCSIControllerOption.numSCSICdroms'

 

I am sure that I am missing this option or something obvious but can't figure it out how to supply this.

 

I am creating cdrom as following(in below test I am creating just any CDROM, no iso file to reduce number of layers):

 

my$cdrom_backing_info = VirtualCdromRemotePassthroughBackingInfo->new(

                        deviceName => "",

                        exclusive => 0,

                );

my$description = Description->new(label => 'CDROM', summary => 'cdddrom');

 

my$connectable = VirtualDeviceConnectInfo->new(allowGuestControl => 1,

                                                  connected => 0,

                                                  startConnected => 1,

                                                  status => 'untried' );

 

my$cdrom = VirtualCdrom->new(backing => $cdrom_backing_info,

                                connectable => $connectable,

                                controllerKey => 0,

                                deviceInfo => $description,

                                key => 1,

                                unitNumber => 1 );

VirtualDeviceConfigSpec->new(device => $cdrom,

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

 

 

Does anyone has working example of creating VM with CDRom?

 

Andrey

add VMFS5 disk to VM using Perl SDK

$
0
0

Hi

Each of my VM's has one hard disk on nfs datastore

 

   9  VirtualLsiLogicController=HASH(0x46f5bc0)

      'busNumber' => 0

      'controllerKey' => 100

      'device' => ARRAY(0x520e190)

         0  2000

      'deviceInfo' => Description=HASH(0x520e148)

         'label' => 'SCSI controller 0'

         'summary' => 'LSI Logic'

      'hotAddRemove' => 1

      'key' => 1000

      'scsiCtlrUnitNumber' => 7

      'sharedBus' => VirtualSCSISharing=HASH(0x520de78)

         'val' => 'noSharing'

 

I have to find an option to add a new disk which is located on another datastore(Serial attached SCSI disk to each ESXi )


dsbrowse.pl --name vp-dscs1-sb1

     Summary

      Name             : vp-dscs1-sb1

      Location         : ds:///vmfs/volumes/5309af02-0ba1ac70-e723-10604bb454c8/

      File system      : VMFS

      Maximum Capacity : 931.25 GB

      Available space  : 930.2978515625 GB

 

I tried to use a vdiskcreate.pl , but it does not have an option to use different datastore for a new disk and always creates a new disk on a nfs datastore.

It's pretty easy to do with a wizard but I have to run it ~50 times

 

Thanks

PowerOffVM not triggering event

$
0
0

Hello:

Using the vSphere client, if I power off a VM, my perl program receives the VmPoweredOffEvent.

 

However, if I use the API and do this:

 

    my $vmName = "someVM";

    my $view = $self->{_VIM}->find_entity_view(view_type => 'VirtualMachine',
                                                filter => {'name' => $vmName});
    $view->PowerOffVM();

 

The VM gets powered off however I don't get the VmPoweredOffEvent.

 

Is this by design or is there something I need to do so the event is triggered?

 

Jonny L.


vifs

$
0
0

Hi.

 

I use the version 5.1 of Perl DSK and I have a problem.

 

I try to use --dir and --get options with --dc option.

 

I've got an error :

root@sdk:/# /usr/bin/vifs --url https://xx.xx.xx.xx --username root --password ******** --dc "My DC" --dir "xxx"

GET https://xx.xx.xx.xx/folder?dsName=xxx unsuccessful : 404 Not Found

Error: Can not list directory 'xxx'.

 

It doesn't take consideration of --dc option...

 

With -s option, it's ok...

"Server Version Unavailable" When using connect.pl from CentOS 6

$
0
0

I'm installing a new Nagios Plugin that's basically a Perl script that connects back to an ESXi host. I've been having issues getting it to connect and I'm wondering what's going on.

 

I've tried connecting to the host using the connect.pl from my CentOS 6 box, and I keep receiving the following error...

 

"Server version unavailable at https://<ip address>/sdk/vimService.wsdl"

 

I can manually navigate to this address, but I cannot seem to connect using the Perl script.

 

I've seen many suggestions about adding $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; at the beginning of your scripts, but this does not seem to be working.

 

I've also tried typing in export PERL_LWP_SSL_VERIFY_HOSTNAME=0 into the shell, and this doesn't fix anything. Not sure what's going on.

 

Perl v5.10.1

LWP Version: 6.05

Crypt::SSLeay Version 0.57

Differentiate VM & Templates using script

$
0
0

I have written a script to get list of VM under a vCenter using TraversalSpec. And in the final list under host it list both VM's & Templates as virtual machine. How to differentiate VM & Templates among these? Is there any specific option available to identify it?

 

Thanks

How to create vm under host without datacenter?

$
0
0



   my $datacenter = Vim::find_entity_view(view_type => 'Datacenter',  filter => { name => Opts::get_option('datacenter')});

   my $vm_folder_view = Vim::get_view(mo_ref => $datacenter->vmFolder);
   $vm_folder_view->CreateVM(config => $vm_config_spec, pool => $comp_res_view->resourcePool,  host => $host_view);


We don have datacenter and folders information, In this script "my $vm_folder_view = Vim::get_view(mo_ref => $datacenter->vmFolder);" any other alternate method (line )to create vm ?? any guess ?  want to create with help of host not datacenter & Folder...

Enabling VNC port on a VM

$
0
0

Is there any perl script available to enable vnc port and assign RemoteDisplay.vnc.password,RemoteDisplay.vnc.port values on a VM? Or can anyone help me with how to proceed forward?

Viewing all 1577 articles
Browse latest View live




Latest Images