Skip to content

Commit

Permalink
Fixes Bug lp:900910
Browse files Browse the repository at this point in the history
- Modified create_server() client method to include optional kwargs.
- This dict can be used to pass any number of optional args including
those supported by create server extension and  avoids the need of having a
separate create_server() method

Change-Id: I742ae411330b9e006130d3a4b59c7201f59243cd
  • Loading branch information
Rohit Karajgi committed Dec 12, 2011
1 parent 4ea2efb commit 95446a2
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions tempest/services/nova/json/servers_client.py
@@ -1,7 +1,6 @@
from tempest import exceptions
from tempest.common import rest_client
import json
import tempest.config
import time


Expand All @@ -17,43 +16,43 @@ def __init__(self, config, username, key, auth_url, tenant_name=None):
self.headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}

def create_server(self, name, image_ref, flavor_ref, meta=None,
personality=None, accessIPv4=None, accessIPv6=None,
adminPass=None):
def create_server(self, name, image_ref, flavor_ref, **kwargs):
"""
Creates an instance of a server.
name: The name of the server.
image_ref: The reference to the image used to build the server.
flavor_ref: The flavor used to build the server.
name (Required): The name of the server.
image_ref (Required): Reference to the image used to build the server.
flavor_ref (Required): The flavor used to build the server.
Following optional keyword arguments are accepted:
adminPass: Sets the initial root password.
meta: A dictionary of values to be used as metadata.
metadata: 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.
networks: A list of network dicts with UUID and fixed_ip.
user_data: User data for instance.
availability_zone: Availability zone in which to launch instance.
accessIPv4: The IPv4 access address for the server.
accessIPv6: The IPv6 access address for the server.
min_count: Count of minimum number of instances to launch.
max_count: Count of maximum number of instances to launch.
"""

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'),
}

if meta != None:
post_body['metadata'] = meta

if personality != None:
post_body['personality'] = personality

if adminPass != None:
post_body['adminPass'] = adminPass

if accessIPv4 != None:
post_body['accessIPv4'] = accessIPv4

if accessIPv6 != None:
post_body['accessIPv6'] = accessIPv6

post_body = json.dumps({'server': post_body})
resp, body = self.client.post('servers', post_body, self.headers)
body = json.loads(body)
Expand Down

0 comments on commit 95446a2

Please sign in to comment.