get_property(mac_address) always returns None

63 views
Skip to first unread message

Dan Finn

unread,
Jul 7, 2014, 6:57:27 PM7/7/14
to pysp...@googlegroups.com
I just started playing with pysphere today, very cool!  I'd like to possibly use it to automate our server builds.  Currently we use cobbler for that which does a PXE boot.  One piece of basic information that I would need to be able to pass along to cobbler is the MAC address of the machine that was just created.  I quickly noticed that doing something basic from the GettingStarted guide like this was not working:

vm1 = server.get_vm_by_path("[na03_linux (1)] imgxfer/imgxfer.vmx")
print vm1.get_property('mac_address')

The output that is returned from that is "None".  However if I do a:

print vm1.get_properties()

I can clearly see that the mac_address field is there and is populated correctly with a valid MAC so I'm not sure why get_property(mac_address) isn't returning it.

I'm on VMware vCenter Server 5.5.

Any insight would be helpful.

Also, if anyone already has a setup like this working where they build the VM with pysphere and then hand the info off to cobbler, I'd love to hear about that too.  No need to rewrite the wheel.

肖时俊

unread,
Jul 7, 2014, 11:27:26 PM7/7/14
to pysp...@googlegroups.com
From seba code:

def get_mac_address(vm):
  mac_list = ''
  net = vm.get_property('net', from_cache=False)
  if net:
    for interface in net:
      mac = interface.get('mac_address', None)
      if mac:
        if mac_list != '':
          mac_list = mac_list + "," + mac
        else:
          mac_list = mac
  for v in vm.get_property("devices").values():
    if v.get('macAddress'):
      if mac_list != '':
        mac_list = mac_list + "," + v.get('macAddress')
      else:
        mac_list=v.get('macAddress')
  return mac_list

https://groups.google.com/forum/#!topic/pysphere/7NcrY0BIsuE

在 2014年7月8日星期二UTC+8上午6时57分27秒,Dan Finn写道:
Reply all
Reply to author
Forward
0 new messages