def create_environment(self, name, description): """ Create a new environment (Tenant) :param name: Name of the environment :param description: Description of the environment :return: 'Requests' response """ logger.info("Creating new environment") env_model = {ENVIRONMENT_BODY_ROOT: {ENVIRONMENT_BODY_NAME: name, ENVIRONMENT_BODY_DESCRIPTION: description}} body = model_to_request_body(env_model, self.headers[HEADER_ACCEPT]) return self.post(ENVIRONMENT_RESOURCE_ROOT_URI, body, self.headers, parameters=None, tenant_id=self.tenant_id)
def create_tier(self, environment_name, name, image, region_name, keypair=None, product_name=None, product_version=None, network_name=None, subnetwork_name=None): """ Add a Tier to an already existing Environment (Tenant) :param name: Name of the environment :param image: image id to deploy a VM :param region: region where to deploy :return: 'Requests' response """ logger.info("Add tier to environment") tier_model = {TIER_BODY_ROOT: { TIER_BODY_NAME: name, TIER_BODY_INITIAL_INSTANCES: "1", TIER_BODY_MAXIMUM_INSTANCES: "1", TIER_BODY_MINIMUM_INSTANCES: "1", TIER_BODY_IMAGE: image, TIER_BODY_FLAVOUR: "2", TIER_BODY_KEYPAIR: keypair, TIER_BODY_FLOATINGIP: "False", TIER_BODY_REGION: region_name, TIER_BODY_PRODUCTRELEASE : { TIER_BODY_PRODUCTRELEASE_NAME : product_name, TIER_BODY_PRODUCTRELEASE_VERSION : product_version }, TIER_BODY_NETWORK : { TIER_BODY_NETWORK_NAME : network_name, TIER_BODY_SUBNETWORK : { TIER_BODY_SUBNETWORK_NAME: subnetwork_name } } } } #Removing keys whose values are None delete_element_when_value_none(tier_model) body = model_to_request_body(tier_model, self.headers[HEADER_ACCEPT]) return self.post(TIER_RESOURCE_ROOT_URI, body, self.headers, parameters=None, tenant_id=self.tenant_id,environment_name=environment_name)
def create_environment(self, name, description): """ Create a new environment (Tenant) :param name: Name of the environment :param description: Description of the environment :return: 'Requests' response """ logger.info("Creating new environment") env_model = { ENVIRONMENT_BODY_ROOT: { ENVIRONMENT_BODY_NAME: name, ENVIRONMENT_BODY_DESCRIPTION: description } } body = model_to_request_body(env_model, self.headers[HEADER_ACCEPT]) return self.post(ENVIRONMENT_RESOURCE_ROOT_URI, body, self.headers, parameters=None, tenant_id=self.tenant_id)
def create_environment_instance(self, name, description, environment_name, environment_description, tier_name, image, region_name, keypair=None, product_name=None, product_version=None, network_name=None, subnetwork_name=None): """ Create a new environment (Tenant) :param name: Name of the environment instance (blueprint) :param description: Description of the environment instance (blueprint) :param environment_name: Name of the environment :param tier_name: Name of the tier :param image: image to deploy a VM from :param keypair: keypair of the user to enter the deployed VM :param product_name: Name of the product :param product_version: Product version :param network_name: Name of the network :param subnetwork_name: Name of the subnetwork :return: A duple : The task (asynchronous method) as a dict, the 'Request' response """ logger.info("Creating new environment instance") env_model = {ENVIRONMENT_INSTANCE_BODY_ROOT: { ENVIRONMENT_INSTANCE_BODY_NAME: name, ENVIRONMENT_BODY_DESCRIPTION: description, ENVIRONMENT_BODY_ROOT: { ENVIRONMENT_BODY_NAME: environment_name, ENVIRONMENT_BODY_DESCRIPTION: environment_description, TIER_BODY_ROOT: { TIER_BODY_NAME: tier_name, TIER_BODY_INITIAL_INSTANCES: "1", TIER_BODY_MAXIMUM_INSTANCES: "1", TIER_BODY_MINIMUM_INSTANCES: "1", TIER_BODY_IMAGE: image, TIER_BODY_FLAVOUR: "2", TIER_BODY_KEYPAIR: keypair, TIER_BODY_FLOATINGIP: "False", TIER_BODY_REGION: region_name, TIER_BODY_PRODUCTRELEASE : { TIER_BODY_PRODUCTRELEASE_NAME : product_name, TIER_BODY_PRODUCTRELEASE_VERSION : product_version }, TIER_BODY_NETWORK : { TIER_BODY_NETWORK_NAME : network_name, TIER_BODY_SUBNETWORK : { TIER_BODY_SUBNETWORK_NAME: subnetwork_name } } } } } } #Removing keys whose values are None delete_element_when_value_none(env_model) #Converting json to body request body = model_to_request_body(env_model, self.headers[HEADER_CONTENT_TYPE]) response = self.post(ENVIRONMENT_INSTANCE_RESOURCE_ROOT_URI, body, self.headers, parameters=None, tenant_id=self.tenant_id) task_dict = response_body_to_dict(response,self.headers[HEADER_ACCEPT], xml_root_element_name=TASK_BODY_ROOT ) return task_dict, response