Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

get out machine name #20

Closed
wants to merge 17 commits into from
Closed

Conversation

andreaspeters
Copy link

Signed-off-by: Andreas Peters [email protected]

Signed-off-by: Andreas Peters <[email protected]>
@cars
Copy link
Contributor

cars commented Nov 30, 2017

Does this work for multi-machine blueprints? Or is it assuming a catalog request just spins up a single VM?

@andreaspeters
Copy link
Author

U know, in vRA7 are no single-mashine blueprints anymore. And my change is working very well with components (aka multi-mashine blueprints).

As example, it looks like that:

vra7_resource.linux-test_2.0:
  id = <NUMBER>
  catalog_id = <NUMBER>
  catalog_name = CentOS
  name = <SERVER NAME>
  request_status = SUCCESSFUL
  resource_configuration.% = 0
vra7_resource.linux-test_2.1:
  id = <NUMBER>
  catalog_id = <NUMBER>
  catalog_name = CentOS
  name = <SERVER NAME>
  request_status = SUCCESSFUL
  resource_configuration.% = 0

@virajindasrao
Copy link
Contributor

virajindasrao commented Nov 30, 2017

I tried this code and the output was different for both the machines.

Actual output

vra7_resource.linux:
     id = <NUMBER>
     catalog_id = <NUMBER>
     catalog_name = CentOS
     name = centos-<NUMBER>
     request_status = SUCCESSFUL
     resource_configuration.% = 0
vra7_resource.windows:
     id = <NUMBER>
     catalog_id = <NUMBER>
     catalog_name = WindowsOS
     name = dev-1
     request_status = SUCCESSFUL
     resource_configuration.% = 0

Expected output

vra7_resource.linux:
     id = <NUMBER>
     catalog_id = <NUMBER>
     catalog_name = CentOS
     name = centos-<NUMBER>
     request_status = SUCCESSFUL
     resource_configuration.% = 0
vra7_resource.windows:
     id = <NUMBER>
     catalog_id = <NUMBER>
     catalog_name = WindowsOS
     name = WindowsOS-<NUMBER>
     request_status = SUCCESSFUL
     resource_configuration.% = 0

This condition should be handled by the code.

@andreaspeters
Copy link
Author

Ah ok thats a good issue. I could not test it with windows. Is ist possible that u show me the resourceView output as json?

@andreaspeters
Copy link
Author

@virajindasrao I mean the response of this curl:

curl --insecure -H "Content-Type: application/json" -H "Authorization: Bearer $token" "https://$vRA/catalog-service/api/consumer/requests/<REQUEST ID>/resourceViews"

@cars
Copy link
Contributor

cars commented Nov 30, 2017

And what I'm seeing is output for just one of the machines in my deployment. I have a single resource defined.

provider "vra7" {
    username = "${var.username}"
    password = "${var.password}"
    tenant   = "${var.tenant}"
    host     = "${var.host}"
}

resource "vra7_resource" "multi_vm"  {
    count = 1
    catalog_name = "UBU_LTS_Ansible_tf3 copy"
    resource_configuration = {
        vm1.cpu = 3
        vm1.memory = 3072
        vm1.lab.vm.prop1 = "ubu7 vm1 Prop1a"
        vm1.lab.vm.Prop2 = "ubu7 vm1 Prop2a"
        vm3.lab.vm2.prop1 = "ubu7 vm2 prop1a"
        vm3.cpu = 2
        vm3.memory = 2048
  }
  catalog_configuration = {
    _deploymentName = "Append Deployment"
    lab.bp.prop1 = "ubu7 BP Test1- Append",
    lab.bp.Prop2 = "ubu7 BP Test2- append"
  }
}

The blueprint/catalog item it is calling spins up 2 VMs.
image

When completed, I have this item in my inventory in vRA
image

When I do a refresh and then show with your code I only get back info about 1 one of the VMs

image

When I do the ResourceViews REST call I get back something that looks like:

{
    "links": [],
    "content": [
        {
            "@type": "CatalogResourceView",
            "resourceId": "19d94733-feb9-49e2-8fb1-2f1eb384a789",
            "iconId": "Infrastructure.CatalogItem.Machine.Virtual.vSphere",
            "name": "VRA168",
            "description": null,
            "status": "On",
            "catalogItemId": null,
            "catalogItemLabel": null,
            "requestId": "bda914c4-824d-4db3-8a20-a21f920329ab",
            "requestState": "SUCCESSFUL",
            "resourceType": "Infrastructure.Virtual",
            "owners": [
                "C T"
            ],
            "businessGroupId": "88eaa78c-384f-4b20-a03a-12d4031cfdac",
            "tenantId": "vsphere.local",
            "dateCreated": "2017-11-30T16:49:50.132Z",
            "lastUpdated": "2017-11-30T16:50:05.433Z",
            "lease": { ...},
            "costs": null,
            "costToDate": null,
            "totalCost": null,
            "parentResourceId": "a9cdc75c-d830-4443-af6c-a3f4f29a5696",
            "hasChildren": false,
            "data": { ....  },
            "links": [ ....  ]
        },
        {
            "@type": "CatalogResourceView",
            "resourceId": "79e29b8f-2f82-46d6-8cc0-67636b577c1c",
            "iconId": "Infrastructure.CatalogItem.Machine.Virtual.vSphere",
            "name": "VRA169",
            "description": null,
            "status": "On",
            "catalogItemId": null,
            "catalogItemLabel": null,
            "requestId": "bda914c4-824d-4db3-8a20-a21f920329ab",
            "requestState": "SUCCESSFUL",
            "resourceType": "Infrastructure.Virtual",
            "owners": [

The full json response is attached below.

request_resourceview.json.txt

@andreaspeters
Copy link
Author

Hi @cars thats great. Thanks for your resourceViewRequest! I think that helps me a lot to see how the output looks like on differen configuration ways. :-) I can fix it therefore u will see all names.

@andreaspeters
Copy link
Author

the change is untestet. I'm at home without the test system. so, give me time until tomorrow please. :-)

iterate though the resource view map to show the name
Signed-off-by: Andreas Peters <[email protected]>
Signed-off-by: Andreas Peters <[email protected]>
Signed-off-by: Andreas Peters <[email protected]>
@vmwclabot
Copy link

@andreaspeters, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link

@andreaspeters, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link

@andreaspeters, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link

@andreaspeters, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@virajindasrao
Copy link
Contributor

virajindasrao commented Dec 4, 2017

What is the expected output here?
name = dev-<number>
or
name = catalog_name-<number>
I am still getting
name = dev-<number>
after successful request status.
Just in case if the expected output is correct, then what if there are two machines in a catalog? Which one will get stored in terraform config?

@andreaspeters
Copy link
Author

@virajindasrao The expected output is the name of the server. But I still missing a resourceView as json file from you to see whats the difference between a linux and a windows server. :-) I can not test windows servers here. Sorry!

@Marcvd316
Copy link

@andreaspeters Would it make sense to broaden the scope of this change to include returning ANY vRA custom property to be used by Terraform as an output? That feature could be pretty valuable...

Also, it seems like most of the work for that could already be done if this portion for the hostname is already implemented?

@andreaspeters
Copy link
Author

@Marcvd316 Thats a very good idea. I will have a look how to realize it so easy and flexible as possible.

@andreaspeters
Copy link
Author

@virajindasrao So, we try it with a windows server and it's working too. Mean, the hostname is like expected. To see what's different to your one, I still need your ResourceView Request. What I can tell u is, the name "dev-" is a vmware internal default name they set, if the user didn't choose one.

Nuno Ferro and others added 2 commits January 5, 2018 15:11
@vmwclabot
Copy link

@andreaspeters, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@virajindasrao
Copy link
Contributor

@andreaspeters go through this blueprint. I tried this blueprint and got wrong output
blueprint

@andreaspeters
Copy link
Author

Hi @virajindasrao thanks for the output, I will have a look. :-)

@andreaspeters
Copy link
Author

Hi @virajindasrao, sorry for my late response. So, what u give me is not a blueprint, it's just a response output to the blueprint. Is it possible that you will export your blueprint therefore we can import it to check whats wrong.

Only to be clear, at the moment we got in no case your failure. But this request stuck only because of your issue. So I really want find outs whats the problem. :-)

@virajindasrao
Copy link
Contributor

@raghavav
Copy link

@virajindasrao I am not sure what discrepancy you are seeing in the output. Could you please summarize. It is hard to tell with the entire history of this conversation, try as I may.

Here is one thing to note though. In a multi-machine (or single-machine for that matter) blueprint, each machine gets a name that is generated based on a machine prefix. That machine prefix is likely set at the business group level, though I see that you have overridden it on the blueprint. Th value is 'dev-' in this case, and hence the machines come out with that name. The number part of the name is a unique value that the system generates to avoid conflicts. This same name is used as the VM name in vCenter.

Hence, I don't see a problem with the 'dev-' names that show up here. So could you please explain what discrepancy you see in a multi-machine case?

@raghavav
Copy link

@Marcvd316 On the question of broadening the scope of this change, I would recommend doing that as a separate pull request. Custom properties can involve a lot of testing against settings in the blueprint and in other scopes in VRA.

@virajindasrao
Copy link
Contributor

@raghavav
Kindly refer the previous comment

@raghavav
Copy link

raghavav commented Mar 5, 2018

@virajindasrao I did look at the particular comment you point to. I am not sure why you are expecting that prefix for the names of Windows machines. The prefix, like I said in my previous comment, is picked based on the machine-prefix setting in vRA, which in this case seems to be 'dev-'. So Can you please elaborate what the expectation mismatch is here? Thx

PS: Sorry for the delayed response, I had an emergency personal trip that got in the way of following up on this thread.

@virajindasrao
Copy link
Contributor

Hi @raghavav
As per my previous comment, one resource contains actual item name and second resoure contains deployment name from the item.
Let's suppose the scenario where two centos machines are in deployment and after deployment machine names are dev-1 and dev-2.
Now, let's consider your view. If terraform resource contains one name dev-1 then what about the second machine?
The same bug I found in my testing. Let me know if I am missing any point here.

@mhhutt
Copy link

mhhutt commented Apr 3, 2018

Guys would it be possible to return all the properties of a machine as output so that they can be used later in the terraform process

@raghavav
Copy link

raghavav commented Apr 3, 2018

Returning all properties as 'computed' properties should not be a problem. Returning them as first class schema properties is a problem. vRA does not support arbitrary updates to a machine resource for most properties. It only allows a very prescriptive set of day-2 operations. For example, it does allow scaling up/down, and it allows reconfiguring cpu, memory and storage limits.
In general, we have to worry about the ability to diff with many of the schema properties. We may need to use a DiffSupressFunc in this plugin because we have fields in VRA deployments that cannot be diffed in order to do an update. They are only usable during a new Create.

@raghavav
Copy link

raghavav commented Apr 3, 2018

The bigger issue that I see in this ticket is the question of what is a resource for the vra-terraform-plugin. When using a catalog item as it is being used in this plugin, the resulting resource should be a 'Deployment'. There should be one sub-object within that Deployment resource for each machine. Each of those machine sub-objects can have all of the properties such as name, ip-address, other computed properties such as custom properties etc. The schema and the resulting state should reflect this hierarchy. Can someone post the current .tf file and the corresponding output of 'terraform show'? I see that the conversations above are referencing different .tf files and responses. I would like to analyze this based on the latest example we are using, please. Thanks a lot.

@mhhutt
Copy link

mhhutt commented Apr 4, 2018

I apologise I am currently running the Master version of this from the vmware repo and terraform show returns nothing at all

@virajindasrao
Copy link
Contributor

As mentioned in comment PR has a static approach and will not work for a multi-machine blueprint.
I have created PR#45 for the same with a dynamic approach for fetching machine details.

Closing this PR.

@g1ps
Copy link

g1ps commented May 17, 2018

I grabbed the complete action.go and resource.go from Viraj's pull request, re-ran dep, recompiled, re-installed, re-ran init and apply and I get nothing different when I run show. The example files aren't required for compilation, are they? What am I missing?

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants