Example #1
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.CONTAINER % ('get_one:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         if url:
             yield ('links', [
                 link.make_link('self', url, 'containers', value),
                 link.make_link('bookmark',
                                url,
                                'containers',
                                value,
                                bookmark=True)
             ])
     elif key == 'registry_id':
         if value:
             # the value is an internal id so replace it with the
             # user-facing uuid
             value = container.registry.uuid
         yield ('registry_id', value)
     else:
         yield (key, value)
Example #2
0
 def convert():
     experimental = Experimental()
     experimental.id = "experimental"
     experimental.links = [
         link.make_link('self',
                        pecan.request.host_url,
                        'experimental',
                        '',
                        bookmark=True),
         link.make_link('describedby',
                        'https://docs.openstack.org',
                        'developer/zun/dev',
                        'api-spec-v1.html',
                        bookmark=True,
                        type='text/html')
     ]
     experimental.media_types = \
         [MediaType(base='application/json',
                    type='application/vnd.openstack.'
                         'zun.experimental+json')]
     experimental.capsules = [
         link.make_link('self',
                        pecan.request.host_url,
                        'experimental/capsules',
                        '',
                        bookmark=True),
         link.make_link('bookmark',
                        pecan.request.host_url,
                        'capsules',
                        '',
                        bookmark=True)
     ]
     return experimental
Example #3
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [
             link.make_link('self', url, 'images', value),
             link.make_link('bookmark', url, 'images', value, bookmark=True)
         ])
     else:
         yield (key, value)
 def convert():
     v1 = V1()
     v1.id = "v1"
     v1.links = [
         link.make_link('self',
                        pecan.request.host_url,
                        'v1',
                        '',
                        bookmark=True),
         link.make_link('describedby',
                        'https://docs.openstack.org',
                        'developer/zun/dev',
                        'api-spec-v1.html',
                        bookmark=True,
                        type='text/html')
     ]
     v1.media_types = [
         MediaType(base='application/json',
                   type='application/vnd.openstack.zun.v1+json')
     ]
     v1.services = [
         link.make_link('self', pecan.request.host_url, 'services', ''),
         link.make_link('bookmark',
                        pecan.request.host_url,
                        'services',
                        '',
                        bookmark=True)
     ]
     v1.containers = [
         link.make_link('self', pecan.request.host_url, 'containers', ''),
         link.make_link('bookmark',
                        pecan.request.host_url,
                        'containers',
                        '',
                        bookmark=True)
     ]
     v1.images = [
         link.make_link('self', pecan.request.host_url, 'images', ''),
         link.make_link('bookmark',
                        pecan.request.host_url,
                        'images',
                        '',
                        bookmark=True)
     ]
     v1.hosts = [
         link.make_link('self', pecan.request.host_url, 'hosts', ''),
         link.make_link('bookmark',
                        pecan.request.host_url,
                        'hosts',
                        '',
                        bookmark=True)
     ]
     return v1
Example #5
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.CAPSULE % ('get:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [link.make_link(
             'self', url, 'capsules', value),
             link.make_link(
                 'bookmark', url,
                 'capsules', value,
                 bookmark=True)])
         if legacy_api_version:
             yield('volumes_info', {})
             yield('containers_uuids', [])
             yield('init_containers_uuids', [])
             yield('capsule_version', '')
     elif key == 'init_containers':
         containers = []
         for c in capsule.init_containers:
             container = containers_view.format_container(
                 context, None, c)
             containers.append(container)
         yield ('init_containers', containers)
     elif key == 'containers':
         containers = []
         for c in capsule.containers:
             container = containers_view.format_container(
                 context, None, c)
             containers.append(container)
         yield ('containers', containers)
     elif key == 'name':
         if legacy_api_version:
             yield('meta_name', value)
         else:
             yield(key, value)
     elif key == 'labels':
         if legacy_api_version:
             yield('meta_labels', value)
         else:
             yield(key, value)
     elif key == 'restart_policy':
         if legacy_api_version:
             if 'Name' in value:
                 yield(key, value['Name'])
         else:
             yield(key, value)
     else:
         yield (key, value)
 def transform(key, value):
     if key not in _basic_keys:
         return
     if key == 'id':
         yield ('id', value)
         yield ('links', [link.make_link(
             'self', url, 'availability_zones', value),
             link.make_link(
                 'bookmark', url,
                 'availability_zones', value,
                 bookmark=True)])
     else:
         yield (key, value)
Example #7
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [link.make_link(
             'self', url, 'hosts', value),
             link.make_link(
                 'bookmark', url,
                 'hosts', value,
                 bookmark=True)])
     else:
         yield (key, value)
Example #8
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.CONTAINER % ('get_one:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [link.make_link(
             'self', url, 'containers', value),
             link.make_link(
                 'bookmark', url,
                 'containers', value,
                 bookmark=True)])
     else:
         yield (key, value)
Example #9
0
 def convert(id, status, max, min):
     version = Version()
     version.id = id
     version.links = [link.make_link('self', pecan.request.host_url,
                                     id, '', bookmark=True)]
     version.status = status
     version.max_version = max
     version.min_version = min
     return version
Example #10
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.REGISTRY % ('get_one:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         if url:
             yield ('links', [link.make_link(
                 'self', url, 'registries', value),
                 link.make_link(
                     'bookmark', url,
                     'registries', value,
                     bookmark=True)])
     elif key == 'password':
         yield ('password', '***')
     else:
         yield (key, value)
Example #11
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [
             link.make_link('self', url, 'capsules', value),
             link.make_link('bookmark',
                            url,
                            'capsules',
                            value,
                            bookmark=True)
         ])
         if legacy_api_version:
             yield ('volumes_info', {})
             yield ('containers_uuids', [])
             yield ('init_containers_uuids', [])
             yield ('capsule_version', '')
     elif key == 'containers':
         containers = []
         for c in capsule.containers:
             container = containers_view.format_container(context, None, c)
             containers.append(container)
         yield ('containers', containers)
     elif key == 'name':
         if legacy_api_version:
             yield ('meta_name', value)
         else:
             yield (key, value)
     elif key == 'labels':
         if legacy_api_version:
             yield ('meta_labels', value)
         else:
             yield (key, value)
     elif key == 'restart_policy':
         if legacy_api_version:
             yield (key, value['Name'])
         else:
             yield (key, value)
     else:
         yield (key, value)
Example #12
0
    def test_make_link(self):
        link = link_module.make_link(
            'self', 'http://localhost:8080', 'v1', '',
            bookmark=True)

        ordered_link = collections.OrderedDict(sorted(link.items()))
        expected_value = collections.OrderedDict([
            ('href', 'http://localhost:8080/v1/'),
            ('rel', 'self')
        ])
        self.assertEqual(six.text_type(expected_value),
                         six.text_type(ordered_link))
Example #13
0
    def test_make_link(self):
        link = link_module.make_link('self',
                                     'http://localhost:8080',
                                     'v1',
                                     '',
                                     bookmark=True)

        ordered_link = collections.OrderedDict(sorted(link.items()))
        expected_value = collections.OrderedDict([
            ('href', 'http://localhost:8080/v1/'), ('rel', 'self')
        ])
        self.assertEqual(str(expected_value), str(ordered_link))
Example #14
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     if key == 'uuid':
         yield ('uuid', value)
         yield ('links', [
             link.make_link('self', url, 'capsules', value),
             link.make_link('bookmark',
                            url,
                            'capsules',
                            value,
                            bookmark=True)
         ])
     elif key == 'containers':
         containers = []
         for c in value:
             container = containers_view.format_container(context, None, c)
             containers.append(container)
         yield ('containers', containers)
     else:
         yield (key, value)
Example #15
0
    def get_next(self, limit, url=None, **kwargs):
        """Return a link to the next subset of the collection."""
        if not self.has_next(limit):
            return None

        resource_url = url or self._type
        q_args = ''.join(['%s=%s&' % (key, kwargs[key]) for key in kwargs])
        next_args = '?%(args)slimit=%(limit)d&marker=%(marker)s' % {
            'args': q_args, 'limit': limit,
            'marker': self.collection[-1]['uuid']}

        return link.make_link('next', pecan.request.host_url,
                              resource_url, next_args)['href']
Example #16
0
    def get_next(self, limit, url=None, **kwargs):
        """Return a link to the next subset of the collection."""
        if not self.has_next(limit):
            return None

        resource_url = url or self._type
        q_args = ''.join(['%s=%s&' % (key, kwargs[key]) for key in kwargs])
        next_args = '?%(args)slimit=%(limit)d&marker=%(marker)s' % {
            'args': q_args, 'limit': limit,
            'marker': self.collection[-1]['uuid']}

        return link.make_link('next', pecan.request.host_url,
                              resource_url, next_args)['href']
Example #17
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.REGISTRY % ('get_one:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         if url:
             yield ('links', [
                 link.make_link('self', url, 'registries', value),
                 link.make_link('bookmark',
                                url,
                                'registries',
                                value,
                                bookmark=True)
             ])
     elif key == 'password':
         yield ('password', '***')
     else:
         yield (key, value)
Example #18
0
 def transform(key, value):
     if key not in _basic_keys:
         return
     # strip the key if it is not allowed by policy
     policy_action = policies.CONTAINER % ('get_one:%s' % key)
     if not context.can(policy_action, fatal=False, might_not_exist=True):
         return
     if key == 'uuid':
         yield ('uuid', value)
         if url:
             yield ('links', [link.make_link(
                 'self', url, 'containers', value),
                 link.make_link(
                     'bookmark', url,
                     'containers', value,
                     bookmark=True)])
     elif key == 'registry_id':
         if value:
             # the value is an internal id so replace it with the
             # user-facing uuid
             value = container.registry.uuid
         yield ('registry_id', value)
     else:
         yield (key, value)
Example #19
0
 def convert():
     v1 = V1()
     v1.id = "v1"
     v1.links = [link.make_link('self', pecan.request.host_url,
                                'v1', '', bookmark=True),
                 link.make_link('describedby',
                                'https://docs.openstack.org',
                                'developer/zun/dev',
                                'api-spec-v1.html',
                                bookmark=True, type='text/html')]
     v1.media_types = [MediaType(
         base='application/json',
         type='application/vnd.openstack.zun.v1+json')]
     v1.services = [link.make_link('self', pecan.request.host_url,
                                   'services', ''),
                    link.make_link('bookmark',
                                   pecan.request.host_url,
                                   'services', '',
                                   bookmark=True)]
     v1.containers = [link.make_link('self', pecan.request.host_url,
                                     'containers', ''),
                      link.make_link('bookmark',
                                     pecan.request.host_url,
                                     'containers', '',
                                     bookmark=True)]
     v1.images = [link.make_link('self', pecan.request.host_url,
                                 'images', ''),
                  link.make_link('bookmark',
                                 pecan.request.host_url,
                                 'images', '',
                                 bookmark=True)]
     v1.networks = [link.make_link('self', pecan.request.host_url,
                                   'networks', ''),
                    link.make_link('bookmark',
                                   pecan.request.host_url,
                                   'networks', '',
                                   bookmark=True)]
     v1.hosts = [link.make_link('self', pecan.request.host_url,
                                'hosts', ''),
                 link.make_link('bookmark',
                                pecan.request.host_url,
                                'hosts', '',
                                bookmark=True)]
     v1.availability_zones = [link.make_link('self', pecan.request.host_url,
                                             'availability_zones', ''),
                              link.make_link('bookmark',
                                             pecan.request.host_url,
                                             'availability_zones', '',
                                             bookmark=True)]
     v1.capsules = [link.make_link('self', pecan.request.host_url,
                                   'capsules', ''),
                    link.make_link('bookmark',
                                   pecan.request.host_url,
                                   'capsules', '',
                                   bookmark=True)]
     v1.quotas = [link.make_link('self', pecan.request.host_url,
                                 'quotas', ''),
                  link.make_link('bookmark',
                                 pecan.request.host_url,
                                 'quotas', '',
                                 bookmark=True)]
     v1.quota_classes = [link.make_link('self', pecan.request.host_url,
                                        'quota_classes', ''),
                         link.make_link('bookmark',
                                        pecan.request.host_url,
                                        'quota_classes', '',
                                        bookmark=True)]
     v1.registries = [link.make_link('self', pecan.request.host_url,
                                     'registries', ''),
                      link.make_link('bookmark', pecan.request.host_url,
                                     'registries', '', bookmark=True)]
     return v1