Sample Code
The following section provides sample code to perform common scenarios or tasks with the Commander API.
Authenticate
- Logging in with JWT and renewing the token for subsequent API calls.
import requests baseurl = "https://localhost:8443" username = "" password = "" #Get a token tokenurl = "/rest/v3/tokens" tokenposturl = baseurl+tokenurl print( 'Token Get URL: ' + tokenposturl) tokenbody = { "username": username, "password": password} tokenresult = requests.post(tokenposturl, json=tokenbody , verify=False) tokenresult = tokenresult.json() authtoken = tokenresult["token"] print ('Token aquired: ' + authtoken) #Refresh an existing token tokenrefreshurl = "/rest/v3/tokens/refresh" tokenposturl = baseurl+tokenrefreshurl tokenrefreshbody = { "token": authtoken} tokenrefreshresult = requests.post(tokenposturl, json=tokenrefreshbody , verify=False) tokenrefreshresult = tokenrefreshresult.json() authtoken = tokenrefreshresult["token"] print('Refreshed Token Aquired:' + authtoken)
$BaseURL = "https://localhost:8443" $user = "" $pass = "" #Get a token Write-host "Requesting a new token" $TokenBody = "{ ""username"": ""$user"", ""password"": ""$pass"" }" $Tokenendpoint = "/rest/v3/tokens" $TokenpostURL = $BaseURL + $Tokenendpoint $Tokenresult = Invoke-RestMethod $TokenpostURL -Method POST -Body $TokenBody -ContentType 'application/json' -SkipCertificateCheck IF ($Tokenresult) { $authToken = $Tokenresult.token $headers = @{Authorization = ("Bearer $authToken") } Write-host "Token Acquired" } else { Write-host "Failed to aquire token for $user" } #Refresh JWT Token $refreshURL = $BaseURL+"/rest/v3/tokens/refresh" $refreshBody = "{ ""token"": ""$authToken""}" $refreshResult = Invoke-RestMethod -Method POST $refreshURL -Body $refreshBody -ContentType 'application/json' -SkipCertificateCheck $authToken = $refreshResult.token $headers = @{"Authorization" = "Bearer $authToken" }
Add users to an organization
In this scenario, you create an organization and a user, and then add the user as a member of the organization.
- Create an organization named
myNewOrganization
. - Create a user with username
mynewuser
and passwordsecret
. - Add the user to the organization.
url = 'https://localhost:8443/rest/v3/organizations' payload = {"name":"myNewOrganization"} response = requests.post(url, headers=header, json=payload, verify=False)
$request = @{ "name"="myNewOrganization" } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/organizations" $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/users' payload = {"name":"mynewuser", "password":"secret"} response = requests.post(url, headers=header, json=payload, verify=False)
$request = @{ "name"="mynewuser" "password"="secret" } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/users" $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
The user mynewuser
is added as a member of the organization myNewOrganization
. The user is given a role of CUSTOMER
in the organization.
url = 'https://localhost:8443/rest/v3/organizations/' + "myNewOrganization" + '/' + 'members' payload = {"username":"mynewuser", "role":"CUSTOMER"} response = requests.post(url, headers=header, json=payload, verify=False)
$request = @{ "username"="mynewuser" "role"="CUSTOMER" } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/organizations/" + "myNewOrganization" + "/members" $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Apply custom attributes to virtual machines
In this scenario, you look up a virtual machine by name and apply a custom attribute.
- Filter the collection of virtual machines by name to find the virtual machine ID.
- Apply the custom attribute to the virtual machine.
url = 'https://localhost:8443/rest/v3/virtual-machines?filter=name -eq ' + vm_name response = requests.get(url,headers=headers,verify=False) data = response.json() vm_id = (data['items'][0]['id'])
try { $vm_name = "centos-vm" $url = "https://localhost:8443/rest/v3/virtual-machines?filter=name -eq " + $vm_name $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $vm_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
The custom attribute named SLA
is applied to the virtual machine. The custom attribute is given a value of Gold
.
url = 'https://localhost:8443/rest/v3/virtual-machines/' + str(vm_id) + '/attributes' payload = {"name":"SLA", "value":"Gold"} response = requests.post(url, headers=headers, json=payload, verify=False)
$request = @{ "name"="SLA" "value"="Gold" } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/virtual-machines/" + $vm_id.ToString() + "/attributes" $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Assign an organizational owner to a virtual machine
In this scenario, you look up a virtual machine by name and assign it an organizational owner.
- Filter the collection of virtual machines by name to find the virtual machine ID.
- Assign the virtual machine to the organization.
url = 'https://localhost:8443/rest/v3/virtual-machines?filter=name -eq ' + vm_name response = requests.get(url,headers=headers,verify=False) data = response.json() vm_id = (data['items'][0]['id'])
try { $vm_name = "centos-vm" $url = "https://localhost:8443/rest/v3/virtual-machines?filter=name -eq " + $vm_name $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $vm_id = $jsonResponse.items[1].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
The organization myNewOrganization
is assigned as the owner of the virtual machine centos-vm
.
url = 'https://localhost:8443/rest/v3/virtual-machines/' + str(vm_id) + '/organization' payload = {"name":"myNewOrganization"} response = requests.put(url,headers=headers,json=payload,verify=False)
$request = @{ "name"="myNewOrganization" } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/virtual-machines/" + $vm_id.ToString() + "/organization" $responseData = Invoke-WebRequest -Uri $url -Method Put -Headers $headers -Body $jsonRequest } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Deploy a virtual machine
In this scenario, you select a service from the catalog and generate its request form. Reconfigure the request form by increasing the number of CPUs, then submit it. Because there is a deployment destination and an approval workflow, the virtual machine auto-deploys when the service request is submitted.
- Find the ID of the service named
VMware
from the service catalog. - Generate the request form for the service.
- Reconfigure the request form to increase the number of CPUs.
- Submit the complete service request.
url = 'https://localhost:8443/rest/v3/services?filter=name -eq ' + "VMware" response = requests.get(url,headers=headers,verify=False) data = response.json() service_id = data['items'][0]['id']
try { $url = "https://localhost:8443/rest/v3/services?filter=name -eq " + "VMware" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $service_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
The request form is a JSON document that contains the configurable attributes of the service. The administrator controls which attributes of each service are configurable, so the request form varies by service.
url = 'https://localhost:8443/rest/v3/services/' + str(service_id) + '/request-form' response = requests.get(url,headers=headers,verify=False) request_form = response.json()
try { $url = "https://localhost:8443/rest/v3/services/" + $service_id.ToString() + "/request-form" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $requestForm = $responseData | ConvertFrom-JSON } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
In this scenario, the administrator has made the CPU Count a configurable property of the service. The CPU Count may be reconfigured, but it isn't required.
request_form['components'][0]['CPU Count'] = 2
$requestForm.components[0]."CPU Count" = 2
url = 'https://localhost:8443/rest/v3/service-requests' payload = request_form response = requests.post(url,headers=headers,json=payload,verify=False)
try { $url = "https://localhost:8443/rest/v3/service-requests" $jsonRequest = $requestForm | ConvertTo-JSON $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Create an AWS deployment destination
In this scenario, you create an AWS deployment destination.
To create a deployment destination, you find the supporting resources for the cloud account type, and reference those resources in the creation request.
- Find the cloud account that the target of the deployment destination belongs to, filtering by cloud account type.
- Find the region that the target belongs to, filtering by cloud account and region name.
- Find the virtual cloud that's the target of the destination, filtering by cloud account and region.
- Find the subnets applicable to the destination, filtering by the target virtual cloud.
- Optionally, add a key pair to the destination. To find key pairs applicable to the destination, filter by the cloud account.
- Optionally, add security groups to the destination. To find security groups applicable to the target, filter by the virtual cloud.
- In the common section of the deployment destination creation request, configure the cloud account, the target virtual cloud, and a unique name for the destination. Configure the AWS specific resource references in the
aws
property, and submit the request. Becauseusers
andorganizations
weren't configured, the deployment destination is globally accessible.
url = 'https://localhost:8443/rest/v3/cloud-accounts?filter=type -eq AWS' data = response.json() cloud_account_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/cloud-accounts?filter=type -eq AWS" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $cloud_account_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/regions?filter=(cloud_account_id -eq ' + cloud_account_id + ')' + ' -and ' + '(name -eq us-east-1)' data = response.json() region_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/regions?filter=(cloud_account_id -eq " + $cloud_account_id + ")" + " -and " + "(name -eq us-east-1)" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $region_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/virtual-clouds?filter=(cloud_account_id -eq ' + cloud_account_id + ')' + ' -and ' + '(region_id -eq ' + region_id + ')' data = response.json() target_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/virtual-clouds?filter=(cloud_account_id -eq " + $cloud_account_id + ")" + " -and " + "(region_id -eq " + $region_id + ")" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $target_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/subnets?filter=virtual_cloud_id -eq ' + target_id data = response.json() subnet_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/subnets?filter=virtual_cloud_id -eq " + $target_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $subnet_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/key-pairs?filter=cloud_account_id -eq ' + cloud_account_id data = response.json() key_pair_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/key-pairs?filter=cloud_account_id -eq " + $cloud_account_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $key_pair_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/security-groups?filter=virtual_cloud_id -eq ' + virtual_cloud_id data = response.json() security_group_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/security-groups?filter=virtual_cloud_id -eq " + $virtual_cloud_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $security_group_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
{ "name":"AWS-deployment-destination", "cloud_account" : { "id": 15564808 }, "target": { "id": 15565024, "type": "VIRTUAL_CLOUD" }, "users": [], "organizations": [], "placement_attributes": [], "aws": { "key_pair": { "id": 93323265 }, "security_groups: [ { "id": 6332142 } ], "iam_role": "UserAccess-Role", "subnets": [ { "id": 14352408 } ], "region": { "id": 14352412 } } }
url = 'https://localhost:8443/rest/v3/deployment-destinations payload = {"name": "AWS-deployment-destination, ...} response = requests.post(url, headers=header, json=payload, verify=False)
$request = @{ "name": "AWS-deployment-destination", ... } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest $statusCode $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Create a VMware deployment destination
In this scenario, you create a VMware deployment destination.
To create a deployment destination, you find the supporting resources for the cloud account type, and reference those resources in the creation request. In this scenario, the destination targets a host, and you use both datastores and datastore clusters as storage. You assign both standard networks and distributed portgroups to the destination.
- Find the cloud account that the target of the deployment destination belongs to, filtering by cloud account type.
- Find the datacenter that the target belongs to, filtering by cloud account and datacenter name.
- Find the host that's the target of the destination, filtering by cloud account and datacenter.
- Find the storage to use for the destination. You can use any combination of datastores and datastore clusters as storage. To find storage that's valid for the destination, filter the datastores and datastore clusters by the target host.
- Since you're not connecting to the same network as the source, find the networks to use for the destination. You can use any combination of standard networks and distributed portgroups, both of which are available in the networks collection. To find networks that are valid for the destination, filter by the target host.
- In the common section of the deployment destination create request, reference the cloud account, the target host, and configure a unique name for the destination. In the
vmware_vcenter
property, configure the datacenter as the location, and reference the storage resources. Configure the destination to not use the same networks as the source, and configure the networks. Don't assign NICs a static IP address. Disable fenced networking, and submit the request. Because users and organizations weren't configured for the destination, the destination is globally accessible.
url = 'https://localhost:8443/rest/v3/cloud-accounts?filter=type -eq VMWARE_VCENTER' data = response.json() cloud_account_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/cloud-accounts?filter=type -eq VMWARE_VCENTER" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $cloud_account_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/datacenters?filter=(cloud_account_id -eq ' + cloud_account_id + ')' + ' -and ' + '(name -eq Shared)' data = response.json() datacenter_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/datacenters?filter=(cloud_account_id -eq " + $cloud_account_id + ")" + " -and " + "(name -eq Shared)" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $datacenter_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/hosts?filter=(cloud_account_id -eq ' + cloud_account_id + ')' + ' -and ' + '(datacenter_id -eq ' + datacenter_id + ')' data = response.json() target_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/hosts?filter=(cloud_account_id -eq " + $cloud_account_id + ")" + " -and " + "(datacenter_id -eq " + $datacenter_id + ")" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $target_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/datastores?filter=host_id -eq ' + host_id data = response.json() datastore_id = (data['items'][0]['id']) url = 'https://localhost:8443/rest/v3/datastore-clusters?filter=datacenter_id -eq ' + datacenter_id data = response.json() datastore_cluster_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/datastores?filter=host_id -eq " + $host_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $datastore_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ } try { $url = "https://localhost:8443/rest/v3/datastore-clusters?filter=datacenter_id -eq " + $datacenter_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $datastore_cluster_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/networks?filter=host_id -eq ' + host_id data = response.json() network_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/networks?filter=host_id -eq " + $host_id $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $network_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
{ "name":"VMware-deployment-destination", "cloud_account" : { "id": 15564808 }, "target": { "id": 15565024, "type": "HOST" }, "users": [], "organizations": [], "placement_attributes": [], "vmware_vcenter": { "location": { "id": 196947, "type": "DATACENTER" }, "connect_to_same_network_as_source_service": false, "networks": [ { "id": 197342, "type": "DISTRIBUTED_PORTGROUP" }, { "id": 197341, "type": "NETWORK" } ], "assign_nics_static_ip_from_pool": false, "enable_fenced_networks": false, "fenced_networking_configuration": null, "storage": [ { "id": 196993, "type": "DATASTORE" }, { "id": 12345, "type": "DATASTORE_CLUSTER" } ], "disk_format": "SAME_AS_SOURCE", "calculate_capacity_using": "PEAK" } }
url = 'https://localhost:8443/rest/v3/deployment-destinations payload = {"name": "VMware-deployment-destination, ...} response = requests.post(url, headers=header, json=payload, verify=False)
$request = @{ "name": "VMware-deployment-destination", ... } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations $responseData = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $jsonRequest $statusCode $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Add users and organizations to a deployment destination
In this scenario, you modify a deployment destination to make it accessible to a limited set of users and organizations. You update the users and organizations by replacing the existing sets with new sets.
- Get the current set of users and organizations the destination is accessible to.
- Replace the existing set of users and organizations with new sets, and submit the update request. The destination is accessible only to the configured users and organizations. It isn't globally accessible.
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 response = requests.get(url,headers=headers,verify=False) data = response.json() users = (data['users']) organizations = (data['organizations'])
try { $url = "https://localhost:8443/rest/v3/deployment-destinations/12345 $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $users = $jsonResponse.users $organizations = $jsonResponse.organizations } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 payload = {"users":["existingUser", "newUser"], "organizations": ["existingOrganization", "newOrganization"]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "users"=["existingUser", "newUser"], "organizations"=["existingOrganization", "newOrganization"] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations/12345 $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Add placement attributes to a deployment destination
In this scenario, you update a deployment destination by adding placement attributes. You add one provided placement attribute, and one selectable placement attribute. To update placement attributes, you replace the existing set with a new set.
- Get the current set of placement attributes associated with the destination.
- Add the new placement attributes to the set, and submit the update request. Because the attribute
fixed-placement-attribute
is a provided placement attribute, it has no value. Theselectable-placement-attribute
has a value ofsome value
.
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 response = requests.get(url,headers=headers,verify=False) data = response.json() placement_attributes = (data['placement_attributes'])
try { $url = "https://localhost:8443/rest/v3/deployment-destinations $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $placement_attributes = $jsonResponse.placement_attributes } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 payload = {"placement_attributes":[{"name":"fixed-placement-attribute", "values": []},{"name":"selectable-placement-attribute", "values":["some value"]}]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "placement_attributes"=[ { "name":"fixed-placement-attribute", "values": [] }, { "name": "selectable-placement-attribute", "values": ["some value"] } ] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers -Body $jsonRequest $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Configure per-destination quotas for organizations
In this scenario, you configure a destination quota for an organization. The organization is named myOrganization
and the deployment destination is named VMWare-dest
. You assign the organization to the deployment destination, and update the organization with a quota for the destination. Like global quotas, a destination can have either a cost quota or a resource quota, but not both. In this example, you configure a cost quota for the organization.
- Filter the collection of deployment destinations by name to find the deployment destination ID.
- Assign the organization to the deployment destination.
- Update the organization with a cost quota for the deployment destination. Reference the deployment destination ID, and configure a quota limit of $2000.00 for the organization.
url = 'https://localhost:8443/rest/v3/deployment-destinations?filter=name -eq VMware-dest' response = requests.get(url,headers=headers,verify=False) data = response.json() destination_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/deployment-destinations?filter=name -eq VMware-dest" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $destination_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 payload = {"organizations": ["myOrganization"]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "organizations"=["myOrganization"] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations/12345 $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/organizations/myOrganization payload = {"destination_quotas": [{"deployment_destination_id": 12345, "cost_quota":{"daily_cost": 2000.00}}]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "destination_quotas"=[{"deployment_destination_id": 12345, "cost_quota":{"daily_cost": 2000.00}}] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/organizations/myOrganization $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
Configure per-destination quotas for organization members
In this scenario, you configure a destination quota for an organization member. You assign the organization to the deployment destination, and update the organization member with a quota for the destination. Because the organization has a destination cost quota, the organization member can either have a destination cost quota, or no quota.
In this example, the user myOrgMember
is a member of organization myOrganization
. The deployment destination is named VMware-dest
.
- Filter the collection of deployment destinations by name to find the deployment destination ID.
- Assign the organization to the deployment destination.
- Update the organization member with a cost quota for the deployment destination. Reference the deployment destination ID, and configure a quota limit of $100.00 for the organization member.
url = 'https://localhost:8443/rest/v3/deployment-destinations?filter=name -eq VMware-dest' response = requests.get(url,headers=headers,verify=False) data = response.json() destination_id = (data['items'][0]['id'])
try { $url = "https://localhost:8443/rest/v3/deployment-destinations?filter=name -eq VMware-dest" $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers $jsonResponse = $responseData | ConvertFrom-JSON $destination_id = $jsonResponse.items[0].id } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/deployment-destinations/12345 payload = {"organizations": ["myOrganization"]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "organizations"=["myOrganization"] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/deployment-destinations/12345 $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }
url = 'https://localhost:8443/rest/v3/organizations/myOrganization/members/myOrgMember payload = {"destination_quotas": [{"deployment_destination_id": 12345, "cost_quota":{"daily_cost": 100.00}}]} response = requests.patch(url, headers=header, json=payload, verify=False)
$request = @{ "destination_quotas"=[{"deployment_destination_id": 12345, "cost_quota":{"daily_cost": 100.00}}] } $jsonRequest = $request | ConvertTo-Json try { $url = "https://localhost:8443/rest/v3/organizations/myOrganization/members/myOrgMember $responseData = Invoke-WebRequest -Uri $url -Method Patch -Headers $headers $statusCode = $responseData.StatusCode } catch { $statusCode = $_.Exception.Response.StatusCode.value__ }