CenturyLinkCloud / chef-provisioning-vsphere

A chef-provisioning provisioner for VMware vSphere
MIT License
66 stars 57 forks source link

Retrieving Ohai Attributes from Provisioned Node? #30

Open MattMencel opened 9 years ago

MattMencel commented 9 years ago

I have a need to retrieve the node mac address so I can statically assign the node an IP through DHCP.

Is there a way to callout to the node during provisioning and retrieve the mac address?

The AWS driver can do something like this... Chef::Resource::AwsInstance.get_aws_object()

mwrock commented 9 years ago

Maybe not so elegantly, but I think it is possible. Here is a snippet that will pull a VM Instance by id:

      vsphere_helper = ChefProvisioningVsphere::VsphereHelper.new(
        { host: 'my_vcenter_host', user: 'my_vcenter_user', password: 'my_password' }, 'my_datacenter'
      )
      vm = vsphere_helper.find_vm_by_id(server_id)
      mac = vm.guest.net.macAddress

The vm returned is a vsphere VirtualMachine instance as documented here

Let me know if this works for you.