示例#1
0
    def _extract_server(self, node):
        """Marshal the server attribute of a parsed request"""
        server = {}
        server_node = self.find_first_child_named(node, 'server')

        attributes = [
            "name", "imageRef", "flavorRef", "adminPass", "accessIPv4",
            "accessIPv6"
        ]
        for attr in attributes:
            if server_node.getAttribute(attr):
                server[attr] = server_node.getAttribute(attr)

        metadata_node = self.find_first_child_named(server_node, "metadata")
        if metadata_node is not None:
            server["metadata"] = self.extract_metadata(metadata_node)

        personality = self._extract_personality(server_node)
        if personality is not None:
            server["personality"] = personality

        networks = self._extract_networks(server_node)
        if networks is not None:
            server["networks"] = networks

        security_groups = self._extract_security_groups(server_node)
        if security_groups is not None:
            server["security_groups"] = security_groups

        auto_disk_config = server_node.getAttribute('auto_disk_config')
        if auto_disk_config:
            server['auto_disk_config'] = utils.bool_from_str(auto_disk_config)

        return server
示例#2
0
    def _extract_server(self, node):
        """Marshal the server attribute of a parsed request"""
        server = {}
        server_node = self.find_first_child_named(node, 'server')

        attributes = ["name", "imageRef", "flavorRef", "adminPass",
                      "accessIPv4", "accessIPv6"]
        for attr in attributes:
            if server_node.getAttribute(attr):
                server[attr] = server_node.getAttribute(attr)

        metadata_node = self.find_first_child_named(server_node, "metadata")
        if metadata_node is not None:
            server["metadata"] = self.extract_metadata(metadata_node)

        personality = self._extract_personality(server_node)
        if personality is not None:
            server["personality"] = personality

        networks = self._extract_networks(server_node)
        if networks is not None:
            server["networks"] = networks

        security_groups = self._extract_security_groups(server_node)
        if security_groups is not None:
            server["security_groups"] = security_groups

        auto_disk_config = server_node.getAttribute('auto_disk_config')
        if auto_disk_config:
            server['auto_disk_config'] = utils.bool_from_str(auto_disk_config)

        return server
示例#3
0
    def _get_servers(self, req, is_detail):
        """Returns a list of servers, taking into account any search
        options specified.
        """

        search_opts = {}
        search_opts.update(req.str_GET)

        context = req.environ['engine.context']
        remove_invalid_options(context, search_opts,
                               self._get_server_search_options())

        # Convert local_zone_only into a boolean
        search_opts['local_zone_only'] = utils.bool_from_str(
            search_opts.get('local_zone_only', False))

        # If search by 'status', we need to convert it to 'vm_state'
        # to pass on to child zones.
        if 'status' in search_opts:
            status = search_opts['status']
            state = common.vm_state_from_status(status)
            if state is None:
                reason = _('Invalid server status: %(status)s') % locals()
                raise exception.InvalidInput(reason=reason)
            search_opts['vm_state'] = state

        if 'changes-since' in search_opts:
            try:
                parsed = utils.parse_isotime(search_opts['changes-since'])
            except ValueError:
                msg = _('Invalid changes-since value')
                raise exc.HTTPBadRequest(explanation=msg)
            search_opts['changes-since'] = parsed

        # By default, compute's get_all() will return deleted instances.
        # If an admin hasn't specified a 'deleted' search option, we need
        # to filter out deleted instances by setting the filter ourselves.
        # ... Unless 'changes-since' is specified, because 'changes-since'
        # should return recently deleted images according to the API spec.

        if 'deleted' not in search_opts:
            if 'changes-since' not in search_opts:
                # No 'changes-since', so we only want non-deleted servers
                search_opts['deleted'] = False

        instance_list = self.compute_api.get_all(context,
                                                 search_opts=search_opts)

        limited_list = self._limit_items(instance_list, req)
        if is_detail:
            self._add_instance_faults(context, limited_list)
            return self._view_builder.detail(req, limited_list)
        else:
            return self._view_builder.index(req, limited_list)
示例#4
0
    def _get_servers(self, req, is_detail):
        """Returns a list of servers, taking into account any search
        options specified.
        """

        search_opts = {}
        search_opts.update(req.str_GET)

        context = req.environ['engine.context']
        remove_invalid_options(context, search_opts,
                self._get_server_search_options())

        # Convert local_zone_only into a boolean
        search_opts['local_zone_only'] = utils.bool_from_str(
                search_opts.get('local_zone_only', False))

        # If search by 'status', we need to convert it to 'vm_state'
        # to pass on to child zones.
        if 'status' in search_opts:
            status = search_opts['status']
            state = common.vm_state_from_status(status)
            if state is None:
                reason = _('Invalid server status: %(status)s') % locals()
                raise exception.InvalidInput(reason=reason)
            search_opts['vm_state'] = state

        if 'changes-since' in search_opts:
            try:
                parsed = utils.parse_isotime(search_opts['changes-since'])
            except ValueError:
                msg = _('Invalid changes-since value')
                raise exc.HTTPBadRequest(explanation=msg)
            search_opts['changes-since'] = parsed

        # By default, compute's get_all() will return deleted instances.
        # If an admin hasn't specified a 'deleted' search option, we need
        # to filter out deleted instances by setting the filter ourselves.
        # ... Unless 'changes-since' is specified, because 'changes-since'
        # should return recently deleted images according to the API spec.

        if 'deleted' not in search_opts:
            if 'changes-since' not in search_opts:
                # No 'changes-since', so we only want non-deleted servers
                search_opts['deleted'] = False

        instance_list = self.compute_api.get_all(context,
                                                 search_opts=search_opts)

        limited_list = self._limit_items(instance_list, req)
        if is_detail:
            self._add_instance_faults(context, limited_list)
            return self._view_builder.detail(req, limited_list)
        else:
            return self._view_builder.index(req, limited_list)
示例#5
0
    def _GET_images(self, req, res, body):
        images = self._extract_resource_from_body(res, body,
            singular='image', singular_template=ImageDiskConfigTemplate(),
            plural='images', plural_template=ImagesDiskConfigTemplate())

        for image in images:
            metadata = image['metadata']

            if self.INTERNAL_DISK_CONFIG in metadata:
                raw_value = metadata[self.INTERNAL_DISK_CONFIG]
                value = utils.bool_from_str(raw_value)
                image[self.API_DISK_CONFIG] = disk_config_to_api(value)

        return res
示例#6
0
    def _GET_images(self, req, res, body):
        images = self._extract_resource_from_body(
            res,
            body,
            singular='image',
            singular_template=ImageDiskConfigTemplate(),
            plural='images',
            plural_template=ImagesDiskConfigTemplate())

        for image in images:
            metadata = image['metadata']

            if self.INTERNAL_DISK_CONFIG in metadata:
                raw_value = metadata[self.INTERNAL_DISK_CONFIG]
                value = utils.bool_from_str(raw_value)
                image[self.API_DISK_CONFIG] = disk_config_to_api(value)

        return res
示例#7
0
    def update(self, req, id, body):
        """Update server then pass on to version-specific controller"""
        if len(req.body) == 0:
            raise exc.HTTPUnprocessableEntity()

        if not body:
            raise exc.HTTPUnprocessableEntity()

        ctxt = req.environ['engine.context']
        update_dict = {}

        if 'name' in body['server']:
            name = body['server']['name']
            self._validate_server_name(name)
            update_dict['display_name'] = name.strip()

        if 'accessIPv4' in body['server']:
            access_ipv4 = body['server']['accessIPv4']
            update_dict['access_ip_v4'] = access_ipv4.strip()

        if 'accessIPv6' in body['server']:
            access_ipv6 = body['server']['accessIPv6']
            update_dict['access_ip_v6'] = access_ipv6.strip()

        if 'auto_disk_config' in body['server']:
            auto_disk_config = utils.bool_from_str(
                body['server']['auto_disk_config'])
            update_dict['auto_disk_config'] = auto_disk_config

        instance = self.compute_api.routing_get(ctxt, id)

        try:
            self.compute_api.update(ctxt, instance, **update_dict)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        instance.update(update_dict)

        self._add_instance_faults(ctxt, [instance])
        return self._view_builder.show(req, instance)
示例#8
0
    def update(self, req, id, body):
        """Update server then pass on to version-specific controller"""
        if len(req.body) == 0:
            raise exc.HTTPUnprocessableEntity()

        if not body:
            raise exc.HTTPUnprocessableEntity()

        ctxt = req.environ['engine.context']
        update_dict = {}

        if 'name' in body['server']:
            name = body['server']['name']
            self._validate_server_name(name)
            update_dict['display_name'] = name.strip()

        if 'accessIPv4' in body['server']:
            access_ipv4 = body['server']['accessIPv4']
            update_dict['access_ip_v4'] = access_ipv4.strip()

        if 'accessIPv6' in body['server']:
            access_ipv6 = body['server']['accessIPv6']
            update_dict['access_ip_v6'] = access_ipv6.strip()

        if 'auto_disk_config' in body['server']:
            auto_disk_config = utils.bool_from_str(
                    body['server']['auto_disk_config'])
            update_dict['auto_disk_config'] = auto_disk_config

        instance = self.compute_api.routing_get(ctxt, id)

        try:
            self.compute_api.update(ctxt, instance, **update_dict)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        instance.update(update_dict)

        self._add_instance_faults(ctxt, [instance])
        return self._view_builder.show(req, instance)
示例#9
0
 def test_bool_from_str(self):
     self.assertTrue(utils.bool_from_str('1'))
     self.assertTrue(utils.bool_from_str('2'))
     self.assertTrue(utils.bool_from_str('-1'))
     self.assertTrue(utils.bool_from_str('true'))
     self.assertTrue(utils.bool_from_str('True'))
     self.assertTrue(utils.bool_from_str('tRuE'))
     self.assertFalse(utils.bool_from_str('False'))
     self.assertFalse(utils.bool_from_str('false'))
     self.assertFalse(utils.bool_from_str('0'))
     self.assertFalse(utils.bool_from_str(None))
     self.assertFalse(utils.bool_from_str('junk'))
示例#10
0
 def test_bool_from_str(self):
     self.assertTrue(utils.bool_from_str('1'))
     self.assertTrue(utils.bool_from_str('2'))
     self.assertTrue(utils.bool_from_str('-1'))
     self.assertTrue(utils.bool_from_str('true'))
     self.assertTrue(utils.bool_from_str('True'))
     self.assertTrue(utils.bool_from_str('tRuE'))
     self.assertFalse(utils.bool_from_str('False'))
     self.assertFalse(utils.bool_from_str('false'))
     self.assertFalse(utils.bool_from_str('0'))
     self.assertFalse(utils.bool_from_str(None))
     self.assertFalse(utils.bool_from_str('junk'))