Don't pass None for any values in post body.

There is unspecifiedness and nonuniformity of the behavior of passing
None values to create server. So don't do it.
The case of the 'meta' keyword argument is ugly and it should be changed
to 'metadata' but the various APIs are inconsistent about this so I didn't
want to mess with that now and risk breaking something.

Change-Id: I3a8a3afbc179a54b524db0e2ed04d1542401f4a7
This commit is contained in:
David Kranz 2012-04-12 15:49:41 -04:00
parent 1b3bf7f93d
commit 28e79de897

View File

@ -26,7 +26,7 @@ class ServersClient(object):
flavor_ref (Required): The flavor used to build the server.
Following optional keyword arguments are accepted:
adminPass: Sets the initial root password.
metadata: A dictionary of values to be used as metadata.
meta: A dictionary of values to be used as metadata.
personality: A list of dictionaries for files to be injected into
the server.
security_groups: A list of security group dicts.
@ -42,23 +42,23 @@ class ServersClient(object):
post_body = {
'name': name,
'imageRef': image_ref,
'flavorRef': flavor_ref,
'metadata': kwargs.get('meta'),
'personality': kwargs.get('personality'),
'adminPass': kwargs.get('adminPass'),
'security_groups': kwargs.get('security_groups'),
'networks': kwargs.get('networks'),
'user_data': kwargs.get('user_data'),
'availability_zone': kwargs.get('availability_zone'),
'accessIPv4': kwargs.get('accessIPv4'),
'accessIPv6': kwargs.get('accessIPv6'),
'min_count': kwargs.get('min_count'),
'max_count': kwargs.get('max_count')
'flavorRef': flavor_ref
}
disk_config = kwargs.get('disk_config')
if disk_config != None:
post_body['OS-DCF:diskConfig'] = disk_config
for option in ['personality', 'adminPass',
'security_groups', 'networks', 'user_data',
'availability_zone', 'accessIPv4', 'accessIPv6',
'min_count', 'max_count', ('metadata', 'meta'),
('OS-DCF:diskConfig', 'disk_config')]:
if isinstance(option, tuple):
post_param = option[0]
key = option[1]
else:
post_param = option
key = option
value = kwargs.get(key)
if value != None:
post_body[post_param] = value
post_body = json.dumps({'server': post_body})
resp, body = self.client.post('servers', post_body, self.headers)