jbowdre / site-comments

0 stars 0 forks source link

Adding VM Notes and Custom Attributes with vRA8 - Virtually Potato #8

Closed utterances-bot closed 9 months ago

utterances-bot commented 3 years ago

Adding VM Notes and Custom Attributes with vRA8 - Virtually Potato

In past posts, I started by creating a basic deployment infrastructure in Cloud Assembly and using tags to group those resources. I then wrote an integration to let vRA8 use phpIPAM for static address assignments. I implemented a vRO workflow for generating unique VM names which fit an organization’s established naming standard, and then extended the workflow to avoid any naming conflicts in Active Directory and DNS. And, finally, I created an intelligent provisioning request form in Service Broker to make it easy for users to get the servers they need. That’s got the core functionality pretty well sorted, so moving forward I’ll be detailing additions that enable new capabilities and enhance the experience.

https://virtuallypotato.com/adding-vm-notes-and-custom-attributes-with-vra8

jbowdre commented 3 years ago

Dennis Posted June 12, 2021 on Hashnode

I also found useful the ability to add vCenter tags in the blueprint which can be used by vRO and vRNI for application mapping, reporting etc. You can update the tag values from selections in an input form.

  Cloud_vSphere_Machine_1:
    properties:
      tags:
        - key: Application
          value: MyApp1
        ### Update environment name from Input e.g. Dev, Staging, Prod
        - key: Environment
          value: Prod
        ### Update tenant name from Input
        - key: Tenant
          value: T98
bcarnegie commented 3 years ago

Hi There

I have tried adding to this code to also put the date the VM was requested. I have it working to give the date in UTC time but would like to change that to a better date/time format as well as possibly use just current date/time. I have not been able to find out what the values to make this happen. Any ideas?

Thanks

jbowdre commented 3 years ago

Hi @bcarnegie,

Maybe adding something like this to the Set Notes task would get what you need?

var date = new Date();
var requestDate = date.toLocaleDateString();

System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm,"Request Date", requestDate)

That would insert a string for the current date like "September 16, 2021" (and should automatically adjust the format to match your locale).

Hope that helps, John

bcarnegie commented 3 years ago

Hi John

That worked like a charm. Thank you very much for your help.

I am wondering if there are any other bits of data that I should capture to put into the custom attributes for a VM?

jbowdre commented 3 years ago

Hey @bcarnegie,

Awesome, I'm glad that worked for you!

As far as what else might be useful, that really kind of depends on your environment and operational needs. For instance, it may be helpful to add a Department or Business Unit field to easily tie a server back to who uses is (rather than just a single point of contact).

I've found that vSphere Custom Attributes work really well for details that are going to be specific to a single VM, things I might want to know while viewing/managing a given VM. I'm thinking the sort of stuff that answers questions like "who manages this VM?" rather than "which VMs are managed by this person?"

vSphere Tags may be a better fit for those latter sorts of questions, since they'd let you easily find all the VMs in your inventory which match a given tag - like if you want to add a docker tag to VMs which function as Docker hosts. I haven't written anything for that in my lab just yet, but this blog post may get you pointed in the right direction if you'd like to explore that.

Again, though, it all comes down to what's appropriate in your environment. Please do let me know if you come up with any clever uses for this though!

Cheers, John

bcarnegie commented 3 years ago

Another question for you. In our current 7.6 environment, we capture who submits the request as VRM Owner in the Custom Attributes. I didn't have much to do with this setup, is there a way to capture this in 8.x? The person submitting the request might be different than the Point of Contact person (Server Team member submitting the request on behalf of a Customer for example). Thanks

jbowdre commented 3 years ago

Hey @bcarnegie,

Sorry for the slow response; it's been A Week. I did some experimenting and I think I figured out a way to accomplish what you're after. It's not super elegant and there may be a better way, but this at least works.

I started by going to vRO and looking at the Variables tab of a previous run of the VM Post-Provisioning workflow so I could see what data I had to work with. In addition to the inputProperties variable that I've been working with, there's also a bunch of __metadata_* variables which hold various deployment details. Most of those aren't particularly interesting to me, but __metadata_userName includes the username I use to log into vRA. So that should work to identify the account which requested the deployment, replacing the old VRM Owner attribute generated by vRA 7.x.

To use the newfound knowledge, I edit the VM Post-Provisioning workflow and add a new input named the same way (__metadata_userName) of type String. I then also link this Input to the Set Notes scriptable task within the workflow. And then I just add two new lines to the task:

var requester = __metadata_userName;

System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm,"VRM Owner", requester)

So now vRA 8.x will continue to create a VRM Owner attribute on vSphere VMs, just like in the olden days.

Hope that helps! John

wacky0021 commented 3 years ago

Hi John, Im currently learning about this. Thank you for your inputs. Im having a hard time right now, my VM are in array (2vm) and need to split it to string so I can set it to parameters and pass it as arguments to next schema can you help me split the VMs?

bcarnegie commented 3 years ago

Hi John

No worries about the reply, I have been working on some logic that SHOULD work in normal programming language but does not appear to work as expected in YAML :P

I gave it a try and it doesn't appear to be working properly.

A few things I noticed; If I view the workflow run, i see __metadata_userName but only before I made these changes does a value appear. After I made the changes, the value field is blank. If I change the name from VRM to VM (or whatever I want to call it), it creates the custom attribute so that part is working properly.

Any ideas?

jbowdre commented 3 years ago

@bcarnegie,

Interesting. I admit that I had just tested this by re-running a previous workflow run after making the changes, and that worked fine. I just tested a fresh deployment and I see the same thing as you. I'll see if I can come up with another solution and let you know.

jbowdre commented 3 years ago

@wacky0021

Hi John, Im currently learning about this. Thank you for your inputs. Im having a hard time right now, my VM are in array (2vm) and need to split it to string so I can set it to parameters and pass it as arguments to next schema can you help me split the VMs?

Without knowing exactly what you're trying to accomplish I'm kind of shooting in the dark there, but you should be able to use a for loop to break out the members of the array and do whatever you need from there:

var arrVmNames = ["VmOne", "VmTwo", "VmThree"];

for (i in arrVmNames) {
  System.log("VM Name: " + arrVmNames[i])
  // Do whatever you need with that individual VM before moving to the next one
}

Hopefully that gets you pointed in the right direction?

j3di77 commented 2 years ago

Hi John,

First and foremost, your content is awesome. You cant even imagine how it has helped me in progressing with vRA 8.x in such a short span of time (like literally i started 2 months ago).

However I need some help in how to send an email from the existing vRO workflow to a user when ever a deployment is commissioned/completed.

Your assistance would be highly appreciated.

jbowdre commented 2 years ago

Hi @j3di77,

Thanks so much for the kind words! I was really fumbling throught this stuff starting out so it's really great to know that others are finding my notes to be helpful.

I'm afraid I haven't done anything with vRA/vRO email notifications so far. There are some built-in workflows in vRO under Library > Mail which might help though. Here's a post which walks through getting that working. Once you've got the workflow doing what you need, it should be easy to attach it to a new subscrition to the Compute Post Provision event topic.

Or at least that's the route I'd start out exploring if I had the time to do so. Good luck!

andrewr01 commented 2 years ago

Thanks heaps for these posts! They are awesome! A real life saver. I have read the VMware documentation but it can be limited at times and confusing. VMware's docs don't often explain very well how things are tied together or have detailed real world examples. You have filled a gap and I am very grateful!

jbowdre commented 2 years ago

@andrewr01 thank you so much for the kind words! When I set out to do these vRA tasks I was also unable to find a lot of great documentation on how to do it. It's great to hear that my notes have been able to help fill that gap!

andrewr01 commented 2 years ago

Hi John, hopefully you can help with a vRA 8.6 question not related to this post. We are using in-built vRA IPAM for IP allocation. We have deployed new VMs in 7.6 that have used IPs that are showing available in 8.6 since I wasn't quite ready to cutover. Is there any way to manually assign an IP in 8.6 IPAM? I was hoping onboarding the VM would do this but it hasn't. A second related question is when onboarding in 8.6 VMs are being listed as having an NSX-T network whereas we are allocating the equivalent network that appears in vCenter. Is there any way to specify the network or change it in the deployment post onboarding?

jbowdre commented 2 years ago

Hey @andrewr01, unfortunately I don't really have any experience with the built-in IPAM provider or with onboarding existing VMs. I won't be able to offer any insight on those issues, I'm afraid.

gummianton commented 2 years ago

Hi John. Thanks for the great content.

I'm in trouble after updating to 8.8. After that update, I always get in the VM post-Provisioning section:

022-06-09 09: 39: 59.023 +00: 00INFO__item_stack: / item1 2022-06-09 09: 40: 04.027 +00: 00INFOFound VM object: undefined 2022-06-09 09: 40: 04.040 +00: 00INFO__item_stack: / item2 2022-06-09 09: 40: 04.079 +00: 00ERRORError in (Workflow: VM Post-Provisioning / Set Notes (item2) # 10) TypeError: Cannot call method "reconfigVM_Task" of undefined 2022-06-09 09: 40: 04.102 +00: 00ERRORWorkflow execution stack:

Do you have any ideas?

Best regards Guðmundur

jbowdre commented 2 years ago

Hi @gummianton,

That sounds a bit like vRO wasn't able to obtain the VM object. Can you check the debug logging for that execution to see if the get VM object scriptable task was successful?

gummianton commented 2 years ago

Hi John,

Thanks for taking the time to do this.

Dose this help?

item: 'VM Post-Provisioning/item2', state: 'failed', business state: 'null', exception: 'TypeError: Cannot call method "reconfigVM_Task" of undefined (Workflow:VM Post-Provisioning / Set Notes (item2)#10)' workflow: 'VM Post-Provisioning' (40621a09-f1e8-455b-a115-b37cf7f7e203) | 'attribute': name=vm type=VC:VirtualMachine value=NULL | 'input': name=inputProperties type=Properties value={9:42:addresses=Array#[31:Array#[20:string#192.26.34.54]]

Best regards Guðmundur

gummianton commented 2 years ago

Hi John,

I did figure out what was causing this error. It was authentication error in the Orchestrator vSphere Vcenter Plug-in. Thanks for your help.

jbowdre commented 2 years ago

Hey @gummianton,

I'm glad you got it sorted - thanks for letting me know. I was just starting to dig into my workflow to see about adding some more logging so I'll try to make sure it can catch auth failures as well. 👍

kduhjganesh commented 1 year ago

Hi All is any procedure to update data captured in VRA custom forms like department / server owner details to update vcenter custom attributes using VRO or any other procdure, really appreciated for support