Posts mit dem Label vCO werden angezeigt. Alle Posts anzeigen
Posts mit dem Label vCO werden angezeigt. Alle Posts anzeigen

Sonntag, 16. Juni 2013

vCenter Orchestrator: Mount ISO image into virtual CDrom

Hey there,
it's Sunday and nothing to do, so I decided to solve a task which was ignored for a long time.

The task is to mount an ISO image to a virtual pc, maybe to deploy virtual machines and configure them with prepared images of SCCM for example. I could imagine many use cases to automtically mount images to many machines.
Anyway, I created 3 scripts to find the CD drive, find the correct ISO file at your datastore and finally mount it.

Part 1: find the ISO and its path.

vCO expects a path like : "[datastore1] ISOs/Win8Alpha1.iso"

var ISOpaths = new Array(); //if you have more then one ISO file
var fileQuery = new Array(new VcIsoImageFileQuery());
var querySpec = new VcHostDatastoreBrowserSearchSpec();
querySpec.query = fileQuery;
var myISO = "Win8.iso"; //the ISO you are looking for
var myISOtemp = null; //temp parameter, it is just use to cut the string
var myISOpath = null; // your final path

var task = datastore.browser.searchDatastoreSubFolders_Task("[" + datastore.name + "]", querySpec);
var searchResults = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,false,5);
for (var i in searchResults) {
for (var j in searchResults[i].file) {
ISOpaths.push(searchResults[i].folderPath + searchResults[i].file[j].path);
}
}
for (k in ISOpaths)
{
myISOtemp = ISOpaths[k].substring(ISOpaths[k].search("] ")+2,300)
myISOtemp = myISOtemp.substring(myISOtemp.search("/")+1,300)
System.log(myISOtemp);
if(myISOtemp == "Win8.iso" )
{
myISOpath = ISOpaths[k];
System.log("found :" + myISOpath);
break;
}
}
//http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.host.DatastoreBrowser.FileInfo.html

Ok that's the script to find the ISO file, you are free to modify this to your own needs. Maybe you have serveral datastores with the same ISO file or different vCenters.

Part 2: Get the CD drive

This is easy, so there are no comments or explanations needed.

var devices = vm.config.hardware.device;

for ( i in devices )  {
if ( devices[i] instanceof VcVirtualCdrom )  {
System.log("Key: " + devices[i].key);
System.log("Label: " + devices[i].deviceInfo.label);
System.log("controllerKey: " + devices[i].controllerKey);
System.log("unitNumber: " + devices[i].unitNumber);
System.log (devices[i]); // will return the scripting class
}
}
Every information you need for part 3 is in there.

Part 3: Mount the ISO image

var spec = new VcVirtualMachineConfigSpec();
var deviceChange = new Array (new VcVirtualDeviceConfigSpec());
var VirtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec();
//http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.device.VirtualDevice.html
VirtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
var device = new VcVirtualCdrom();
device.key = 3002; //this could be an input parameter
deviceInfo = new VcDescription();
deviceInfo.label = "CD/DVD drive 1";
deviceInfo.summary = "ISO";
device.deviceInfo = new VcDescription();
device.deviceInfo = deviceInfo;
device.controllerKey = 201; //this could be an input parameter
device.unitNumber = 0; //this could be an input parameter
var CdromIsoBackingInfo = new VcVirtualCdromIsoBackingInfo();
CdromIsoBackingInfo.fileName = myISOpath;
var DeviceConnectInfo = new VcVirtualDeviceConnectInfo();
DeviceConnectInfo.startConnected = false;
DeviceConnectInfo.allowGuestControl = true;
DeviceConnectInfo.connected = true;
DeviceConnectInfo.status = "untried";

VirtualDeviceConfigSpec.device = new VcVirtualCdrom();
VirtualDeviceConfigSpec.device = device;

VirtualDeviceConfigSpec.device.backing = CdromIsoBackingInfo;
VirtualDeviceConfigSpec.device.connectable = DeviceConnectInfo;
deviceChange[0] = VirtualDeviceConfigSpec;
spec.deviceChange = deviceChange;
task = vm.reconfigVM_Task(spec);  //task is an output parameter if you want to start a waiting task
The only important thing you have to know is that when you want to add an attribute which is also an object you cannot do something like this: "device.deviceInfo.label" DeviceInfo has to defined before you add a values.

If you have questions, send me an email or post a commend.

Samstag, 15. Juni 2013

Powershell and vCenter Orchestrator Webservice with Output parameters

Hi,
here is the the script you need to get all output parameters of your vCO workflow when you call it from powershell.
Better you paste it into an editor, because it is very long:

$vmName = $args[0]; #to launch the script from commandline with parameters

if(!($vmName)) # if no paramteres are set, ask for it
    {
        $vmName = read-host "Please Enter a Server Name"
    }


[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$username = "VCOadmin"
$password = "VCOpassword"
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

$webservice = New-WebServiceProxy -uri "http://vcoserver:8280/vmware-vmo-webcontrol/webservice?WSDL"  -Credential $cred
$t = $webservice.getType().namespace

$attributes = New-Object ($t + ".WorkflowTokenAttribute")

$attributes.name = "vmName"
$attributes.value = $vmName
$attributes.type = "String"


#$webservice | Get-member
$wf = $webservice.getWorkflowsWithName("*getHotPlugINfo*","$vmName = $args[0];

if(!($vmName))
    {
        $vmName = read-host "Please Enter ServerName"
    }


$webservice = New-WebServiceProxy -uri "http://VCOserver:8280/vmware-vmo-webcontrol/webservice?WSDL"  -Credential $cred
$t = $webservice.getType().namespace

$attributes = New-Object ($t + ".WorkflowTokenAttribute")

$attributes.name = "vmName"
$attributes.value = $vmName
$attributes.type = "String"

#get all workflows, where the name is like getHotPlugInfo, or what ever your name is
$wf = $webservice.getWorkflowsWithName("*getHotPlugINfo*","VCOadmin","VCOpassword")

#start the vCO workflow by its ID
foreach($i in $wf)

    {
       $infos = New-Object psobject
        if($i.name -eq "getHotplugInfo")
           {
           $resp = $webservice.executeWorkflow($i.id,"VCOadmin","VCOpassword",$attributes)
           $WFid = $resp.id            
           $resp.businessState
           
           do{Start-Sleep -Seconds 2}
           while($webservice.getWorkflowTokenStatus(@($WFid), "VCOadmin","VCOpassword") -eq”running”) #get workflow status until it is finished
           
           $status = $webservice.getWorkflowTokenResult(@($WFid),"VCOadmin","VCOpassword") #get the output parameters of your workflow

                $infos | Add-Member NoteProperty Server $status[0].value
                $infos | Add-Member NoteProperty Memoryhotplug $status[1].value
                $infos | Add-Member NoteProperty CPUHotplug $status[2].value
            
            $infos      
           }
    }

The script is self explaining I think, if you have any questions send me an email.

If you are looking for more information about webservice and vCO visit the vcoportal at http://www.vcoportal.de/

Dienstag, 9. April 2013

vCenter Orchestrator: First Login to vCO Appliance

Hey there,
I often deployed a vCenter Orchestrator Appliance just for a testing purpose or there is a new release. Normally there shouldn't be any complicated tasks to do, because most facts are written down to its documentation. But what is not covered? Right the first login!
Which error could occure?
The error I got every time I did a new deployment is that my user was not known by vCO even though it was correctly configured in my start up configurtation. Authentification should not be done by the pre configured LDAP server delivered with the appliance, better you use your Active Directory.

If you have a closer look to the log file (you can find the error log in your web configuration) after your failed login (invalig Username/Password) you will find such an entry in your logfile:

2013-04-09 12:17:17.847+0000 ERROR [VcoFactoryFacade] Unable to login (Ex: javax.security.auth.login.LoginException: Cannot login user : vcoadmin, user unknown)
 
The solution is that easy, if you did not restart the whole appliance after configuring your Active Directory configuration, the appliance will still be using its own LDAP server.

Restartting just the service of the configuration server from your web browser does not help. You realy need to restart it from console.
After the appliance is up again you can login with your domain account.

There is one more  stumbling block you might pay attention to. Try to use your userPrincipalName like user@mydomain.com.

Hope this was a good hint to help you.