Example #1
0
 def test_compare_micros(self):
     zulu = utils.parse_isotime('2012-02-14T20:53:07.6544')
     east = utils.parse_isotime('2012-02-14T19:53:07.654321-01:00')
     west = utils.parse_isotime('2012-02-14T21:53:07.655+01:00')
     self.assertTrue(east < west)
     self.assertTrue(east < zulu)
     self.assertTrue(zulu < west)
Example #2
0
 def test_compare(self):
     zulu = utils.parse_isotime('2012-02-14T20:53:07')
     east = utils.parse_isotime('2012-02-14T20:53:07-01:00')
     west = utils.parse_isotime('2012-02-14T20:53:07+01:00')
     self.assertTrue(east > west)
     self.assertTrue(east > zulu)
     self.assertTrue(zulu > west)
Example #3
0
 def test_compare(self):
     zulu = utils.parse_isotime('2012-02-14T20:53:07')
     east = utils.parse_isotime('2012-02-14T20:53:07-01:00')
     west = utils.parse_isotime('2012-02-14T20:53:07+01:00')
     self.assertTrue(east > west)
     self.assertTrue(east > zulu)
     self.assertTrue(zulu > west)
Example #4
0
 def test_compare_micros(self):
     zulu = utils.parse_isotime('2012-02-14T20:53:07.6544')
     east = utils.parse_isotime('2012-02-14T19:53:07.654321-01:00')
     west = utils.parse_isotime('2012-02-14T21:53:07.655+01:00')
     self.assertTrue(east < west)
     self.assertTrue(east < zulu)
     self.assertTrue(zulu < west)
Example #5
0
 def __init__(self, user, project, is_admin=None, read_deleted=False,
              remote_address=None, timestamp=None, request_id=None):
     if hasattr(user, 'id'):
         self._user = user
         self.user_id = user.id
     else:
         self._user = None
         self.user_id = user
     if hasattr(project, 'id'):
         self._project = project
         self.project_id = project.id
     else:
         self._project = None
         self.project_id = project
     if is_admin is None:
         if self.user_id and self.user:
             self.is_admin = self.user.is_admin()
         else:
             self.is_admin = False
     else:
         self.is_admin = is_admin
     self.read_deleted = read_deleted
     self.remote_address = remote_address
     if not timestamp:
         timestamp = utils.utcnow()
     if isinstance(timestamp, str) or isinstance(timestamp, unicode):
         timestamp = utils.parse_isotime(timestamp)
     self.timestamp = timestamp
     if not request_id:
         chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-'
         request_id = ''.join([random.choice(chars) for x in xrange(20)])
     self.request_id = request_id
Example #6
0
    def _get_servers(self, req, is_detail):
        """Returns a list of servers, based on any search options specified."""

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

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

        # Verify search by 'status' contains a valid status.
        # Convert it to filter by vm_state for compute_api.
        status = search_opts.pop('status', None)
        if status is not None:
            state = common.vm_state_from_status(status)
            if state is None:
                msg = _('Invalid server status: %(status)s') % locals()
                raise exc.HTTPBadRequest(explanation=msg)
            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

        # NOTE(dprince) This prevents computes' get_all() from returning
        # instances from multiple tenants when an admin accounts is used.
        # By default non-admin accounts are always limited to project/user
        # both here and in the compute API.
        if not context.is_admin or (context.is_admin and 'all_tenants'
            not in search_opts):
            if context.project_id:
                search_opts['project_id'] = context.project_id
            else:
                search_opts['user_id'] = context.user_id

        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)
Example #7
0
    def _get_servers(self, req, is_detail):
        """Returns a list of servers, based on any search options specified."""

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

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

        # Verify search by 'status' contains a valid status.
        # Convert it to filter by vm_state for compute_api.
        status = search_opts.pop('status', None)
        if status is not None:
            state = common.vm_state_from_status(status)
            if state is None:
                msg = _('Invalid server status: %(status)s') % locals()
                raise exc.HTTPBadRequest(explanation=msg)
            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

        # NOTE(dprince) This prevents computes' get_all() from returning
        # instances from multiple tenants when an admin accounts is used.
        # By default non-admin accounts are always limited to project/user
        # both here and in the compute API.
        if not context.is_admin or (context.is_admin and 'all_tenants'
            not in search_opts):
            if context.project_id:
                search_opts['project_id'] = context.project_id
            else:
                search_opts['user_id'] = context.user_id

        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)
Example #8
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['nova.context']
        remove_invalid_options(context, search_opts,
                               self._get_server_search_options())

        # Convert recurse_zones into a boolean
        search_opts['recurse_zones'] = utils.bool_from_str(
            search_opts.get('recurse_zones', 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)
        servers = [
            self._build_view(req, inst, is_detail)['server']
            for inst in limited_list
        ]

        return dict(servers=servers)
Example #9
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['nova.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)
Example #10
0
 def __init__(self, tenant, user, groups=None, remote_address=None, timestamp=None, request_id=None):
     self.user = user
     self.tenant = tenant
     self.groups = groups and groups or []
     self.remote_address = remote_address
     if not timestamp:
         timestamp = utils.utcnow()
     if isinstance(timestamp, str) or isinstance(timestamp, unicode):
         timestamp = utils.parse_isotime(timestamp)
     self.timestamp = timestamp
     if not request_id:
         chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-"
         request_id = "".join([random.choice(chars) for x in xrange(20)])
     self.request_id = request_id
Example #11
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["nova.context"]
        remove_invalid_options(context, search_opts, self._get_server_search_options())

        # Convert recurse_zones into a boolean
        search_opts["recurse_zones"] = utils.bool_from_str(search_opts.get("recurse_zones", 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)
        servers = [self._build_view(req, inst, is_detail)["server"] for inst in limited_list]

        return dict(servers=servers)
Example #12
0
 def __init__(self, tenant, user, groups=None, remote_address=None,
              timestamp=None, request_id=None):
     self.user = user
     self.tenant = tenant
     self.groups = groups and groups or []
     self.remote_address = remote_address
     if not timestamp:
         timestamp = utils.utcnow()
     if isinstance(timestamp, str) or isinstance(timestamp, unicode):
         timestamp = utils.parse_isotime(timestamp)
     self.timestamp = timestamp
     if not request_id:
         chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-'
         request_id = ''.join([random.choice(chars) for x in xrange(20)])
     self.request_id = request_id
Example #13
0
 def __init__(self,
              user,
              project,
              is_admin=None,
              read_deleted=False,
              remote_address=None,
              timestamp=None,
              request_id=None):
     if hasattr(user, 'id'):
         self._user = user
         self.user_id = user.id
     else:
         self._user = None
         self.user_id = user
     if hasattr(project, 'id'):
         self._project = project
         self.project_id = project.id
     else:
         self._project = None
         self.project_id = project
     if is_admin is None:
         if self.user_id and self.user:
             self.is_admin = self.user.is_admin()
         else:
             self.is_admin = False
     else:
         self.is_admin = is_admin
     self.read_deleted = read_deleted
     self.remote_address = remote_address
     if not timestamp:
         timestamp = utils.utcnow()
     if isinstance(timestamp, str) or isinstance(timestamp, unicode):
         timestamp = utils.parse_isotime(timestamp)
     self.timestamp = timestamp
     if not request_id:
         chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-'
         request_id = ''.join([random.choice(chars) for x in xrange(20)])
     self.request_id = request_id
Example #14
0
 def test_east_normalize(self):
     str = '2012-02-14T20:53:07-07:00'
     east = utils.parse_isotime(str)
     normed = utils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 03, 53, 07, 0)
Example #15
0
 def test_zulu_normalize(self):
     str = '2012-02-14T20:53:07Z'
     zulu = utils.parse_isotime(str)
     normed = utils.normalize_time(zulu)
     self._instaneous(normed, 2012, 2, 14, 20, 53, 07, 0)
Example #16
0
 def test_now_roundtrip(self):
     str = utils.isotime()
     now = utils.parse_isotime(str)
     self.assertEquals(now.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(utils.isotime(now), str)
Example #17
0
 def test_west_roundtrip(self):
     str = '2012-02-14T20:53:07+11:30'
     west = utils.parse_isotime(str)
     self.assertEquals(west.tzinfo.tzname(None), '+11:30')
     self.assertEquals(utils.isotime(west), str)
Example #18
0
 def test_east_roundtrip(self):
     str = '2012-02-14T20:53:07-07:00'
     east = utils.parse_isotime(str)
     self.assertEquals(east.tzinfo.tzname(None), '-07:00')
     self.assertEquals(utils.isotime(east), str)
Example #19
0
 def test_zulu_roundtrip(self):
     str = '2012-02-14T20:53:07Z'
     zulu = utils.parse_isotime(str)
     self.assertEquals(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(utils.isotime(zulu), str)
Example #20
0
 def test_east_normalize(self):
     str = '2012-02-14T20:53:07-07:00'
     east = utils.parse_isotime(str)
     normed = utils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 03, 53, 07, 0)
Example #21
0
 def _do_test(self, str, yr, mon, day, hr, min, sec, micro, shift):
     DAY_SECONDS = 24 * 60 * 60
     timestamp = utils.parse_isotime(str)
     self._instaneous(timestamp, yr, mon, day, hr, min, sec, micro)
     offset = timestamp.tzinfo.utcoffset(None)
     self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
Example #22
0
 def _do_test(self, str, yr, mon, day, hr, min, sec, micro, shift):
     DAY_SECONDS = 24 * 60 * 60
     timestamp = utils.parse_isotime(str)
     self._instaneous(timestamp, yr, mon, day, hr, min, sec, micro)
     offset = timestamp.tzinfo.utcoffset(None)
     self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
Example #23
0
 def test_zulu_roundtrip(self):
     str = '2012-02-14T20:53:07Z'
     zulu = utils.parse_isotime(str)
     self.assertEquals(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(utils.isotime(zulu), str)
Example #24
0
 def test_east_roundtrip(self):
     str = '2012-02-14T20:53:07-07:00'
     east = utils.parse_isotime(str)
     self.assertEquals(east.tzinfo.tzname(None), '-07:00')
     self.assertEquals(utils.isotime(east), str)
Example #25
0
 def test_west_roundtrip(self):
     str = '2012-02-14T20:53:07+11:30'
     west = utils.parse_isotime(str)
     self.assertEquals(west.tzinfo.tzname(None), '+11:30')
     self.assertEquals(utils.isotime(west), str)
Example #26
0
 def test_now_roundtrip(self):
     str = utils.isotime()
     now = utils.parse_isotime(str)
     self.assertEquals(now.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(utils.isotime(now), str)
Example #27
0
 def test_west_normalize(self):
     str = '2012-02-14T20:53:07+21:00'
     west = utils.parse_isotime(str)
     normed = utils.normalize_time(west)
     self._instaneous(normed, 2012, 2, 13, 23, 53, 07, 0)
Example #28
0
 def test_west_normalize(self):
     str = '2012-02-14T20:53:07+21:00'
     west = utils.parse_isotime(str)
     normed = utils.normalize_time(west)
     self._instaneous(normed, 2012, 2, 13, 23, 53, 07, 0)
Example #29
0
 def test_zulu_normalize(self):
     str = '2012-02-14T20:53:07Z'
     zulu = utils.parse_isotime(str)
     normed = utils.normalize_time(zulu)
     self._instaneous(normed, 2012, 2, 14, 20, 53, 07, 0)