Esempio n. 1
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, 'baymodel:create',
                       action='baymodel:create')
        baymodel_dict = baymodel.as_dict()
        cli = clients.OpenStackClients(context)
        attr_validator.validate_os_resources(context, baymodel_dict)
        image_data = attr_validator.validate_image(cli,
                                                   baymodel_dict['image_id'])
        baymodel_dict['cluster_distro'] = image_data['os_distro']
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        # check permissions for making baymodel public
        if baymodel_dict['public']:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.ClusterTemplatePublishDenied()

        # NOTE(yuywz): We will generate a random human-readable name for
        # baymodel if the name is not spcified by user.
        arg_name = baymodel_dict.get('name')
        name = arg_name or self._generate_name_for_baymodel(context)
        baymodel_dict['name'] = name

        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 2
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        self.check_keypair_exists(context, baymodel_dict['keypair_id'])
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        image_data = self._get_image_data(context, baymodel_dict['image_id'])
        if image_data.get('os_distro'):
            baymodel_dict['cluster_distro'] = image_data['os_distro']
        else:
            raise exception.OSDistroFieldNotFound(
                image_id=baymodel_dict['image_id'])
        # check permissions for making baymodel public
        if baymodel_dict['public']:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 3
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        cli = clients.OpenStackClients(context)
        attr_validator.validate_keypair(cli, baymodel_dict['keypair_id'])
        image_data = attr_validator.validate_image(cli,
                                                   baymodel_dict['image_id'])
        baymodel_dict['cluster_distro'] = image_data['os_distro']
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        # check permissions for making baymodel public
        if baymodel_dict['public']:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 4
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        if self.from_baymodels:
            raise exception.OperationNotPermitted

        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        baymodel_dict['project_id'] = auth_token['project']['id']
        baymodel_dict['user_id'] = auth_token['user']['id']
        image_data = self._get_image_data(context, baymodel_dict['image_id'])
        if image_data.get('os_distro'):
            baymodel_dict['cluster_distro'] = image_data['os_distro']
        else:
            raise exception.OSDistroFieldNotFound(
                image_id=baymodel_dict['image_id'])
        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 5
0
File: bay.py Progetto: voa808/magnum
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, 'bay:create',
                       action='bay:create')
        baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
        attr_validator.validate_os_resources(context, baymodel.as_dict())
        attr_validator.validate_master_count(bay.as_dict(), baymodel.as_dict())
        bay_dict = bay.as_dict()
        bay_dict['project_id'] = context.project_id
        bay_dict['user_id'] = context.user_id
        # NOTE(yuywz): We will generate a random human-readable name for
        # bay if the name is not spcified by user.
        name = bay_dict.get('name') or self._generate_name_for_bay(context)
        bay_dict['name'] = name

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 6
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        new_bay = self._post(bay)
        res_bay = pecan.request.rpcapi.cluster_create(new_bay,
                                                      bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 7
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        if self.from_pods:
            raise exception.OperationNotPermitted

        new_pod = objects.Pod(pecan.request.context,
                                **pod.as_dict())
        new_pod.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Esempio n. 8
0
    def post(self, node):
        """Create a new node.

        :param node: a node within the request body.
        """
        node_dict = node.as_dict()
        context = pecan.request.context
        node_dict['project_id'] = context.project_id
        node_dict['user_id'] = context.user_id
        new_node = objects.Node(context, **node_dict)
        new_node.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('nodes', new_node.uuid)
        return Node.convert_with_links(new_node)
Esempio n. 9
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        if self.from_bays:
            raise exception.OperationNotPermitted

        new_bay = objects.Bay(pecan.request.context,
                                **bay.as_dict())
        new_bay.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', new_bay.uuid)
        return Bay.convert_with_links(new_bay)
Esempio n. 10
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        if self.from_containers:
            raise exception.OperationNotPermitted

        new_container = objects.Container(pecan.request.context,
                                **container.as_dict())
        new_container.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('containers',
                                                 new_container.uuid)
        return Container.convert_with_links(new_container)
Esempio n. 11
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        pod.parse_manifest()
        pod_dict = pod.as_dict()
        context = pecan.request.context
        pod_dict['project_id'] = context.project_id
        pod_dict['user_id'] = context.user_id
        pod_obj = objects.Pod(context, **pod_dict)
        new_pod = pecan.request.rpcapi.pod_create(pod_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Esempio n. 12
0
    def post(self, x509keypair):
        """Create a new x509keypair.

        :param x509keypair: a x509keypair within the request body.
        """
        x509keypair_dict = x509keypair.as_dict()
        context = pecan.request.context
        x509keypair_dict['project_id'] = context.project_id
        x509keypair_dict['user_id'] = context.user_id
        x509keypair_obj = objects.X509KeyPair(context, **x509keypair_dict)
        new_x509keypair = pecan.request.rpcapi.x509keypair_create(
            x509keypair_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('x509keypairs',
                                                 new_x509keypair.uuid)
        return X509KeyPair.convert_with_links(new_x509keypair)
Esempio n. 13
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        container_dict = container.as_dict()
        context = pecan.request.context
        container_dict["project_id"] = context.project_id
        container_dict["user_id"] = context.user_id
        new_container = objects.Container(context, **container_dict)
        new_container.create()
        res_container = pecan.request.rpcapi.container_create(new_container)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url("containers", res_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 14
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        container_dict = container.as_dict()
        context = pecan.request.context
        container_dict['project_id'] = context.project_id
        container_dict['user_id'] = context.user_id
        new_container = objects.Container(context, **container_dict)
        new_container.create()
        res_container = pecan.request.rpcapi.container_create(new_container)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('containers',
                                                 res_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 15
0
    def post(self, x509keypair):
        """Create a new x509keypair.

        :param x509keypair: a x509keypair within the request body.
        """
        x509keypair_dict = x509keypair.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        x509keypair_dict['project_id'] = auth_token['project']['id']
        x509keypair_dict['user_id'] = auth_token['user']['id']
        x509keypair_obj = objects.X509KeyPair(context, **x509keypair_dict)
        new_x509keypair = pecan.request.rpcapi.x509keypair_create(
            x509keypair_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('x509keypairs',
                                                 new_x509keypair.uuid)
        return X509KeyPair.convert_with_links(new_x509keypair)
Esempio n. 16
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        container_dict = container.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        container_dict['project_id'] = auth_token['project']['id']
        container_dict['user_id'] = auth_token['user']['id']
        new_container = objects.Container(context, **container_dict)
        new_container.create()
        res_container = pecan.request.rpcapi.container_create(new_container)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('containers',
                                                 res_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 17
0
    def post(self, node):
        """Create a new node.

        :param node: a node within the request body.
        """
        if self.from_nodes:
            raise exception.OperationNotPermitted

        node_dict = node.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        node_dict['project_id'] = auth_token['project']['id']
        node_dict['user_id'] = auth_token['user']['id']
        new_node = objects.Node(context, **node_dict)
        new_node.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('nodes', new_node.uuid)
        return Node.convert_with_links(new_node)
Esempio n. 18
0
    def post(self, node):
        """Create a new node.

        :param node: a node within the request body.
        """
        if self.from_nodes:
            raise exception.OperationNotPermitted

        node_dict = node.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        node_dict['project_id'] = auth_token['project']['id']
        node_dict['user_id'] = auth_token['user']['id']
        new_node = objects.Node(context, **node_dict)
        new_node.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('nodes', new_node.uuid)
        return Node.convert_with_links(new_node)
Esempio n. 19
0
    def post(self, rc):
        """Create a new ReplicationController.

        :param rc: a ReplicationController within the request body.
        """
        rc.parse_manifest()
        rc_dict = rc.as_dict()
        context = pecan.request.context
        rc_dict['project_id'] = context.project_id
        rc_dict['user_id'] = context.user_id
        rc_obj = objects.ReplicationController(context, **rc_dict)
        new_rc = pecan.request.rpcapi.rc_create(rc_obj)
        if not new_rc:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('rcs', new_rc.uuid)
        return ReplicationController.convert_with_links(new_rc)
Esempio n. 20
0
    def post(self, service):
        """Create a new service.

        :param service: a service within the request body.
        """
        service.parse_manifest()
        service_dict = service.as_dict()
        context = pecan.request.context
        service_dict['project_id'] = context.project_id
        service_dict['user_id'] = context.user_id
        service_obj = objects.Service(context, **service_dict)
        new_service = pecan.request.rpcapi.service_create(service_obj)
        if new_service is None:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('services', new_service.uuid)
        return Service.convert_with_links(new_service)
Esempio n. 21
0
    def post(self, service):
        """Create a new service.

        :param service: a service within the request body.
        """
        service.parse_manifest()
        service_dict = service.as_dict()
        context = pecan.request.context
        service_dict['project_id'] = context.project_id
        service_dict['user_id'] = context.user_id
        service_obj = objects.Service(context, **service_dict)
        new_service = pecan.request.rpcapi.service_create(service_obj)
        if new_service is None:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('services', new_service.uuid)
        return Service.convert_with_links(new_service)
Esempio n. 22
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        bay_dict['project_id'] = auth_token['project']['id']
        bay_dict['user_id'] = auth_token['user']['id']
        new_bay = objects.Bay(context, **bay_dict)
        if isinstance(bay.bay_create_timeout, wsme.types.UnsetType):
            bay.bay_create_timeout = 0
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 23
0
    def post(self, rc):
        """Create a new ReplicationController.

        :param rc: a ReplicationController within the request body.
        """
        if self.from_rcs:
            raise exception.OperationNotPermitted

        rc.parse_manifest()
        rc_dict = rc.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        rc_dict['project_id'] = auth_token['project']['id']
        rc_dict['user_id'] = auth_token['user']['id']
        rc_obj = objects.ReplicationController(context, **rc_dict)
        new_rc = pecan.request.rpcapi.rc_create(rc_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('rcs', new_rc.uuid)
        return ReplicationController.convert_with_links(new_rc)
Esempio n. 24
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        if self.from_pods:
            raise exception.OperationNotPermitted

        pod.parse_manifest()
        pod_dict = pod.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        pod_dict['project_id'] = auth_token['project']['id']
        pod_dict['user_id'] = auth_token['user']['id']
        pod_obj = objects.Pod(context, **pod_dict)
        new_pod = pecan.request.rpcapi.pod_create(pod_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Esempio n. 25
0
    def post(self, pod):
        """Create a new pod.

        :param pod: a pod within the request body.
        """
        if self.from_pods:
            raise exception.OperationNotPermitted

        pod.parse_manifest()
        pod_dict = pod.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        pod_dict['project_id'] = auth_token['project']['id']
        pod_dict['user_id'] = auth_token['user']['id']
        pod_obj = objects.Pod(context, **pod_dict)
        new_pod = pecan.request.rpcapi.pod_create(pod_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('pods', new_pod.uuid)
        return Pod.convert_with_links(new_pod)
Esempio n. 26
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        bay_dict["project_id"] = context.project_id
        bay_dict["user_id"] = context.user_id
        # NOTE(suro-patz): Apply default node_count is 1, None -> 1
        if bay_dict.get("node_count", None) is None:
            bay_dict["node_count"] = 1

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay, bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url("bays", res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 27
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        if self.from_bays:
            raise exception.OperationNotPermitted

        bay_dict = bay.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        bay_dict['project_id'] = auth_token['project']['id']
        bay_dict['user_id'] = auth_token['user']['id']
        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 28
0
    def post(self, service):
        """Create a new service.

        :param service: a service within the request body.
        """
        if self.from_services:
            raise exception.OperationNotPermitted

        service.parse_manifest()
        service_dict = service.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        service_dict['project_id'] = auth_token['project']['id']
        service_dict['user_id'] = auth_token['user']['id']
        service_obj = objects.Service(context, **service_dict)
        new_service = pecan.request.rpcapi.service_create(service_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('services', new_service.uuid)
        return Service.convert_with_links(new_service)
Esempio n. 29
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        if self.from_baymodels:
            raise exception.OperationNotPermitted

        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        baymodel_dict['project_id'] = auth_token['project']['id']
        baymodel_dict['user_id'] = auth_token['user']['id']
        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 30
0
    def post(self, cluster_template):
        """Create a new ClusterTemplate.

        :param cluster_template: a ClusterTemplate within the request body.
        """
        context = pecan.request.context
        policy.enforce(context,
                       'clustertemplate:create',
                       action='clustertemplate:create')
        cluster_template_dict = cluster_template.as_dict()
        cli = clients.OpenStackClients(context)
        attr_validator.validate_os_resources(context, cluster_template_dict)
        image_data = attr_validator.validate_image(
            cli, cluster_template_dict['image_id'])
        cluster_template_dict['cluster_distro'] = image_data['os_distro']
        cluster_template_dict['project_id'] = context.project_id
        cluster_template_dict['user_id'] = context.user_id
        # check permissions for making cluster_template public or hidden
        if cluster_template_dict['public'] or cluster_template_dict['hidden']:
            if not policy.enforce(
                    context, "clustertemplate:publish", None, do_raise=False):
                raise exception.ClusterTemplatePublishDenied()

        if (cluster_template.docker_storage_driver
                in ('devicemapper', 'overlay')):
            warnings.warn(self._devicemapper_overlay_deprecation_note,
                          DeprecationWarning)
            LOG.warning(self._devicemapper_overlay_deprecation_note)

        # NOTE(yuywz): We will generate a random human-readable name for
        # cluster_template if the name is not specified by user.
        arg_name = cluster_template_dict.get('name')
        name = arg_name or self._generate_name_for_cluster_template(context)
        cluster_template_dict['name'] = name

        new_cluster_template = objects.ClusterTemplate(context,
                                                       **cluster_template_dict)
        new_cluster_template.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('clustertemplates',
                                                 new_cluster_template.uuid)
        return ClusterTemplate.convert_with_links(new_cluster_template)
Esempio n. 31
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        bay_dict['project_id'] = context.project_id
        bay_dict['user_id'] = context.user_id
        # NOTE(suro-patz): Apply default node_count is 1, None -> 1
        if bay_dict.get('node_count', None) is None:
            bay_dict['node_count'] = 1

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 32
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        container_dict = container.as_dict()
        check_policy_on_bay(container_dict['bay_uuid'], "container:create")
        context = pecan.request.context
        container_dict['project_id'] = context.project_id
        container_dict['user_id'] = context.user_id
        if 'memory' in container_dict:
            api_utils.validate_docker_memory(container_dict['memory'])
        new_container = objects.Container(context, **container_dict)
        new_container.create()
        res_container = pecan.request.rpcapi.container_create(new_container)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('containers',
                                                 res_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 33
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        image_data = self._get_image_data(context, baymodel_dict['image_id'])
        if image_data.get('os_distro'):
            baymodel_dict['cluster_distro'] = image_data['os_distro']
        else:
            raise exception.OSDistroFieldNotFound(
                image_id=baymodel_dict['image_id'])
        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 34
0
File: bay.py Progetto: yamt/magnum
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        attr_validator.validate_os_resources(context,
                                             bay_dict.get('baymodel_id'))
        bay_dict['project_id'] = context.project_id
        bay_dict['user_id'] = context.user_id
        if bay_dict.get('name') is None:
            bay_dict['name'] = None

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 35
0
File: bay.py Progetto: sidx64/magnum
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        attr_validator.validate_os_resources(context,
                                             bay_dict.get('baymodel_id'))
        bay_dict['project_id'] = context.project_id
        bay_dict['user_id'] = context.user_id
        if bay_dict.get('name') is None:
            bay_dict['name'] = None

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 36
0
    def post(self, service):
        """Create a new service.

        :param service: a service within the request body.
        """
        if self.from_services:
            raise exception.OperationNotPermitted

        service.parse_manifest()
        service_dict = service.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info["token"]
        service_dict["project_id"] = auth_token["project"]["id"]
        service_dict["user_id"] = auth_token["user"]["id"]
        service_obj = objects.Service(context, **service_dict)
        new_service = pecan.request.rpcapi.service_create(service_obj)
        if new_service is None:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url("services", new_service.uuid)
        return Service.convert_with_links(new_service)
Esempio n. 37
0
    def post(self, rc):
        """Create a new ReplicationController.

        :param rc: a ReplicationController within the request body.
        """
        if self.from_rcs:
            raise exception.OperationNotPermitted

        rc.parse_manifest()
        rc_dict = rc.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        rc_dict['project_id'] = auth_token['project']['id']
        rc_dict['user_id'] = auth_token['user']['id']
        rc_obj = objects.ReplicationController(context, **rc_dict)
        new_rc = pecan.request.rpcapi.rc_create(rc_obj)
        if not new_rc:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('rcs', new_rc.uuid)
        return ReplicationController.convert_with_links(new_rc)
Esempio n. 38
0
    def post(self, container):
        """Create a new container.

        :param container: a container within the request body.
        """
        if self.from_containers:
            raise exception.OperationNotPermitted

        container_dict = container.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        container_dict['project_id'] = auth_token['project']['id']
        container_dict['user_id'] = auth_token['user']['id']
        new_container = objects.Container(context, **container_dict)
        new_container.create()
        res_container = backend_api.container_create(new_container.name,
                                                     new_container.uuid,
                                                     new_container)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('containers',
                                                 res_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 39
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        bay_dict = bay.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        bay_dict['project_id'] = auth_token['project']['id']
        bay_dict['user_id'] = auth_token['user']['id']
        # NOTE(suro-patz): Apply default node_count is 1, None -> 1
        if bay_dict.get('node_count', None) is None:
            bay_dict['node_count'] = 1

        new_bay = objects.Bay(context, **bay_dict)
        if isinstance(bay.bay_create_timeout, wsme.types.UnsetType):
            bay.bay_create_timeout = 0
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 40
0
    def post(self, bay):
        """Create a new bay.

        :param bay: a bay within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, 'bay:create', action='bay:create')
        baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
        attr_validator.validate_os_resources(context, baymodel.as_dict())
        bay_dict = bay.as_dict()
        bay_dict['project_id'] = context.project_id
        bay_dict['user_id'] = context.user_id
        # NOTE(yuywz): We will generate a random human-readable name for
        # bay if the name is not spcified by user.
        name = bay_dict.get('name') or self._generate_name_for_bay(context)
        bay_dict['name'] = name

        new_bay = objects.Bay(context, **bay_dict)
        res_bay = pecan.request.rpcapi.bay_create(new_bay,
                                                  bay.bay_create_timeout)

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('bays', res_bay.uuid)
        return Bay.convert_with_links(res_bay)
Esempio n. 41
0
    def post(self, cluster_template):
        """Create a new ClusterTemplate.

        :param cluster_template: a ClusterTemplate within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, 'clustertemplate:create',
                       action='clustertemplate:create')
        cluster_template_dict = cluster_template.as_dict()
        cli = clients.OpenStackClients(context)
        attr_validator.validate_os_resources(context, cluster_template_dict)
        image_data = attr_validator.validate_image(cli,
                                                   cluster_template_dict[
                                                       'image_id'])
        cluster_template_dict['cluster_distro'] = image_data['os_distro']
        cluster_template_dict['project_id'] = context.project_id
        cluster_template_dict['user_id'] = context.user_id
        # check permissions for making cluster_template public
        if cluster_template_dict['public']:
            if not policy.enforce(context, "clustertemplate:publish", None,
                                  do_raise=False):
                raise exception.ClusterTemplatePublishDenied()

        # NOTE(yuywz): We will generate a random human-readable name for
        # cluster_template if the name is not specified by user.
        arg_name = cluster_template_dict.get('name')
        name = arg_name or self._generate_name_for_cluster_template(context)
        cluster_template_dict['name'] = name

        new_cluster_template = objects.ClusterTemplate(context,
                                                       **cluster_template_dict)
        new_cluster_template.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('clustertemplates',
                                                 new_cluster_template.uuid)
        return ClusterTemplate.convert_with_links(new_cluster_template)