Beispiel #1
0
    def provision(self, server_uuid, target):
        """Asynchronous trigger the provisioning of the server.

        This will set the target provision state of the server, and
        a background task will begin which actually applies the state
        change. This call will return a 202 (Accepted) indicating the
        request was accepted and is in progress; the client should
        continue to GET the status of this server to observe the
        status of the requested action.

        :param server_uuid: UUID of a server.
        :param target: The desired provision state of the server or verb.
        """

        # Currently we only support rebuild target
        if target not in (states.REBUILD, ):
            raise exception.InvalidActionParameterValue(value=target,
                                                        action="provision",
                                                        server=server_uuid)

        db_server = self._resource or self._get_resource(server_uuid)
        if target == states.REBUILD:
            pecan.request.engine_api.rebuild(pecan.request.context, db_server)

        # Set the HTTP Location Header
        url_args = '/'.join([server_uuid, 'states'])
        pecan.response.location = link.build_url('servers', url_args)
Beispiel #2
0
    def power(self, server_uuid, target):
        """Set the power state of the server.

        :param server_uuid: the UUID of a server.
        :param target: the desired target to change power state,
                       on, off or reboot.
        :raises Conflict (HTTP 409): if a power operation is
                 already in progress.
        :raises BadRequest (HTTP 400): if the requested target
                 state is not valid or if the server is in CLEANING state.

        """
        if target not in ["on", "off", "reboot", "soft_off", "soft_reboot"]:
            # ironic will throw InvalidStateRequested
            raise exception.InvalidActionParameterValue(value=target,
                                                        action="power",
                                                        server=server_uuid)

        db_server = self._resource or self._get_resource(server_uuid)
        pecan.request.engine_api.power(pecan.request.context, db_server,
                                       target)
        # At present we do not catch the Exception from ironicclient.
        # Such as Conflict and BadRequest.
        # varify provision_state, if server is being cleaned,
        # don't change power state?

        # Set the HTTP Location Header, user can get the power_state
        # by locaton.
        url_args = '/'.join([server_uuid, 'states'])
        pecan.response.location = link.build_url('servers', url_args)
Beispiel #3
0
    def post(self, server):
        """Create a new server.

        :param server: a server within the request body.
        """
        validation.check_schema(server, server_schemas.create_server)
        scheduler_hints = server.get('scheduler_hints', {})
        server = server.get('server')

        min_count = server.get('min_count', 1)
        max_count = server.get('max_count', min_count)

        if min_count > max_count:
            msg = _('min_count must be <= max_count')
            raise wsme.exc.ClientSideError(msg,
                                           status_code=http_client.BAD_REQUEST)

        requested_networks = server.pop('networks', None)
        flavor_uuid = server.get('flavor_uuid')
        image_uuid = server.get('image_uuid')
        user_data = server.get('user_data')
        key_name = server.get('key_name')
        partitions = server.get('partitions')
        personality = server.pop('personality', None)

        password = self._get_server_admin_password(server)

        injected_files = []
        if personality:
            for item in personality:
                injected_files.append((item['path'], item['contents']))

        flavor = objects.Flavor.get(pecan.request.context, flavor_uuid)
        if flavor.disabled:
            raise exception.FlavorDisabled(flavor_id=flavor.uuid)
        servers = pecan.request.engine_api.create(
            pecan.request.context,
            flavor,
            image_uuid=image_uuid,
            name=server.get('name'),
            description=server.get('description'),
            availability_zone=server.get('availability_zone'),
            metadata=server.get('metadata'),
            requested_networks=requested_networks,
            user_data=user_data,
            injected_files=injected_files,
            admin_password=password,
            key_name=key_name,
            min_count=min_count,
            max_count=max_count,
            partitions=partitions,
            scheduler_hints=scheduler_hints)
        # Set the HTTP Location Header for the first server.
        pecan.response.location = link.build_url('server', servers[0].uuid)
        return Server.convert_with_links(servers[0])
Beispiel #4
0
    def post(self, flavor):
        """Create an new flavor.

        :param flavor: a flavor within the request body.
        """
        validation.check_schema(flavor, flavor_schema.create_flavor)
        new_flavor = objects.Flavor(pecan.request.context, **flavor)
        new_flavor.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('flavors', new_flavor.uuid)
        return Flavor.convert_with_links(new_flavor)
Beispiel #5
0
    def post(self, server_group):
        """Create an new server group.

        :param server_group: a server group within the request body.
        """
        validation.check_schema(server_group, sg_schema.create_server_group)
        new_server_group = objects.ServerGroup(pecan.request.context,
                                               **server_group)
        new_server_group.project_id = pecan.request.context.project_id
        new_server_group.user_id = pecan.request.context.user_id
        new_server_group.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('server_groups',
                                                 new_server_group.uuid)
        return ServerGroup.convert_with_links(new_server_group)
Beispiel #6
0
    def post(self, server):
        """Manage an existing bare metal node.

        :param server: A manageable server within the request body
        :return: The server information.
        """
        validation.check_schema(server, schema.manage_server)

        manageable_server = pecan.request.engine_api.manage(
            pecan.request.context, server.get('node_uuid'), server.get('name'),
            server.get('description'), server.get('metadata'))

        # Set the HTTP Location Header for the first server.
        pecan.response.location = link.build_url('server',
                                                 manageable_server.uuid)
        return Server.convert_with_links(manageable_server)
Beispiel #7
0
    def post(self, aggregate):
        """Create a new aggregate.

        :param aggregate: an aggregate within the request body.
        """
        validation.check_schema(aggregate, agg_schema.create_aggregate)
        metadata = aggregate.get('metadata')
        if metadata and 'availability_zone' in metadata:
            if not metadata['availability_zone']:
                msg = _("Aggregate %s does not support empty named "
                        "availability zone") % aggregate['name']
                raise wsme.exc.ClientSideError(
                    msg, status_code=http_client.BAD_REQUEST)

        new_aggregate = objects.Aggregate(pecan.request.context, **aggregate)
        new_aggregate.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('aggregates',
                                                 new_aggregate.uuid)
        return Aggregate.convert_with_links(new_aggregate)