Using the Embotics® vCommander® REST API, you can interact with the Service Catalog using several methods. For each method, one or more powershell examples are provided.


GET Method

 

Get All Published Services 

 

$collection = Get-PublishedServices

 

Get Published Service by ID


  

$ps = Get-PublishedServiceById -psId 24555

 

 

Get Published Service by Name

 

$ps = Get-PublishedServiceByName -name "Service #1"

 


NEW Method

  

Create a Published Service 

#Assuming you have a VM with this name
$vm = Get-VMs -vmName "TestVM_catalogueEntry"
$psDTO = New-DTOTemplateObject -DTOTagName "PublishedService"

#Create a published service component, backed by a VM inventory
$psc = New-DTOTemplateObject -DTOTagName "PublishedServiceComponent"
$psc.PublishedServiceComponent.ref.id = $vm.VirtualMachineCollection.VirtualMachines[0].id
$psc.PublishedServiceComponent.ref.type = $vm.VirtualMachineCollection.VirtualMachines[0].type

#To add instance types (for public clouds)
#$allInstanceTypes = Get-VMInstanceTypesByManagementServerType -mstype "HP_CLOUD"
#$xsmallInstanceType = $allInstanceTypes.VMInstanceTypeCollection.VMInstanceTypes | Where-Object
{$_.name -match "standard.xsmall"}
#$smallInstance = $allInstanceTypes.VMInstanceTypeCollection.VMInstanceTypes | Where-Object {$_.name
-match "standard.small"}
#$instanceTypes = ($xsmallInstanceType.instanceType,$smallInstance.instanceType)
#Add-Member -InputObject $psc.PublishedServiceComponent -MemberType NoteProperty -Name "instanceTypes"
-Value $instanceTypes -Force

$psDTO.PublishedService.serviceComponents = @()
$psDTO.PublishedService.serviceComponents += $psc.PublishedServiceComponent

#Create a user; the only information we need is the loginId
$userDTO = New-DTOTemplateObject -DTOTagName "OwnerInfo"
$userDTO.OwnerInfo.id = -1
$userDTO.OwnerInfo.loginId = "superuser"
$userDTO.OwnerInfo.itContact = $false
$userDTO.OwnerInfo.primary = $false
$userDTO.OwnerInfo.email = $null
$userDTO.OwnerInfo.displayName = $null

#Clear out user(s); add new one we just created
$psDTO.PublishedService.serviceUsers = @()
$psDTO.PublishedService.serviceUsers += $userDTO.OwnerInfo

$createPS = New-PublishedService -psDto $psDTO

 

Create a Published Service from Azure


 

#set variables
$source_component_name = “azure-img-1″
$assigned_user = “Jim”
$published_service_name = “azure catalog item”
$availabilityset_name = “as1″
#Lookup source
$vm = Get-VMs -vmName $source_component_name
#Create a published service component DTO, backed by the VM we just found
$pscDTO = New-DTOTemplateObject -DTOTagName “PublishedServiceComponent”
$pscDTO.PublishedServiceComponent.name = $vm.VirtualMachineCollection.VirtualMachines[0].name
$pscDTO.PublishedServiceComponent.ref.displayName = $vm.VirtualMachineCollection.VirtualMachines[0].displayName
$pscDTO.PublishedServiceComponent.ref.id = $vm.VirtualMachineCollection.VirtualMachines[0].id
$pscDTO.PublishedServiceComponent.ref.type = $vm.VirtualMachineCollection.VirtualMachines[0].type
#Lookup all Azure instance types
$allInstanceTypes = Get-VMInstanceTypesByManagementServerType -mstype “MS_AZURE”
#Select only the first one (Basic_A0)
Add-Member -InputObject $pscDTO.PublishedServiceComponent -MemberType NoteProperty -Name “instanceTypes” -Value $allInstanceTypes.VMInstanceTypeCollection.VMInstanceTypes[0].instanceType -Force
#Add availability set
Add-Member -InputObject $pscDTO.PublishedServiceComponent -MemberType NoteProperty -Name “availabilitySet” -Value $availabilityset_name -Force
#Add endpoints
$endpoint1 = New-DTOTemplateObject -DTOTagName “VMEndpoint”
$endpoint1.VMEndpoint.name = “SSH”
$endpoint1.VMEndpoint.privatePort = “22”
$endpoint1.VMEndpoint.protocol = “tcp”
$endpoint1.VMEndpoint.publicPort = “33”
$endpoint2 = New-DTOTemplateObject -DTOTagName “VMEndpoint”
$endpoint2.VMEndpoint.name = “Custom Endpoint”
$endpoint2.VMEndpoint.privatePort = “54321”
$endpoint2.VMEndpoint.protocol = “udp”
$endpoint2.VMEndpoint.publicPort = $null #Set to null to have the public port be AUTO
$endpoints = @($endpoint1.VMEndpoint, $endpoint2.VMEndpoint)
Add-Member -InputObject $pscDTO.PublishedServiceComponent -MemberType NoteProperty -Name “endpoints” -Value $endpoints -Force
#Create a published service DTO and add the component to it
$psDTO = New-DTOTemplateObject -DTOTagName “PublishedService”
$psDTO.PublishedService.name = $published_service_name
$psDTO.PublishedService.deployType = “VAPP” #Configure to deploy as vApp
$psDTO.PublishedService.serviceComponents = @()
$psDTO.PublishedService.serviceComponents += $pscDTO.PublishedServiceComponent
#Create a user DTO; the only information we need is the loginId
$userDTO = New-DTOTemplateObject -DTOTagName “OwnerInfo”
$userDTO.OwnerInfo.loginId = $assigned_user
#Clear out user(s); add new one we just created
$psDTO.PublishedService.serviceUsers = @()
$psDTO.PublishedService.serviceUsers += $userDTO.OwnerInfo
#Add the service to the service catalog
$createPS = New-PublishedService -psDto $psDTO 


Create a Published Service from VMware

 

##### Creating a VMWare service
# Single component
# Have request attributes tie to component
#Locate the VM to use as published service component
$vms = Get-VMs -vmName “DevVM – 001″
$vm = $vms.VirtualMachineCollection.VirtualMachines[0]
#Create a published service component template
$psDTO = New-DTOTemplateObject -DTOTagName “PublishedService”
#Create a published service component, backed by a VM inventory
$psc = New-DTOTemplateObject -DTOTagName “PublishedServiceComponent”
$psc.PublishedServiceComponent.ref.id = $vm.id
$psc.PublishedServiceComponent.ref.type = $vm.type
$psDTO.PublishedService.serviceComponents = @()
$psDTO.PublishedService.serviceComponents += $psc.PublishedServiceComponent
#Create a user; the only information we need is the loginId
$userDTO = New-DTOTemplateObject -DTOTagName “OwnerInfo”
$userDTO.OwnerInfo.id = -1
$userDTO.OwnerInfo.loginId = “superuser”
$userDTO.OwnerInfo.itContact = $false
$userDTO.OwnerInfo.primary = $false
$userDTO.OwnerInfo.email = $null
$userDTO.OwnerInfo.displayName = $null
#Clear out user(s); add new one we just created
$psDTO.PublishedService.serviceUsers = @()
$psDTO.PublishedService.serviceUsers += $userDTO.OwnerInfo
$vmRequestAttribute1Template = New-DTOTemplateObject -DTOTagName “VMRequestAttribute”
$vmRequestAttribute2Template = New-DTOTemplateObject -DTOTagName “VMRequestAttribute”
$vmRequestAttribute3Template = New-DTOTemplateObject -DTOTagName “VMRequestAttribute”
#Attributes for the service component
$vmRequestAttribute1Template.VMRequestAttribute.attributeName = “SLA”
$vmRequestAttribute1Template.VMRequestAttribute.value = “Gold”
$vmRequestAttribute2Template.VMRequestAttribute.attributeName = “Cost Center”
$vmRequestAttribute2Template.VMRequestAttribute.value = “Toronto CS”
$vmRequestAttribute3Template.VMRequestAttribute.attributeName = “Primary Application”
$vmRequestAttribute3Template.VMRequestAttribute.value = “CIS App”
#Add the request attributes to service component
$requestAttributes = @($vmRequestAttribute1Template.VMRequestAttribute, $vmRequestAttribute2Template.VMRequestAttribute, $vmRequestAttribute3Template.VMRequestAttribute)
Add-Member -InputObject $psc.PublishedServiceComponent.serviceComponentSettings -MemberType NoteProperty -Name “requestAttributes” -Value $requestAttributes -Force
#Create the published service
$createPS = New-PublishedService -psDto $psDTO


 


Create a Published Service with Fencing from VMware

 

Port forwarding, external address via IP pool, DHCP

 

#Locate the VM to use as published servie component
$vms = Get-VMs -vmName “DevVM – 001″
$vm = $vms.VirtualMachineCollection.VirtualMachines[0]
#Create a published service component template
$psDTO = New-DTOTemplateObject -DTOTagName “PublishedService”
#Create a published service component, backed by a VM inventory
$psc = New-DTOTemplateObject -DTOTagName “PublishedServiceComponent”
$psc.PublishedServiceComponent.ref.id = $vm.id
$psc.PublishedServiceComponent.ref.type = $vm.type
$psDTO.PublishedService.serviceComponents = @()
$psDTO.PublishedService.serviceComponents += $psc.PublishedServiceComponent
#Create a user; the only information we need is the loginId
$userDTO = New-DTOTemplateObject -DTOTagName “OwnerInfo”
$userDTO.OwnerInfo.id = -1
$userDTO.OwnerInfo.loginId = “superuser”
$userDTO.OwnerInfo.itContact = $false
$userDTO.OwnerInfo.primary = $false
$userDTO.OwnerInfo.email = $null
$userDTO.OwnerInfo.displayName = $null
#Clear out user(s); add new one we just created
$psDTO.PublishedService.serviceUsers = @()
$psDTO.PublishedService.serviceUsers += $userDTO.OwnerInfo
#Grab one of the VM nics
$vmNic1 = $vm.networkCards | Where-Object {$_.label -eq “Network adapter 1″}
#Setup network fencing service properties
$psDTO.PublishedService.fenced = $true
$psDTO.PublishedService.internalRouterIp = “192.168.1.1”
$psDTO.PublishedService.externalRouterStaticallyAssigned = $true
#Setup port forward pairs
$portForwardPairTemplate1 = New-DTOTemplateObject -DTOTagName “PortForwardPair”
$portForwardPairTemplate1.PortForwardPair.publicPort = 80
$portForwardPairTemplate1.PortForwardPair.privatePort = 8080
$portForwardPairTemplate2 = New-DTOTemplateObject -DTOTagName “PortForwardPair”
$portForwardPairTemplate2.PortForwardPair.publicPort = 443
$portForwardPairTemplate2.PortForwardPair.privatePort = 8443
#Setup component NIC parameters
$componentNICTemplate = New-DTOTemplateObject -DTOTagName “PublishedServiceComponentNIC”
$componentNICTemplate.PublishedServiceComponentNIC.accessMode = “OUT_ONLY”
$componentNICTemplate.PublishedServiceComponentNIC.addressMode=”DHCP”
$componentNICTemplate.PublishedServiceComponentNIC.mac = $vmNic1.macAddress
$componentNICTemplate.PublishedServiceComponentNIC.hostName=””
$componentNICTemplate.PublishedServiceComponentNIC.portForwardPairs=@($portForwardPairTemplate1.PortForwardPair, $portForwardPairTemplate2.PortForwardPair)
#Add the component nic to the published service component
Add-Member -InputObject $psc.PublishedServiceComponent -MemberType NoteProperty -Name “componentNics” -Value @($componentNICTemplate.PublishedServiceComponentNIC) -Force
#Create the published service
$createPS = New-PublishedService -psDto $psDTO


 

No port forwarding, external address via DHCP, static assign address mode

 

#Locate the VM to use as published service component
$vms = Get-VMs -vmName “DevVM – 001″
$vm = $vms.VirtualMachineCollection.VirtualMachines[0]
#Create a published service component template
$psDTO = New-DTOTemplateObject -DTOTagName “PublishedService”
#Create a published service component, backed by a VM inventory
$psc = New-DTOTemplateObject -DTOTagName “PublishedServiceComponent”
$psc.PublishedServiceComponent.ref.id = $vm.id
$psc.PublishedServiceComponent.ref.type = $vm.type
$psDTO.PublishedService.serviceComponents = @()
$psDTO.PublishedService.serviceComponents += $psc.PublishedServiceComponent
#Create a user; the only information we need is the loginId
$userDTO = New-DTOTemplateObject -DTOTagName “OwnerInfo”
$userDTO.OwnerInfo.id = -1
$userDTO.OwnerInfo.loginId = “superuser”
$userDTO.OwnerInfo.itContact = $false
$userDTO.OwnerInfo.primary = $false
$userDTO.OwnerInfo.email = $null
$userDTO.OwnerInfo.displayName = $null
#Clear out user(s); add new one we just created
$psDTO.PublishedService.serviceUsers = @()
$psDTO.PublishedService.serviceUsers += $userDTO.OwnerInfo
#Grab one of the VM nics
$vmNic1 = $vm.networkCards | Where-Object {$_.label -eq “Network adapter 1″}
#Setup network fencing service properties
$psDTO.PublishedService.fenced = $true
$psDTO.PublishedService.internalRouterIp = “192.168.1.1”
$psDTO.PublishedService.externalRouterStaticallyAssigned = $false
#Setup component NIC parameters
$componentNICTemplate = New-DTOTemplateObject -DTOTagName “PublishedServiceComponentNIC”
$componentNICTemplate.PublishedServiceComponentNIC.accessMode = “OUT_ONLY”
$componentNICTemplate.PublishedServiceComponentNIC.addressMode=”STATIC_PUSH”
$componentNICTemplate.PublishedServiceComponentNIC.staticIp = “192.168.1.2”
$componentNICTemplate.PublishedServiceComponentNIC.mac = $vmNic1.macAddress
$componentNICTemplate.PublishedServiceComponentNIC.hostName=”test”
$componentNICTemplate.PublishedServiceComponentNIC.portForwardPairs=@()
#Add the component nic to the published service component
Add-Member -InputObject $psc.PublishedServiceComponent -MemberType NoteProperty -Name “componentNics” -Value @($componentNICTemplate.PublishedServiceComponentNIC) -Force
#Create the published service
$createPS = New-PublishedService -psDto $psDTO


 

UPDATE Method

 

Update Published Service Name

 

$existingPS = Get-PublishedServiceByName -name “Published Service #1″
$existingPS.PublishedService.name = “New Name”
$updatedPublishedService = Update-PublishedService -psId $existingPS.PublishedService.id -updatePs $existingPS

 


Change Published Service Instance Type

 

#Changing instance types
$existingPS = Get-PublishedServiceByName -name “Published Service #1″
$serviceComponent = $existingPS.PublishedService.serviceComponents | Where-Object {$_.name -match “Windows 2008 R2 – webserver”}
#Dealing with instances type
#$allInstanceTypes = Get-VMInstanceTypesByManagementServerType -mstype “HP_CLOUD”
#$xsmallInstanceType = $allInstanceTypes.VMInstanceTypeCollection.VMInstanceTypes | Where-Object {$_.name -match “standard.xsmall”}
#$smallInstance = $allInstanceTypes.VMInstanceTypeCollection.VMInstanceTypes | Where-Object {$_.name -match “standard.small”}
#Override with said instance types
#$serviceComponent.instanceTypes =@($xsmallInstanceType.instanceType,$smallInstance.instanceType)
#or add to
#$serviceComponent.instanceTypes +=($xsmallInstanceType.instanceType,$smallInstance.instanceType)
$updatedPublishedService = Update-PublishedService -psId $existingPS.PublishedService.id -updatePs $existingPS

 

Remove Method

  

Delete a Published Service By ID

 

Remove-PublishedService -psId 304299