From 2178db8dc73898d991da82f054f4cdf04e7273c8 Mon Sep 17 00:00:00 2001 From: Viraj Indasrao Date: Thu, 12 Jul 2018 16:51:10 +0530 Subject: [PATCH 1/3] Change lease date Signed-off-by: Viraj Indasrao --- vrealize/actions.go | 27 ++++++++++++++++++ vrealize/resource.go | 65 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/vrealize/actions.go b/vrealize/actions.go index e4416f2..9301912 100644 --- a/vrealize/actions.go +++ b/vrealize/actions.go @@ -97,3 +97,30 @@ func (s byLength) Len() int { func (s byLength) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +// getDeploymentLeaseActionLinks returns a MAP of GET/POST action links of change lease +func (vRAClient *APIClient) getDeploymentLeaseActionLinks(resourceData *ResourceView) (map[string]interface{}) { + //Set resource power-off URL label + const templateRel = "GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}" + const postRel = "POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}" + //Set get action URL function call + actionData := vRAClient.GetDeploymentActionLinks(resourceData, templateRel, postRel) + return actionData +} + +// GetDeploymentActionLinks determines change lease action links from resourceView template +func (vRAClient *APIClient) GetDeploymentActionLinks(resourceData *ResourceView, templateRel string, postRel string) map[string]interface{} { + data := map[string]interface{}{} + for _, value := range resourceData.Content { + resourceMap := value.(map[string]interface{}) + if resourceMap["resourceType"] == "composition.resource.type.deployment" { + resourceSpecificLinks := resourceMap["links"].([]interface{}) + data["template_url"] = readActionLink(resourceSpecificLinks, templateRel) + data["post_url"] = readActionLink(resourceSpecificLinks, postRel) + break + } + + } + return data +} + diff --git a/vrealize/resource.go b/vrealize/resource.go index 8a98aad..59aec09 100644 --- a/vrealize/resource.go +++ b/vrealize/resource.go @@ -110,11 +110,13 @@ func setResourceSchema() map[string]*schema.Schema { "catalog_name": { Type: schema.TypeString, Optional: true, + ForceNew: true, }, "catalog_id": { Type: schema.TypeString, Computed: true, Optional: true, + ForceNew: true, }, "businessgroup_id": { Type: schema.TypeString, @@ -129,14 +131,28 @@ func setResourceSchema() map[string]*schema.Schema { "request_status": { Type: schema.TypeString, Computed: true, - ForceNew: true, }, "failed_message": { Type: schema.TypeString, Computed: true, - ForceNew: true, Optional: true, }, + "lease": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "start": &schema.Schema{ + Optional: true, + Type: schema.TypeString, + }, + "end": &schema.Schema{ + Optional: true, + Type: schema.TypeString, + }, + }, + }, + }, "deployment_configuration": { Type: schema.TypeMap, Optional: true, @@ -410,6 +426,37 @@ func readVMReconfigActionUrls(GetDeploymentStateData *ResourceView) map[string]i return urlMap } +// updateDeploymentLeaseTime function updates a end time of deployment lease +// It returns error on failure at any step of lease time update +func updateDeploymentLeaseTime(d *schema.ResourceData, meta interface{}) error { + //Get the ID of the catalog request that was used to provision this Deployment. + catalogItemRequestID := d.Id() + //Get client handle + vRAClient := meta.(*APIClient) + + // Get deployment details + GetDeploymentStateData, errTemplate := vRAClient.GetDeploymentState(catalogItemRequestID) + if errTemplate != nil { + return fmt.Errorf("Resource view failed to load: %v", errTemplate) + } + + // Get change lease GET/POST links + leaseActionLinks := vRAClient.getDeploymentLeaseActionLinks(GetDeploymentStateData) + // Get change lease template + leaseActionTemplate, err := getResourceConfigTemplate(leaseActionLinks["template_url"].(string), d, meta) + if err != nil { + return fmt.Errorf("lease template loeading failed: %v", err) + } + + // Update template value + leaseActionTemplate.Data["provider-ExpirationDate"] = d.Get("lease.end") + // POST changes + changeLeaseErr := postResourceConfig(d, leaseActionLinks["post_url"].(string), leaseActionTemplate, meta) + if changeLeaseErr != nil { + return fmt.Errorf("change lease post call failed: %v", changeLeaseErr) + } + return nil +} // Terraform call - terraform apply // This function updates the state of a vRA 7 Deployment when changes to a Terraform file are applied. // The update is performed on the Deployment using supported (day-2) actions. @@ -419,6 +466,17 @@ func updateResource(d *schema.ResourceData, meta interface{}) error { //Get client handle vRAClient := meta.(*APIClient) + // Check lease date changes + if d.HasChange("lease.end") { + leaseTimeErr := updateDeploymentLeaseTime(d, meta) + if leaseTimeErr != nil { + // Reset lease dates and return error + // if error is returned from updateDeploymentLeaseTime() + oldData, _ := d.GetChange("lease") + d.Set("lease", oldData) + return leaseTimeErr + } + } //If any change made in resource_configuration. if d.HasChange("resource_configuration") { //Read resource template @@ -549,6 +607,9 @@ func readResource(d *schema.ResourceData, meta interface{}) error { for _, value := range GetDeploymentStateData.Content { resourceMap := value.(map[string]interface{}) + if resourceMap["resourceType"] == "composition.resource.type.deployment" { + d.Set("lease", resourceMap["lease"].(map[string]interface{})) + } resourceSpecificData := resourceMap["data"].(map[string]interface{}) resourceSpecificLinks := resourceMap["links"].([]interface{}) if resourceSpecificData["Component"] != nil { From 0323c3d26726146fb46ba5065ec8216fecc33cbd Mon Sep 17 00:00:00 2001 From: Viraj Indasrao Date: Thu, 12 Jul 2018 17:03:06 +0530 Subject: [PATCH 2/3] Change lease date - minor change in function name Signed-off-by: Viraj Indasrao --- vrealize/resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vrealize/resource.go b/vrealize/resource.go index 59aec09..b3bc4f4 100644 --- a/vrealize/resource.go +++ b/vrealize/resource.go @@ -428,7 +428,7 @@ func readVMReconfigActionUrls(GetDeploymentStateData *ResourceView) map[string]i // updateDeploymentLeaseTime function updates a end time of deployment lease // It returns error on failure at any step of lease time update -func updateDeploymentLeaseTime(d *schema.ResourceData, meta interface{}) error { +func updateDeploymentLease(d *schema.ResourceData, meta interface{}) error { //Get the ID of the catalog request that was used to provision this Deployment. catalogItemRequestID := d.Id() //Get client handle @@ -468,7 +468,7 @@ func updateResource(d *schema.ResourceData, meta interface{}) error { // Check lease date changes if d.HasChange("lease.end") { - leaseTimeErr := updateDeploymentLeaseTime(d, meta) + leaseTimeErr := updateDeploymentLease(d, meta) if leaseTimeErr != nil { // Reset lease dates and return error // if error is returned from updateDeploymentLeaseTime() From 3c82a28fb120faa694ca0144441e1f0fd812d732 Mon Sep 17 00:00:00 2001 From: Viraj Indasrao Date: Fri, 3 Aug 2018 12:19:39 +0530 Subject: [PATCH 3/3] Unit test cases Signed-off-by: Viraj Indasrao --- vrealize/action_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/vrealize/action_test.go b/vrealize/action_test.go index 262e5dc..d999e85 100644 --- a/vrealize/action_test.go +++ b/vrealize/action_test.go @@ -5,6 +5,7 @@ import ( "fmt" "gopkg.in/jarcoal/httpmock.v1" "testing" + "encoding/json" ) //var client APIClient @@ -178,3 +179,40 @@ func TestPowerOffAction(t *testing.T) { t.Errorf("Fail to get destroy action template exception.") } } + +func TestGetActionTemplate(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + resourceView := new(ResourceView) + str := `{"links":[],"content":[{"@type":"CatalogResourceView","resourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","iconId":"502efc1b-d5ce-4ef9-99ee-d4e2a741747c","name":"CentOS 6.3 - IPAM EXT-95563173","description":"","status":null,"catalogItemId":"502efc1b-d5ce-4ef9-99ee-d4e2a741747c","catalogItemLabel":"CentOS 6.3 - IPAM EXT","requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"composition.resource.type.deployment","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:26:42.102Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":null,"hasChildren":true,"data":{},"links":[{"@type":"link","rel":"GET: Catalog Item","href":"http://localhost/catalog-service/api/consumer/entitledCatalogItemViews/502efc1b-d5ce-4ef9-99ee-d4e2a741747c"},{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/561be422-ece6-4316-8acb-a8f3dbb8ed0c/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/561be422-ece6-4316-8acb-a8f3dbb8ed0c/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changeowner.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/59249166-e427-4082-a3dc-eb7223bb2de1/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changeowner.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/59249166-e427-4082-a3dc-eb7223bb2de1/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.destroy.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/3da0ca14-e7e2-4d7b-89cb-c6db57440d72/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.destroy.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/3da0ca14-e7e2-4d7b-89cb-c6db57440d72/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.archive.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/9725d56e-461a-471a-be00-b1856681c6d0/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.archive.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/9725d56e-461a-471a-be00-b1856681c6d0/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scalein.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/85e090f9-9529-4101-9691-6bab1b0a1f77/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scalein.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/85e090f9-9529-4101-9691-6bab1b0a1f77/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scaleout.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/ab5795f5-32ad-4f6c-8598-1d3a7d190caa/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scaleout.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/ab5795f5-32ad-4f6c-8598-1d3a7d190caa/requests"},{"@type":"link","rel":"GET: Child Resources","href":"http://localhost/catalog-service/api/consumer/resourceViews?managedOnly=false&withExtendedData=true&withOperations=true&%24filter=parentResource%20eq%20%27b313acd6-0738-439c-b601-e3ebf9ebb49b%27"}]},{"@type":"CatalogResourceView","resourceId":"51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5","iconId":"Infrastructure.CatalogItem.Machine.Virtual.vSphere","name":"Content0061","description":"Basic IaaS CentOS Machine","status":"Missing","catalogItemId":null,"catalogItemLabel":null,"requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"Infrastructure.Virtual","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:33:16.686Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","hasChildren":false,"data":{"Component":"CentOS_6.3","DISK_VOLUMES":[{"componentTypeId":"com.vmware.csp.component.iaas.proxy.provider","componentId":null,"classId":"dynamicops.api.model.DiskInputModel","typeFilter":null,"data":{"DISK_CAPACITY":3,"DISK_INPUT_ID":"DISK_INPUT_ID1","DISK_LABEL":"Hard disk 1"}}],"Destroy":true,"EXTERNAL_REFERENCE_ID":"vm-773","IS_COMPONENT_MACHINE":false,"MachineBlueprintName":"CentOS 6.3 - IPAM EXT","MachineCPU":1,"MachineDailyCost":0,"MachineDestructionDate":null,"MachineExpirationDate":null,"MachineGroupName":"Content","MachineGuestOperatingSystem":"CentOS 4/5/6/7 (64-bit)","MachineInterfaceDisplayName":"vSphere (vCenter)","MachineInterfaceType":"vSphere","MachineMemory":512,"MachineName":"Content0061","MachineReservationName":"IPAM Sandbox","MachineStorage":3,"MachineType":"Virtual","NETWORK_LIST":[{"componentTypeId":"com.vmware.csp.component.iaas.proxy.provider","componentId":null,"classId":"dynamicops.api.model.NetworkViewModel","typeFilter":null,"data":{"NETWORK_ADDRESS":"192.168.110.150","NETWORK_MAC_ADDRESS":"00:50:56:ae:31:bd","NETWORK_NAME":"VM Network","NETWORK_NETWORK_NAME":"ipamext1921681100","NETWORK_PROFILE":"ipam-ext-192.168.110.0"}}],"SNAPSHOT_LIST":[],"Unregister":true,"VirtualMachine.Admin.UUID":"502e9fb3-6f0d-0b1e-f90f-a769fd406620","endpointExternalReferenceId":"d322b019-58d4-4d6f-9f8b-d28695a716c0","ip_address":"192.168.110.150","machineId":"4fc33663-992d-49f8-af17-df7ce4831aa0"},"links":[{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET: Parent Resource","href":"http://localhost/catalog-service/api/consumer/resourceViews/b313acd6-0738-439c-b601-e3ebf9ebb49b"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.virtual.Destroy}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/654b4c71-e84f-40c7-9439-fd409fea7323/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.virtual.Destroy}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/654b4c71-e84f-40c7-9439-fd409fea7323/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.machine.Unregister}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/f3ae9408-885a-4a3a-9200-43366f2aa163/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.machine.Unregister}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/f3ae9408-885a-4a3a-9200-43366f2aa163/requests"}]},{"@type":"CatalogResourceView","resourceId":"169b596f-e4c0-4b25-ba44-18cb19c0fd65","iconId":"existing_network","name":"ipamext1921681100","description":"Infoblox External Network","status":null,"catalogItemId":null,"catalogItemLabel":null,"requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"Infrastructure.Network.Network.Existing","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:27:17.526Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","hasChildren":false,"data":{"Description":"Infoblox External Network","IPAMEndpointId":"1c2b6237-540a-43c3-8c06-b37a1d274b44","IPAMEndpointName":"Infoblox - nios01a","Name":"ipamext1921681100","_archiveDays":5,"_hasChildren":false,"_leaseDays":null,"_number_of_instances":1,"dns":{"componentTypeId":"com.vmware.csp.iaas.blueprint.service","componentId":null,"classId":"Infrastructure.Network.Network.DnsWins","typeFilter":null,"data":{"alternate_wins":null,"dns_search_suffix":null,"dns_suffix":null,"preferred_wins":null,"primary_dns":null,"secondary_dns":null}},"gateway":null,"ip_ranges":[{"componentTypeId":"com.vmware.csp.iaas.blueprint.service","componentId":null,"classId":"Infrastructure.Network.Network.IpRanges","typeFilter":null,"data":{"description":"","end_ip":"","externalId":"network/default-vra/192.168.110.0/24","id":"b078d23a-1c3d-4458-ab57-e352c80e6d55","name":"192.168.110.0/24","start_ip":""}}],"network_profile":"ipam-ext-192.168.110.0","providerBindingId":"CentOS63Infoblox","providerId":"2fbaabc5-3a48-488a-9f2a-a42616345445","subnet_mask":"255.255.255.0","subtenantId":"53619006-56bb-4788-9723-9eab79752cc1"},"links":[{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET: Parent Resource","href":"http://localhost/catalog-service/api/consumer/resourceViews/b313acd6-0738-439c-b601-e3ebf9ebb49b"}]}],"metadata":{"size":20,"totalElements":3,"totalPages":1,"number":1,"offset":0}}` + json.Unmarshal([]byte(str), &resourceView) + client.GetActionTemplate(resourceView, "") + + httpmock.RegisterResponder("GET", "http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/3da0ca14-e7e2-4d7b-89cb-c6db57440d72/requests/template", + httpmock.NewErrorResponder(errors.New(`{"errors":[{"code":50505,"source":null,"message":"System exception.","systemMessage":null,"moreInfoUrl":null}]}`))) + actionURL := "GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.destroy.name}" + _,_, err := client.GetActionTemplate(resourceView, actionURL) + if err == nil { + t.Errorf("error expected while fetching action template") + } +} + +func TestDeploymentLeaseActionLinks(t *testing.T) { + // check deployment action links with false resource data + resourceView := new(ResourceView) + actionLinks1 := client.getDeploymentLeaseActionLinks(resourceView) + // action links mapn should be empty with false resource map / empty resource map + if len(actionLinks1) != 0 { + t.Errorf("empty action link map expected") + } + str := `{"links":[],"content":[{"@type":"CatalogResourceView","resourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","iconId":"502efc1b-d5ce-4ef9-99ee-d4e2a741747c","name":"CentOS 6.3 - IPAM EXT-95563173","description":"","status":null,"catalogItemId":"502efc1b-d5ce-4ef9-99ee-d4e2a741747c","catalogItemLabel":"CentOS 6.3 - IPAM EXT","requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"composition.resource.type.deployment","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:26:42.102Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":null,"hasChildren":true,"data":{},"links":[{"@type":"link","rel":"GET: Catalog Item","href":"http://localhost/catalog-service/api/consumer/entitledCatalogItemViews/502efc1b-d5ce-4ef9-99ee-d4e2a741747c"},{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/561be422-ece6-4316-8acb-a8f3dbb8ed0c/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changelease.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/561be422-ece6-4316-8acb-a8f3dbb8ed0c/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changeowner.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/59249166-e427-4082-a3dc-eb7223bb2de1/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.changeowner.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/59249166-e427-4082-a3dc-eb7223bb2de1/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.destroy.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/3da0ca14-e7e2-4d7b-89cb-c6db57440d72/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.destroy.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/3da0ca14-e7e2-4d7b-89cb-c6db57440d72/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.archive.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/9725d56e-461a-471a-be00-b1856681c6d0/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.archive.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/9725d56e-461a-471a-be00-b1856681c6d0/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scalein.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/85e090f9-9529-4101-9691-6bab1b0a1f77/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scalein.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/85e090f9-9529-4101-9691-6bab1b0a1f77/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scaleout.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/ab5795f5-32ad-4f6c-8598-1d3a7d190caa/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.cafe.composition@resource.action.deployment.scaleout.name}","href":"http://localhost/catalog-service/api/consumer/resources/b313acd6-0738-439c-b601-e3ebf9ebb49b/actions/ab5795f5-32ad-4f6c-8598-1d3a7d190caa/requests"},{"@type":"link","rel":"GET: Child Resources","href":"http://localhost/catalog-service/api/consumer/resourceViews?managedOnly=false&withExtendedData=true&withOperations=true&%24filter=parentResource%20eq%20%27b313acd6-0738-439c-b601-e3ebf9ebb49b%27"}]},{"@type":"CatalogResourceView","resourceId":"51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5","iconId":"Infrastructure.CatalogItem.Machine.Virtual.vSphere","name":"Content0061","description":"Basic IaaS CentOS Machine","status":"Missing","catalogItemId":null,"catalogItemLabel":null,"requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"Infrastructure.Virtual","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:33:16.686Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","hasChildren":false,"data":{"Component":"CentOS_6.3","DISK_VOLUMES":[{"componentTypeId":"com.vmware.csp.component.iaas.proxy.provider","componentId":null,"classId":"dynamicops.api.model.DiskInputModel","typeFilter":null,"data":{"DISK_CAPACITY":3,"DISK_INPUT_ID":"DISK_INPUT_ID1","DISK_LABEL":"Hard disk 1"}}],"Destroy":true,"EXTERNAL_REFERENCE_ID":"vm-773","IS_COMPONENT_MACHINE":false,"MachineBlueprintName":"CentOS 6.3 - IPAM EXT","MachineCPU":1,"MachineDailyCost":0,"MachineDestructionDate":null,"MachineExpirationDate":null,"MachineGroupName":"Content","MachineGuestOperatingSystem":"CentOS 4/5/6/7 (64-bit)","MachineInterfaceDisplayName":"vSphere (vCenter)","MachineInterfaceType":"vSphere","MachineMemory":512,"MachineName":"Content0061","MachineReservationName":"IPAM Sandbox","MachineStorage":3,"MachineType":"Virtual","NETWORK_LIST":[{"componentTypeId":"com.vmware.csp.component.iaas.proxy.provider","componentId":null,"classId":"dynamicops.api.model.NetworkViewModel","typeFilter":null,"data":{"NETWORK_ADDRESS":"192.168.110.150","NETWORK_MAC_ADDRESS":"00:50:56:ae:31:bd","NETWORK_NAME":"VM Network","NETWORK_NETWORK_NAME":"ipamext1921681100","NETWORK_PROFILE":"ipam-ext-192.168.110.0"}}],"SNAPSHOT_LIST":[],"Unregister":true,"VirtualMachine.Admin.UUID":"502e9fb3-6f0d-0b1e-f90f-a769fd406620","endpointExternalReferenceId":"d322b019-58d4-4d6f-9f8b-d28695a716c0","ip_address":"192.168.110.150","machineId":"4fc33663-992d-49f8-af17-df7ce4831aa0"},"links":[{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET: Parent Resource","href":"http://localhost/catalog-service/api/consumer/resourceViews/b313acd6-0738-439c-b601-e3ebf9ebb49b"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.virtual.Destroy}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/654b4c71-e84f-40c7-9439-fd409fea7323/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.virtual.Destroy}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/654b4c71-e84f-40c7-9439-fd409fea7323/requests"},{"@type":"link","rel":"GET Template: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.machine.Unregister}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/f3ae9408-885a-4a3a-9200-43366f2aa163/requests/template"},{"@type":"link","rel":"POST: {com.vmware.csp.component.iaas.proxy.provider@resource.action.name.machine.Unregister}","href":"http://localhost/catalog-service/api/consumer/resources/51bf8bd7-8553-4b0d-b580-41ab0cfaf9a5/actions/f3ae9408-885a-4a3a-9200-43366f2aa163/requests"}]},{"@type":"CatalogResourceView","resourceId":"169b596f-e4c0-4b25-ba44-18cb19c0fd65","iconId":"existing_network","name":"ipamext1921681100","description":"Infoblox External Network","status":null,"catalogItemId":null,"catalogItemLabel":null,"requestId":"dcb12203-93f4-4873-a7d5-1757f3696141","requestState":"SUCCESSFUL","resourceType":"Infrastructure.Network.Network.Existing","owners":["Jason Cloud Admin"],"businessGroupId":"53619006-56bb-4788-9723-9eab79752cc1","tenantId":"vsphere.local","dateCreated":"2017-07-17T13:27:17.526Z","lastUpdated":"2017-07-17T13:33:25.521Z","lease":{"start":"2017-07-17T13:26:42.079Z","end":null},"costs":null,"costToDate":null,"totalCost":null,"parentResourceId":"b313acd6-0738-439c-b601-e3ebf9ebb49b","hasChildren":false,"data":{"Description":"Infoblox External Network","IPAMEndpointId":"1c2b6237-540a-43c3-8c06-b37a1d274b44","IPAMEndpointName":"Infoblox - nios01a","Name":"ipamext1921681100","_archiveDays":5,"_hasChildren":false,"_leaseDays":null,"_number_of_instances":1,"dns":{"componentTypeId":"com.vmware.csp.iaas.blueprint.service","componentId":null,"classId":"Infrastructure.Network.Network.DnsWins","typeFilter":null,"data":{"alternate_wins":null,"dns_search_suffix":null,"dns_suffix":null,"preferred_wins":null,"primary_dns":null,"secondary_dns":null}},"gateway":null,"ip_ranges":[{"componentTypeId":"com.vmware.csp.iaas.blueprint.service","componentId":null,"classId":"Infrastructure.Network.Network.IpRanges","typeFilter":null,"data":{"description":"","end_ip":"","externalId":"network/default-vra/192.168.110.0/24","id":"b078d23a-1c3d-4458-ab57-e352c80e6d55","name":"192.168.110.0/24","start_ip":""}}],"network_profile":"ipam-ext-192.168.110.0","providerBindingId":"CentOS63Infoblox","providerId":"2fbaabc5-3a48-488a-9f2a-a42616345445","subnet_mask":"255.255.255.0","subtenantId":"53619006-56bb-4788-9723-9eab79752cc1"},"links":[{"@type":"link","rel":"GET: Request","href":"http://localhost/catalog-service/api/consumer/requests/dcb12203-93f4-4873-a7d5-1757f3696141"},{"@type":"link","rel":"GET: Parent Resource","href":"http://localhost/catalog-service/api/consumer/resourceViews/b313acd6-0738-439c-b601-e3ebf9ebb49b"}]}],"metadata":{"size":20,"totalElements":3,"totalPages":1,"number":1,"offset":0}}` + json.Unmarshal([]byte(str), &resourceView) + + // check deployment action links with false resource data + actionLinks1 = client.getDeploymentLeaseActionLinks(resourceView) + + // action links mapn should not be empty with correct resource map + if len(actionLinks1) == 0 { + t.Errorf("empty action link map was not expected") + } +} \ No newline at end of file