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

Add VMDK to VM using SDRS recommendation

$
0
0

Hi guys,

 

I am trying to add a disk to a VM following SDRS recommendation based on William Lam work.

 

Here is my code:

 

my $storagePod = Vim::find_entity_view(view_type => 'StoragePod', filter => {'name' => 'DCL_DC1_NOPROD_01'}, properties => ['name']);

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

my $podSpec = StorageDrsPodSelectionSpec->new(storagePod => $storagePod);

my $vmSpec = VirtualMachineConfigSpec->new(files => $vm->config->files);

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

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

 

 

Bit I get this error:

 

 

SOAP Fault:

-----------

Fault string: A specified parameter was not correct.

StoragePlacementSpec.podSelectionSpec.storagePod

 

 

Any idea?

 

 

Thanks in advance.


How Allocate VM's on cluster host

$
0
0

Dear All,

 

I am creating a VM from template, by specifying the vmhost ( cluster host specifically ), this has been done smoothly.

 

but since now i am having more the one cluster hosts, is it possible to provide only cluster name and VM creation would be create VM on any suitable free cluster hosts.

 

How to achieve this, please provide your valuable comments.

 

Regards,

Nilesh

How to get vmlist by host

$
0
0

Hello

 

I have four VMServer.

 

I Want to get vmlist by host.

 

How to do it??

 

Now, I though vcenter to get it. But I can't success.

Is there any way to set iops for virtual disk through Perl SDK?

$
0
0

Hi,

 

we are trying to limit the number of iops on specific virtual disks in vsphere, is it possible to do this via Perl SDK?

Do any of you have some experience with that? I was not able to find it in documentation.

 

Thanks a lot,

JZ.

Delete VM via Perl SDK

$
0
0

Hi Everyone,

 

I am looking for a way to delete a VM from a vCenter using Perl SDK.

 

It seems that there is no delete() method once a vm refernce is obtained from find_view call. There is register and unregister but I could not find it anywhere how-to destroy a VM destructively as opposed to just simply unregister. I must be missing something and guessing that it cannot be that complicated since it is a basic operation that anyone would want to perform.

 

Anyone have any Perl snippet that can share in this regards here?

 

Thanks.

changing host password via perl SDK?

$
0
0

Can anybody provide a quick pointer on how to change the root password using the perl SDK?

 

It appears that I need to create a hostConfigSpec (with userAccount property) and call applyHostConfig_Task to achieve that. But I am having a hard time figuring out the structure of hostconfigSpec piece...

 

In addition, if I want to only get the properties needed to speed up the query, what properties should I filter on?

$hosts = Vim::find_entity_views(view_type => 'HostSystem', properties => ['name','config'], filter => { name => qr/$hostName/});

 

Thanks!

Count free ports in portgroup

$
0
0

Hello,

 

I want to monitor the count of free ports in a portgroup (Distributed Virtual Switch). The number for total ports is no problem, I can get this value from the DVS-Object.

The better question is: where to get the count of used ports from. I can't get this value from the DVS-Object.


I tried to fill a hash with the portgroups used in all VMs, but it seems, that there were some ports missing (i.e. VM powered off).

 

Has anyone some scripts or ideas how to get an overview of all portgroups with used/free ports?

 

Thanks so far,


Greets,

Alex

Not able to run vmreconfig.pl

$
0
0

Hi ,

 

I am not able to run vmreconfig.pl

 

/usr/lib/vmware-viperl/apps/vm/vmreconfig.pl --server VC_server --username <name> --password <passwd> --filename  test.xml --schema /usr/lib/vmware-viperl/apps/schema/vmreconfig.xsd

Can't load class 'XML::LibXML::XPathContext' at /usr/lib/perl5/site_perl/5.8.5/VMware/VIMRuntime.pm line 52.

My test.xml looks as below .

<?xml version="1.0"?>

<Reconfigure-Virtual-Machine>

  <Name>VM_NAME</Name>

  <Host>ESX_IP</Host>

  <Add-Device>

   <Hard-Disk>

    <Name>'datastore1 (20)'</Name>

    <Size>1024</Size>

    <Persistent-Mode>persistent</Persistent-Mode>

   </Hard-Disk>

  </Add-Device>

  <Shares>

   <CPU>2</CPU>

   <Memory>1024</Memory>

  </Shares>

</Reconfigure-Virtual-Machine>

 

Regards

Deb


Creation of the virtual machine on a cluster via vmcreate.pl script

$
0
0

Hi,

 

I have checked few posts on this forum on how to create the virtual machine via vmcreate.pl, but the responses was not so clear to me...

These are the topics I have read:

 

Create VM instance on Cluster

How to set up the HostSystem Managed object

 

So, I would like to create a virtual machine on a Cluster, not on a specified host. Does the script vmcreate.pl would do the job ? Or I should modify it ?

From the topic => Create VM instance on Cluster    I didn't quite get, what should I modify ...

 

This is what I do:

 

vmcreate.pl --server "ESX NAME" --username "LOGIN" --password "PASS" --filename vmcreate.xml --schema vmcreate.xsd


Result:

 

Error creating VM 'myTestMachine':

SOAP Fault:

-----------

Fault string: InvalidArgument

Fault detail: InvalidArgument

 

Here are the XML file values:

 

                <Name>myTestMachine</Name>

                <Host>blabla</Host>

                <Datacenter>blabla</Datacenter>

                <Guest-Id>Linioch</Guest-Id>

                <Datastore>blabla</Datastore>

                <Disksize>2048</Disksize>

                <Memory>256</Memory>

                <Number-of-Processor>1</Number-of-Processor>

                <Nic-Network></Nic-Network>

                <Nic-Poweron>1</Nic-Poweron>

 

The values are correct cause I have checked them via other perl scripts.

 

Thank You in advance for Your help

Michal

Adding a paravirtual controller and disk to existing VM

$
0
0

Hi,

 

Are there any example scripts using the perl sdk on how to add a paravirtual scsi controller and a disk to a existing VM?

 

I've modified my vmcreate.pl script to create a paravirtual controller instead of a Buslogic at VM creation time. How do I add a disk to this controller, OR add another paravirt controller and a disk?

 

Thanks!

Device status "connected and connected at power on" stays unchecked after VM clone in linux

$
0
0

Dear All,

 

We are creating a linked VM and finding some weird behavior  the network adapter's Device status "connected and connected at power on" stays unchecked after VM clone in Linux.

 

When multiple VM gets created at once we see this issue but creating single VM works well.

 

Can you please let me know what could be the cause of the issue.

 

Why this indifference behavior?

 

Regards,

Nilesh

How to improve time to fetch VM from vmhost.

$
0
0

Dear All,

 

Here is my code  which return VM count in

 

real0m38.877s
user0m13.869s
sys 0m0.503s

 

 

for below code, how do i improve the time to fetch the results.

 

my $host_name =  Opts::get_option('vmhost');

 

my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => {'name' => $host_name});

 

&listVMs($host_view);

 

    sub listVMs {

    # Prints a list of registered VM on the screen.

    # Does not log it's use.

    #

        my ($host_view) = @_;

        my $vms = Vim::get_views(mo_ref_array => $host_view->vm, properties => ['name','runtime.powerState','guest.toolsRunningStatus']);

        my $totalVMs = 0;

        foreach(@$vms) {

            $totalVMs += 1;

            print "VM: ".$_->{'name'}.", ".$_->{'runtime.powerState'}->val.", "

                   .$_->{'guest.toolsRunningStatus'}.", ".$_->{'mo_ref'}->value."\n";

        }

        print "\nTotal ".$totalVMs." VMs found.\n\n"

    }

Create VM instance on Cluster

$
0
0

 

Hi,

 

 

I want to create virtual machines on Cluster, not on a specified host.

 

 

My Problem is that the function VMCreate need an type "resourcePool" and I don't know how to create a resourcePool from a ClusterComputeResource.

 

 

Can anyone help me?

 

 

Thanks in advance

 

 

Henning

 

 

Data Object - VirtualSCSIController doesnt return initialized array for property 'devices'

$
0
0

When searching through devices looking for objects of type 'VirtualSCSIController', the property 'device[]' (an array) is only initialized IF the extended controller type is VirtualLsiLogicController

 

If the extended type of VirtualScsiController is any one of 'VirtualBusLogicController', 'VirtualLsiLogicSASController', or 'ParaVirtualController' the array remains uninitialized.

 

sample code:

 

<code>

   my $devices = $vm->config->hardware->device;

   foreach my $device (@$devices) {

      if ( $device->isa('VirtualSCSIController') && ($device->busNumber == $vctrl_num) )

       {

         if ( $device->device[0] )

          {

            return $device;

          }

       }

   }

   print "Returning UNDEF from find_scsi_controller_device\n";

   return undef;

}

 

</code>

 

Any ideas? Is this a known bug of some sorts?

Using 2 SDK versions side by side

$
0
0

Hi.

 

I am currently using older SDK. I have tried to upgrade to 5.1 SDK, but it looks like it breaks a lot of my scripts.  Most of the issues seem to be in using regular expressions in filters. It seems the 5.1 SDK does not like regex not surrounded by qr op. One idea is to run 2 SDKs side by side, so I dont have to modify any of my existing scripts. Anyone know how I can install the new SDK and have it not interfere with the older SDK?


Get cloud.uuid optionvalue from extra config without iterating through the array?

$
0
0

I need to get the cloud.uuid (or any other optionValue for that matter) from the extraConfig data object.  Is there a way to get to the value of a specific key without having to iterating through the array? As this is not a hash, attempt at getting to the value with this fails miserably:

 

$extra->{'could.uuid'}...

 

Here is an iteration approach that works.


my $extra = $vm->config->extraConfig;

        foreach (@$extra) {

                print $_->value if ($_->key =~ /cloud.uuid/);

        }

 

Thanks!

Linked VM does not respond after few hours of creation.

$
0
0

Dear All,

 

Please help us know the causes of below issues, as we are struggling to get this resolved.

 

1. After few hours of Linked VM creation, my Linux VM stops responding, my ssh command hangs.

2. Load of the cluster are normal.

3. Data store also show normal.

4. Memory utilization is also normal.

 

This is impacting the existing run on the VM causing productivity reduction. Does we need to recreate snapshot over the period of time, but we don't have any changes in the base VM. we such instances after every 2 out of 7 occurrences of VM linked VM creation.

 

We also seen behavior like after Linked VM creation VM does not connect to network adapter and its corresponding checkbox is marked unchecked, why we are getting this inconsistent results.

 

Please help and provide your valuable comments.

 

Regards,

Nilesh

Retreiving VM IOPS using perl SDK

$
0
0

I'm looking for some assistance with pulling real time disk IOPS for our VMs (preferably both read and write). It appears as this data is rooted in both the virtualDisk and storageAdapter performance counter groups.

 

I figured I'd start with the storageAdapter group. For storage Adapter, it looks like the counters would be numberReadAveraged and numberWriteAveraged. In vSphere, I can see data in the advanced section of the VM's performance tab (although the actual storageAdapter data looks to be under the virtual disk category in the performance hierarchy).

 

The process I go through is:

 

get a view of the vm: 

     my $view = find_entity_view(view_type => 'VirtualMachine', filter => {'name' => '<vmname>'})

get a perfmgr view:

     my $perfmgr = get_view(mo_ref => Vim::get_service_content()->perfManager)

get the metrics of interest from the perfmgr view:

     iterate through $perfmgr->perfCounter  to find the $_->groupinfo->key and $_->nameinfo->key that match the counters I'm looking for and create an array of PerfMetricIds with the associated keys

     $counters[$index] = PerfMetricId->new(counterId => $_->key)   # do I also need to include the instance parameter here, for example: instance => 'scsi0:0'. or maybe some type of wildcard?

create a perf query spec from the vm's view and the array of PerfMetricIds

     my $perf_query_spec = PerfQuerySpec->new(entity => $view, metricId => $counters, format => 'csv', intervalId => 20, maxSample => 1); # should the entity go to the vm view, or another view associated with the vm's storage adapter devices?

get the perf data (seems to always return no data in my trial and error approach):

     my $perf_data = $perfMgr->QueryPerf(querySpec => $perf_query_spec);

 

Thanks in advance.

 

-mike

Network configuration of Windows VM using unattended installation

$
0
0

Hi,

I'm writting some scripts to automate the installation of Windows 2012 and 2008R2 in VM using an unattended installation. My VM have 2 nics. Each nic in a different VLAN (one for backup, one for production).

But, using unattended installation, setup do not name the nic in the same order at each install.

So, as the nics are not in the same VLAN and Windows setup do not name the nic in the same order at each install, it seems impossible to personnalize an unattended file to specify a fixed IP Address of backup and production on one nic in each vlan.

 

Is there a way to dectect from the OS the "Network Adapter 1" and "Network Adapter 2" as listed in the settings of the VM ? Using the powercli is not convenient.

I tried under windows 2012 : get-netadapterhardwareinfo, but it does not help me.

The hosts run vpshere 5.0U1 and we plan to upgrade to 5.1U1 in the next couple of months

 

Thank you

Best regards

ML

Perl API error

$
0
0

Sorry if this is the wrong forum, I could not find a more relevant forum. I'm trying to create a script that automatically resignatures a cloned datastore in Perl. I've written it in PowerCLI and have it working but I get errors when trying to use Perl. Here's the PowerShell

 

Connect-CIServer vcenter-server

Get-VMHost -VM test-VM | Get-VMHostStorage -RescanAllHba

$hostView = get-vmhost -VM test-VM | get-view

$dsView = get-view $hostView.ConfigManager.DatastoreSystem

$unBound = $dsView.QueryUnresolvedVmfsVolumes()

 

$extPaths = @()

$Extents = $dstore.Extent

foreach ($ex in $Extents) {

      $extPaths = $extPaths + $ex.DevicePath

}

$res = New-Object VMware.Vim.HostUnresolvedVmfsResignatureSpec

$res.ExtentDevicePath = $extPaths

$return = $dsView.ResignatureUnresolvedVmfsVolume($res)

 

Here's the Perl:

 

Util::connect();

 

 

my $vm_views = Vim::find_entity_views(

  view_type => 'HostSystem',

  filter => {

  'name' => qr/esx-host/

  }

);

 

 

print "Rescanning all HBAs to find new LUNs\n";

foreach $host (@$vm_views) {

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

  $storageSystem->RescanAllHba();

}

 

 

$host = ${$vm_views}[0];

 

 

# Find the snap LUN and resignature it

print "Querying for unresolved VMFS volumes\n";

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

my @unbound = $datastoreSystem->QueryUnresolvedVmfsVolumes();

foreach my $dstore (@unbound) {

        my $volume = ${$dstore}[0];

        if($volume->{'vmfsLabel'} ne $vmfsLabel) {

                print "Unresolved VMFS volume ".$volume->{'vmfsLabel'}." found but does not match ".$vmfsLabel."\n";

                next;

        }

 

 

        my @extpaths;

        my $extents = $volume->{'extent'};

        foreach my $ex (@$extents) {

                push @extpaths, $ex->devicePath;

        }

        my $res = bless ( {

                        'extentDevicePath'      => [ @extpaths ]

                }, 'HostUnresolvedVmfsResignatureSpec' );

        print Dumper $res;

 

 

        $datastoreSystem->ResignatureUnresolvedVmfsVolume(resolutionSpec => $res);

}

Util::disconnect();

 

This prints the following:

Rescanning all HBAs to find new LUNs

Querying for unresolved VMFS volumes

$VAR1 = bless( {

                 'extentDevicePath' => [

                                         '/vmfs/devices/disks/naa.6006016083d226001cf20fdc0d27e311:1'

                                       ]

               }, 'HostUnresolvedVmfsResignatureSpec' );

Undefined subroutine &HostUnresolvedVmfsResignatureSpec::serialize called at (eval 29) line 111

 

I've also tried with ResolveMultipleUnresolvedVmfsVolumes but I get the same error.

Viewing all 1577 articles
Browse latest View live




Latest Images