Esempio n. 1
0
 def post(self):
     """Create a new network interface."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     obj = dbapi.net_interfaces_create(context, json)
     interface = jsonutils.to_primitive(obj)
     return interface, 200, None
Esempio n. 2
0
 def post(self):
     """Create a new network device."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     obj = dbapi.netdevices_create(context, json)
     device = jsonutils.to_primitive(obj)
     return device, 200, None
Esempio n. 3
0
 def post(self):
     """Create a new user. Requires project admin privileges."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     project_id = json["project_id"]
     dbapi.projects_get_by_id(context, project_id)
     api_key = uuidutils.generate_uuid()
     g.json["api_key"] = api_key
     user_obj = dbapi.users_create(context, json)
     return jsonutils.to_primitive(user_obj), 200, None
Esempio n. 4
0
 def post(self):
     """Create a new user. Requires project admin privileges."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     project_id = json["project_id"]
     dbapi.projects_get_by_id(context, project_id)
     api_key = uuidutils.generate_uuid()
     g.json["api_key"] = api_key
     user_obj = dbapi.users_create(context, json)
     return jsonutils.to_primitive(user_obj), 200, None
Esempio n. 5
0
    def post(self, context, request_data):
        """Create a new network interface."""
        json = util.copy_project_id_into_json(context, request_data)
        obj = dbapi.network_interfaces_create(context, json)
        interface = jsonutils.to_primitive(obj)

        location = v1.api.url_for(NetworkInterfaceById,
                                  id=obj.id,
                                  _external=True)
        headers = {'Location': location}

        return interface, 201, headers
Esempio n. 6
0
    def post(self, context, request_data):
        """Create a new user. Requires project admin privileges."""
        json = util.copy_project_id_into_json(context, request_data)
        project_id = json["project_id"]
        dbapi.projects_get_by_id(context, project_id)
        api_key = uuidutils.generate_uuid()
        request_data["api_key"] = api_key
        user_obj = dbapi.users_create(context, json)

        location = v1.api.url_for(UserById, id=user_obj.id, _external=True)
        headers = {'Location': location}

        return jsonutils.to_primitive(user_obj), 201, headers
Esempio n. 7
0
    def post(self, context, request_data):
        """Create a new cloud."""
        json = util.copy_project_id_into_json(context, request_data)
        cloud_obj = dbapi.clouds_create(context, json)
        cloud = jsonutils.to_primitive(cloud_obj)
        if 'variables' in json:
            cloud["variables"] = jsonutils.to_primitive(cloud_obj.variables)
        else:
            cloud["variables"] = {}

        location = v1.api.url_for(CloudsById, id=cloud_obj.id, _external=True)
        headers = {'Location': location}

        return cloud, 201, headers
Esempio n. 8
0
    def post(self, context, request_data):
        """Create a new region."""
        json = util.copy_project_id_into_json(context, request_data)
        region_obj = dbapi.regions_create(context, json)
        region = jsonutils.to_primitive(region_obj)
        if 'variables' in json:
            region["variables"] = jsonutils.to_primitive(region_obj.variables)
        else:
            region["variables"] = {}

        location = v1.api.url_for(RegionsById,
                                  id=region_obj.id,
                                  _external=True)
        headers = {'Location': location}

        return region, 201, headers
Esempio n. 9
0
    def post(self, context, request_data):
        """Create a new network device."""
        json = util.copy_project_id_into_json(context, request_data)
        obj = dbapi.network_devices_create(context, json)
        device = jsonutils.to_primitive(obj)
        if 'variables' in json:
            device["variables"] = jsonutils.to_primitive(obj.variables)
        else:
            device["variables"] = {}

        utils.add_up_link(context, device)

        location = v1.api.url_for(NetworkDeviceById, id=obj.id, _external=True)
        headers = {'Location': location}

        return device, 201, headers
Esempio n. 10
0
    def post(self, context, request_data):
        """Create a new host."""
        json = util.copy_project_id_into_json(context, request_data)
        host_obj = dbapi.hosts_create(context, json)
        host = jsonutils.to_primitive(host_obj)
        if 'variables' in json:
            host["variables"] = jsonutils.to_primitive(host_obj.variables)
        else:
            host["variables"] = {}

        utils.add_up_link(context, host)

        location = v1.api.url_for(HostById, id=host_obj.id, _external=True)
        headers = {'Location': location}

        return host, 201, headers
Esempio n. 11
0
    def post(self, context, request_data):
        """Create a new network."""
        json = util.copy_project_id_into_json(context, request_data)
        network_obj = dbapi.networks_create(context, json)
        network = jsonutils.to_primitive(network_obj)
        if 'variables' in json:
            network["variables"] = jsonutils.to_primitive(
                network_obj.variables)
        else:
            network["variables"] = {}

        location = v1.api.url_for(NetworkById,
                                  id=network_obj.id,
                                  _external=True)
        headers = {'Location': location}

        return network, 201, headers
Esempio n. 12
0
 def post(self):
     """Create a new network."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     network_obj = dbapi.networks_create(context, json)
     return jsonutils.to_primitive(network_obj), 200, None
Esempio n. 13
0
 def test_adds_project_id_to_json(self):
     """Verify we add the project_id to the json body."""
     project_id = uuid.uuid4().hex
     self.context.tenant = project_id
     json = util.copy_project_id_into_json(self.context, {})
     self.assertDictEqual({'project_id': project_id}, json)
Esempio n. 14
0
 def test_defaults_project_id_to_zero(self):
     """Verify if there's no tenant attribute on the context we use 0."""
     del self.context.tenant
     json = util.copy_project_id_into_json(self.context, {})
     self.assertDictEqual({'project_id': ''}, json)
Esempio n. 15
0
 def test_adds_project_id_to_json(self):
     """Verify we add the project_id to the json body."""
     project_id = uuid.uuid4().hex
     self.context.tenant = project_id
     json = util.copy_project_id_into_json(self.context, {})
     self.assertDictEqual({'project_id': project_id}, json)
Esempio n. 16
0
 def test_defaults_project_id_to_zero(self):
     """Verify if there's no tenant attribute on the context we use 0."""
     del self.context.tenant
     json = util.copy_project_id_into_json(self.context, {})
     self.assertDictEqual({'project_id': ''}, json)
Esempio n. 17
0
 def post(self):
     """Create a new network."""
     context = request.environ.get('context')
     json = util.copy_project_id_into_json(context, g.json)
     network_obj = dbapi.networks_create(context, json)
     return jsonutils.to_primitive(network_obj), 200, None