def deserialize_wrong_mimetype_flavor_test(): data = util.load_json_from_file('flavor_creation_request.json') try: Flavor.deserialize(util.WRONG_MIMETYPE, data) assert False except NotImplementedError as e: assert 'Unrecognized mimetype or model type' in str(e)
def from_openstack_flavor_test(): data = util.load_json_from_file('flavor_response.json') openstackflavor = OpenStackFlavor(None, data['flavor']) infrastructure = util.create_example_infrastructure() flavor = util.create_example_flavor() converted_flavor = Flavor.from_openstack_flavor(openstackflavor, infrastructure) assert util.json_are_equal(flavor.to_dict(), converted_flavor.to_dict())
def create_flavor(): body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_flavor_request_validator() validator.validate(body) flavor = Flavor.deserialize(content_type, body) manager = FlavorSynchronizer() created_flavor = manager.create_flavor(flavor) response_body = created_flavor.serialize(request.accept_mimetypes) return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
def publish_or_promote_flavor(flavor_id): body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_flavor_modification_request_validator() validator.validate(body) modified_flavor = Flavor.deserialize(content_type, request.data) manager = FlavorSynchronizer() if not modified_flavor.nodes: modified_flavor = manager.publish_or_promote_flavor(flavor_id, modified_flavor) else: modified_flavor = manager.add_node_to_flavor(flavor_id, modified_flavor) response_body = modified_flavor.serialize(request.accept_mimetypes) return Response(response_body, mimetype=request.accept_mimetypes[0][0])
def create_region_flavor(region_name): if not manager.is_node_included(region_name): return _create_not_found_region_response(region_name) body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_flavor_request_validator() validator.validate(body) flavor = Flavor.deserialize(content_type, body) flavor.promoted = False flavor.public = False manager = FlavorSynchronizer() created_flavor = manager.create_region_flavor(region_name, flavor) response_body = created_flavor.serialize(request.accept_mimetypes) return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
def modify_promotedflavor(flavor_id): #TODO To be decided how to update promoted flavors. #Only the users with the appropiate roles could manage the promoted flavors. authorization() body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_flavor_modification_request_validator() validator.validate(body) modified_flavor = Flavor.deserialize(content_type, request.data) manager = FlavorSynchronizer() if not modified_flavor.nodes: modified_flavor = manager.publish_or_promote_flavor(flavor_id, modified_flavor) else: return Response("The method specified in the Request-Line is not allowed for the node list of infrastructures.", status=405) response_body = modified_flavor.serialize(request.accept_mimetypes) return Response(response_body, mimetype=request.accept_mimetypes[0][0])
def create_promotedflavor(): #Only the users with the appropiate roles could manage the promoted flavors. authorization() #if the user has the correct roles, they can manage the promoted flavors body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_flavor_request_validator() validator.validate(body) flavor = Flavor.deserialize(content_type, body) flavor.promoted = True flavor.public = True manager = FlavorSynchronizer() created_flavor = manager.create_promoted_flavor(flavor) print ("request.accept_mimetypes") print (request.accept_mimetypes) response_body = created_flavor.serialize(request.accept_mimetypes) return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
def _get_private_flavor(self, flavor_id): infrastructure = self.database_manager.get_infrastructure('Mordor') openstack_manager = OpenStackManager(infrastructure) openstack_flavor = openstack_manager.get_flavor(flavor_id) return Flavor.from_openstack_flavor(openstack_flavor, infrastructure)
def _create_private_flavor(self, flavor): infrastructure = self.database_manager.get_infrastructure('Mordor') openstack_manager = OpenStackManager(infrastructure) created_flavor = openstack_manager.create_flavor(flavor) return Flavor.from_openstack_flavor(created_flavor, infrastructure)
def _create_private_region_flavor(self, region, flavor): token = session['token_keystone'] infrastructure = self.database_manager.get_infrastructure(region) openstack_manager = OpenStackManager(region, token) created_flavor = openstack_manager.create_flavor(flavor) return Flavor.from_openstack_flavor(created_flavor, infrastructure)
def deserialize_json_flavor_test(): data = util.load_json_from_file('flavor_creation_request.json') flavor = Flavor.deserialize(util.JSON_MIMETYPE, json.dumps(data)) _check_flavor_model_contents(flavor)
def deserialize_xml_flavor_test(): data = util.load_clean_xml_payload('flavor_creation_request.xml') flavor = Flavor.deserialize(util.XML_MIMETYPE, data) _check_flavor_model_contents(flavor)