I'm getting unexpected behavior in Python 2.7 when using default arguments. Instead of using the value passed in by the caller, one argument is getting overridden by the default. Consider the following functions:
def vm_list(domain, username, server, verbose, cluster, datacenter, name,
regex, template_only, detailed_list, vm_status):
print 'inside vm_list vm_stauts is', vm_status
vcenter_request = "get_registered_vms"
vmlist = vcenter_connect(server, user, password, vcenter_request, vm_status)
def vcenter_connect(server, user, password, request,
source_vm=None, target_vm=None,
res_pool=None, num=1, vm_status=None):
print 'inside vcenter_connect vm_stauts is', vm_status
vm_list gets called first with vm_status passed in as a string, such as "poweredOff". Inside this function vm_status is equal to "poweredOff" as expected, but when I pass the value to vcenter_connect it's getting overridden by the default argument None. I am using other default arguments in vcenter_connect but they are working as expected, that is, they're only using the default values when nothing is passed in.
Running the relevent parts to test the string value gives me this:
inside vm_list vm_stauts is poweredOff
inside vcenter_connect vm_stauts is None
What am I doing wrong?