PowerCLI vs Perl SDK

On the side of PowerCLI, I can run:

set-model - < name > - tovm

.. what allows to convert a template to a virtual machine.

Perl SDK side, I found the MarkAsVirtualMachine call which seems to do something similar.

However, on the side of Perl SDK the above call requires a ResourcePool be passed while the PowerCLI command does not require a ResourcePool.

In our environment, we do not use set ResourcePools - we have ClusterComputeResources, but that did not help me.

Can anyone offer suggestions to get something on the side of Perl SDK which performs similarly to the game model on the side PowerCLI?

Thank you

M

Yes, they probably have to jump the host.

my $vm_name = "test_vm_template";
my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => { 'name' => $vm_name });
my $host_ref = $vm->{'runtime'}{'host'};
my $host = Vim::get_view(mo_ref => $host_ref, properties => ['name', 'parent']);
my $compute = Vim::get_view(mo_ref => $host->{'parent'}, properties => ['name', 'resourcePool']);
my $pool = Vim::get_view(mo_ref => $compute->{'resourcePool'}, properties => ['name']);

# Now use $pool as parameter to MarkAsVirtualMachine

I do this completely in the SDK documentation, so I'm sure that there are some typos.

Tags: VMware

Similar Questions

  • a few questions on the perl sdk

    I've been using perl sdk for 3.5.1 for awhile and I sued to connect with the virtual Center as follows

    Vim::login (service_url = & gt; "https://lbz0893/sdk/vimService", user_name = & gt;... .

    This no longer works on the new vsphere. can someone help me get started with this.

    (2) is there any sdk perl for Mrs. that I can use to create recovery plans and execute them?

    Thank you.

    In fact, there is an API of SRM , but there seems to be any client-side stubs. You may be able to use SOAP::Lite, however, not sure. The API is also quite minimal in its current form.

    =====

    Carter Shanklin

    Read the PowerCLI Blog
    [Follow me on Twitter |] http://twitter.com/cshanklin]

  • Upgrade to vSphere 6 perl SDK, SOAP errors

    After the successful upgrade of vSphere 6u2, I can no longer run scripts API:


    vmcreate.pl - url https://${vcenter}: 443/sdk / webService < parameters >

    Results in:

    Error creating the VM 'testVM ':

    Fault SOAP:
    -----------
    Fault string: refused permission to perform this operation.
    Fault of details: NoPermissionFault

    I updated and tried the last SDK perl as well, the same error.

    I have administrator rights on vCenter level, all objects of multiplication.

    Suggestions more than welcome!

    Thank you!

    Just an update for those who also have this problem.

    Looks for from vmcreate.pl API call requires privileges of grater on object of data than those fixed in vSphere 5.5 Center,.

    I have documented more details in my blog. http://www.virtualflow.NET/2016/05/vSphere-6u2-permissions-vs-Perl-SDK-API-calls/

    Hope that helps! This thread can be closed.

  • Perl SDK for VM API storage policy

    I understand that it has Java SDK API of VM storage, but we mainly use Perl SDK for vSphere for monitoring before any decision on the integration of strategies of VM storage and virtual infrastructure together in what I would like to ask if there is a plan to release Perl for Vm Storage Policy API SDK? Anoyone know what Perl SDK plan in this area is?

    Thanks in advance for any thoughts,

    DRB

    Well, anyone interested, so made myself... Thanks anyway!

    DRB

  • Support for Perl SDK for ESXi vmclone.pl without vCenter

    I try to use version 5.5 of SDK Perl vmclone.pl.  I have an ESXi with VM Server I want to clone remote.  However, when I try to invoke the perl scipt, I get an error "Operation is not supported by the current agent.

    I was led to believe that the Perl SDK works on ESXi without vCenter Server.  Is this correct?  My mistake for another reason?

    vSphere SDK for Perl can run on ESXi and vCenter, this is just an interface with the API. However, in the case of cloning that is a feature, it is only exposed when vCenter Server is in the picture. You cannot issue a clone operation directly on an ESXi host and this is why the fault was lifted.

  • vCenter Linked Mode and Perl SDK

    Hello

    our VMware environment is divided into two physical places represented as two instances of vCenter. The two vCenters are interconnected. I think that its Mode called "related"?

    Is it possible to use the Perl SDK also bound mode? Currently, I have to manually interrogate both our vCenters and then sort out myself.

    (1) How to configure Perl SDK so I only authenticate once against our environment in Linked mode?

    (2) How can I build queries against the API so results will include objects in the two vCenters? That is to say. If I run a ' Vim::find_entity_views (view_type = > 'VirtualMachine') "I want to get all the objects 'VirtualMachine' in the two vCenters I can avoid running two separate queries and then later combining query results? ".

    Thank you!

    Thomas Willert

    It is not a published API method, but there is a way to get the vCenter server list in a group of related modes.  I have an explanation and sample code: http://www.virtuin.com/2012/12/querying-vcenter-linked-mode-with.html

    With respect to authentication, if your vCenter instances use the same permissions (which is recommended), then it's just a matter to authenticate each vCenter.  This is what the native client as well (if you have never installed vCenters with different permissions, you will see the login for each vCenter prompt).

    If you look at the blog post I linked earlier, you self an example of authentication each vCenter as well.  Basically you call Util::connect() two times, once for each of your URL for vCenter.  However, do not delete the global VIM uses the SDK package, or it will default to the last vCenter.  I show in the example script: LinkedModeExample.pl

    With respect to the combination of queries... not so easy.  You need to redesign each vCenter with $vim-> find_entity_views().  Now on a more advanced note, API is powerful enough to make custom inventory queries, you can usually pick up and keep the updates in your objects.

    What I would recommend as a simple approach is two calls to find_entity_views, then push them in a hash or an array.  You'll just want to use the UUID vCenter:

    $vc_uuid is $vim1-> get_service_content()-> {'about'}-> {'instanceUuid'};.

    The instanceUuid has been added in vCenter 4.x and later versions (do not have in the past 2.5 vCenter instances).  Then use this instanceUuid + moref as hash keys.  This is important because the morefs can be duplicated between vCenters.

    So, you can then create a hash:

    My % vm_hash;

    foreach my {$entity (@$vm_views)}

    My $moref = $entity-> {'mo_ref'}-> {'value'}; # will be vm-# for virtual machines

    $vm_hash {$vc_uuid.} "+". $moref} = $entity;

    }

    Then you can quickly research specific VMs and keep separate them between vCenters.

    You'll find it works for simple data queries, but you start to get more items of inventory (say for an inventory report), the relationship becomes more complex and the number of objects grow.  I did work to push these values in a database and files (including by running it on 5 or less than weight and WaitForUpdatesEx), excel, which works well if you have the time to build the DB and the work of database object schemas.  Just use instanceUuid + Moref value as primary key to prevent any moref vCenter cross reuse value.

    The other option is that the vim reference is added to each object, so you can just get the data of each entity:

    foreach my {$vm (@$vm_views)}

    Print "VM:". "." $vm-> {'name'}. "\n";

    Print "InstanceUuid VC:". $vm-> {'vim'}-> {'service_content'}-> {'about'}-> {'instanceUuid'}. "\n";

    Print "ServiceUrl VC:". $vm-> {'vim'}-> {'service_url'}. "\n";

    }

    I have a project that I tinker with in my spare time (which is rare these days) which aims to consolidate multiple vCenters into one database for queries and reports, but I didn't get far enough away from share it (very rude, but works for a subset of data at present, but it is very effective for collecting loose on<5s intervals).="">

    You can also look into VMware Orchestrator.  Orchestrator can connect to multiple vCenters and caches data for access by automation.  According to your WAN performance, he can work a geographic site and make sure that you need (just watch the moref, names of entities and other potential overlap between vCenters) aggregated data.

  • Delete VM via Perl SDK

    Hello world

    I am looking for a way to remove a virtual machine from a vCenter using Perl SDK.

    It seems that there is no delete() method after obtaining a find_view call vm refernce. There is register and unregister, but I could not find anywhere how to destroy a machine virtual destructive as opposed to simply cancel the registration. I must be missing something and guess that it may not be so complicated because it is a fundamental operation that someone would want to perform.

    Someone at - it an extracted Perl which can share in it considered here?

    Thank you.

    Attached is the complete script inspired by vmregister.pl which is part of the SDK for Perl sample set.

    Be warned of this successful run this script against a virtual machine in vcenter will destroy and will be UNRECOVERABLE. Use it with caution and at your own risk.

  • Perl SDK - get/set vSphere 5.1 tags?

    My apologies if this has been requested and we responded, but I'm exhausted with the search.  5.1 introduced tags for the custom attributes, but I can't find a way to access the tags in the Perl SDK.  Am I missing something?  It has been extremely frustrating to have a new feature touted with great potential that is being wasted for most, appearing only in the web client.

    Thanks in advance!

    The new "Tagging" feature introduced in vSphere 5.1 is currently not available today in the vSphere API, you can use the new vSphere Web Client to run on the tags.

  • Cannot install VMware-vSphere-Perl-SDK - 5.0.0 on Debian

    HI -.

    I try to install the latest version of the SDK VMware Perl (VMware-vSphere-Perl-SDK-5.0.0-422456.x86_64.gz) on a Debian GNU/Linux "lenny" release.

    root: / usr/local/nagios/vmware-vsphere-cli-distrib #./vmware-install.pl
    Create a new vSphere CLI installer using the tar4 format.
    Installation of vSphere CLI 5.0.0 build-422456 for Linux.
    You must read and accept the vSphere CLI end-user license agreement for
    continue.
    Press ENTER to display it. q
    Do you accept? (yes/no) Yes
    Thank you.
    Cat: / etc / *-output: no such file or directory
    SH: rpm: command not found
    OpenSSL-devel is not installed on the system.
    OpenSSL-devel-0.9.7 is required for encrypted connections.
    Please install openssl-devel version 0.9.7 or higher.
    SH: rpm: command not found
    e2fsprogs is not installed on the system
    e2fsprogs-1.38 is required for the UUID.
    Please install e2fsprogs 1.38 or higher.
    root: / usr/local/nagios/vmware-vsphere-cli-distrib # dpkg-l e2fsprogs
    II e2fsprogs 1.41.3 - 1 ext2/ext3/ext4 file system utilities

    Clearly the Setup is broken.

    So, my question is - is the installer deliberately broken (IE, no support for Debian) or is it a perl error code that needs fixing?

    Thank you

    Chris

    As William, he will not be supported, but you can use the SDK Software VMware Perl quite easily on any platform of Perl (I did it with window as well).  I did specifically on Ubuntu and OS X over the years.

    Install the requirements of the module as shown in "vSphere SDK Perl Source Code installation on Linux".  In the source package, copy the folder VMware vmware vsphere-cli-distrib/lib/VMware/sharing of archive download Perl Linux SDK to your path to Perl.

    For required modules, you can use PPM, CPAN or apt get the packages.

    I ran this way for years without any problem, but this obviously isn't an official support statement

    You should be able to simply do not put a proxy during Setup.  It's there in case it is necessary to download the module dependencies.

  • ticket MKS in Perl SDK - vSphere 4.1

    Hi all

    I try to write the script for AcquireTicket of MKS in perl SDK 4.1 vSphere

    Pleas see an attached Perl file.

    AcquireTicket info:

    http://www.VMware.com/support/developer/VC-SDK/visdk41pubs/ApiReference/Vim.virtualmachine.html#acquireTicket

    I have the answer:

    ./ticketmks.pl --server IP --username User --password Pass --vmname vm_name_fromvCenter --operation ticket
    Get AcquireTicket "vm_name_fromvCenter" ticket Type: mks ...
    Error:
    SOAP Fault:
    -----------
    Fault string: A specified parameter was not correct.
    ticketType
    Fault detail: InvalidArgumentFault
    

    What I am doing wrong?
    Why can I not get the MKS?
    Help, please

    The SOAP fault is always the more descriptive message, but usually when you get "a specified parameter was not correct", this means that you do not pass parameters to a method of giving. If you take a look at the reference for the API for the AcquireTicket() method, you will notice that it accepts a single parameter ticketType and it is of type string. Looking at your script, you try to instantiate the object VirtualMachineTicketType, which is incorrect.

    You must update the execution of the method as follows:

    My = $vm $task-> AcquireTicket (ticketType-online "mks");

    and must now return back VirtualMachineTicket

  • Change the permissions for a particular user on a host ESXi 4.0 U2 CLI (Perl SDK)

    Hello

    I have an ESXi 4.0 U2 host, multiple virtual machines are working. Each VM has

    Some users in the annex (via permissions). For example, there is a

    user called "vm002", which has customized "VM user" role and is

    assigned to certain virtual machines. So the question is... How can I change the role of

    This user? I want to be able to automate the blocking of this user by

    the definition of his role on all VMs available on 'No access' (default system

    blocked role with all functions). I use Perl SDK, please provide some

    script or a code sample, how can be done.

    Thank you.

    As an attachment, you can find the script (ChangeRole.pl) that changes a role (rolename) to a user (setuser) or for all the selected vm or vm on the host (parameter optional vmname)

    ./--server esx --username root --password password --setuser user01 --rolename testrole2
    Check user user01 for vm "vm-001"
     For vm "vm-001" retrieved Permissions Successfully.
    The user user01 does not have a role for vm "vm-001"
    Check user user01 for vm "vm-002"
     For vm "vm-002" retrieved Permissions Successfully.
    Assign role testrole2 to user testuser for vm "vm-002"
     Authorization Role testrole2 Added To testuser For vm "vm-002"" Successfully.
    Check user user01 for vm "vm-003"
     For vm "vm-003" retrieved Permissions Successfully.
    Assign role testrole2 to user user01 for vm "vm-003"
     Authorization Role testrole2 Added To user01 For vm "vm-003" Successfully.
    

    If you find this information useful, please give points to "correct" or "useful".

  • VMware-vSphere-Perl-SDK-5.5.0-1384587 broke up with perl 5.20

    as the subject says, the vmware SDK is broken with perl 5.20.2.

    The issue of possible priority with operator control in the /usr/share/perl/5.20/VMware/VICommon.pm 2147 line flow.

    is there a solution?

    The priority of the return order is not clear in VICommon.pm.  No doubt 5.20.2 added this additional warning.

    Not tested, but try to change the VICommon.pm 2146 line to:

    return (meaning $user_agent-> cookie_jar and)

    $user_agent->-> as_string cookie_jar don't ");

  • Permissions to connect to esxi with perl sdk

    I tried the user scripts perl for surveillance. I have 1 Server ESXi 5.1 I can connect to directly and the script has no problem connecting.

    I have another 3 esxi servers which are connected to a server for vsphere.

    On the same server, I can connect directly to the server esxi with vsphere client no problem.

    On the vsphere server, I can only connect to the server for vsphere, I can't connect directly to the esxi hosts. (http, https, ssh, etc...)

    I think it's the issue that I have with the sdk for perl. I have a SSO connection that I can user to connect to the server for vsphere, but these permissions will not get access to the esxi host.

    Anyone have any ideas on how to solve this problem?

    Thank you

    I'm really not sure about the writing of scripts and other things, but if you need to create local users in ESXi host, you must connect to the host directly and then go to the tab of local users and groups and create users.

  • Remote SCSI via the perl SDK

    I understand that there are ways to get information about the investigation of SCSI LUNS via the SDK and rCLI.

    In particular, the class ScsiLun: http://www.VMware.com/support/developer/VC-SDK/visdk400pubs/ReferenceGuide/Vim.host.ScsiLun.html#field_detail

    But I don't see any way for a user (from the vMA) to go to the next step and send custom object ScsiLun SCSI commands. Someone at - he found a way to send a SCSI CDB custom unit number logic of an ESX SCSI host remotely from a computer using the SDK provided by VMware?

    VDDK seems to only allow access to the low-level vmdk files, but does not have access beyond. VDDK can be a solution with a RDM vmdk file cards, but does not provide the same level of access to a logical unit number which has a VMFS partition.

    What would be nice, is to have methods on the object ScsiLun allowing at least read() calls to appear.

    Is not possible. VDDK primary use case is to allow users to manipulate and manage the VMDK (s) for a given virtual machine, it does nothing with the storage array. The vSphere API allows you to perform basic and the configuration of your VMware infrastructure management and base operations around the storage system under such as creating new VMFS volumes or resignaturing/re-mounting a volume snapshot, which is as much as the API exposed in terms of storage void System. If you want more integration and control of the storage subsystem, then you will probably need to look at vStorage API for integration of table better known under the name of VAAI and only sellers of table I know that it is taking part in this program is the type of EMC, NetApp and Dell. So unless you work for them, you probably won't be able to get access to the internal API allowing then storage vendors hang their respective API

    What you trying to do sounds like this should be done from the point of view of the storage provider and perhaps they have APIs that you can leverage to make your reads/writes, but a large part of this work is already being developed by the big 3 and I am sure that other vendors will join as VAAI becomes more popular and mainstream in order to unload the processes in the data mover in it VMkernel on the storage array.

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

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    Twitter: @lamw

    repository scripts vGhetto

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    VMware Code Central - Scripts/code samples for developers and administrators

    VMware developer community

    If you find this information useful, please give points to "correct" or "useful".

  • vSphere 4 perl SDK with ESX 3.5?

    I start a project with the ESX 3.5, although we can upgrade to vsphere in a near future. Is it safe to use perl vsphere SDK with ESX 3.5 for now, or I'm better with the 1.6 VIPerl sdk until I can upgrade to vsphere 4?

    Thank you

    SDK for Perl 4.0 will work against ESX 3.5. There is a compatibility chart in the Installation Guide.

Maybe you are looking for