def setUp(self): super(MakeCollectionResponseTestCase, self).setUp() flask.g.limit = None flask.g.offset = None flask.g.unused_args = set([]) flask.g.collection_schema = Schema((st.Int('test'), )) self.result = [{ 'test': 1 }, { 'test': 2 }, { 'test': 3 }, { 'test': 4 }, { 'test': 5 }, { 'test': 6 }, { 'test': 7 }]
def test_required_ok(self): schema = Schema((st.Int('req'), )) params = {'req': 42} with self.request_context(params): self.assertEquals(params, parse_request_data(None, schema))
def test_required_missing(self): schema = Schema((st.Int('req'), )) with self.request_context({}): self.assertRaises(exc.MissingElement, parse_request_data, None, schema)
rule.ip_range.get('cidr') } def _get_security_group(sg_id): try: sg = auth.admin_client_set().compute.security_groups.get(sg_id) except osc_exc.NotFound: abort(404) auth.assert_admin_or_project_user(sg.tenant_id, eperm_status=404) # TODO(imelnikov): do we need to check if group belongs to systenant? return sg _SCHEMA = Schema((st.String('id'), st.String('protocol'), st.Cidr('source'), st.Int('port-range-first', min_val=-1, max_val=65535), st.Int('port-range-last', min_val=-1, max_val=65535)), required=('protocol', 'source'), allowed=('port-range-first', 'port-range-last')) @BP.route('/', methods=('GET', )) @user_endpoint def list_fw_rules(fw_rule_set_id): parse_collection_request(_SCHEMA) result = [ _fw_rule_dict_to_view(rule) for rule in _get_security_group(fw_rule_set_id).rules ] parent_href = url_for('fw_rule_sets.get_fw_rule_set', fw_rule_set_id=fw_rule_set_id)
@BP.route('/<project_id>', methods=('GET', )) @user_endpoint def get_project(project_id): tenant = get_tenant(project_id) # checks permissions net = _network_for_project(project_id) quotaset = _quotaset_for_project(project_id) result = _project_to_view(tenant, net, quotaset) return make_json_response(result) _SCHEMA = Schema( (st.String('id'), st.String('name'), st.String('description', allow_empty=True), st.LinkObject('network'), st.Int('cpus-limit'), st.Int('ram-limit'), st.Int('instances-limit')), create_required=('name', 'network'), allowed=( # both on creation and update 'description', 'cpus-limit', 'ram-limit', 'instances-limit')) @BP.route('/', methods=('GET', )) @root_endpoint('projects') @user_endpoint def list_projects(): parse_collection_request(_SCHEMA) if g.my_projects: client = g.client_set.identity_public else: client = admin_client_set().identity_admin
return result def list_all_images(client): """Get list of all images from all tenants""" # NOTE(imelnikov): When is_public is True (the default), images # available for current tenant are returned (public images and # images from current tenant). When is_public is set to None # explicitly, current tenant is ignored. return client.list(filters={'is_public': None}) _SCHEMA = Schema( (st.String('id'), st.String('name'), st.String('status'), st.String('disk-format'), st.String('container-format'), st.String('md5sum'), st.Int('size'), st.Timestamp('created'), st.Boolean('global'), st.LinkObject('project', add_search_matchers={'for': st.not_implemented_matcher}), st.LinkObject('kernel'), st.LinkObject('ramdisk')), create_required=('name', 'container-format', 'disk-format'), create_allowed=('project', 'global', 'kernel', 'ramdisk'), updatable=('name')) def _images_for_tenant(tenant_id, is_public): try: tenant = auth.admin_client_set().identity_admin \ .tenants.get(tenant_id) except osc_exc.NotFound: return [] # consistent with project:eq
def setUp(self): super(IntTestCase, self).setUp() self.u = st.Int('test')
def test_allowed_ok(self): schema = Schema((st.Int('test'), )) params = {'test': 42} with self.request_context(params): self.assertEquals(params, parse_request_data(schema))
d["href"] = flask.url_for('networks.get_network', net_id=net.id) d["name"] = net.label d["vlan"] = int(net.vlan) d["cidr"] = net.cidr if net.project_id: d["used"] = True d["project"] = link_for_project(net.project_id) else: d["used"] = False return d _SCHEMA = Schema( (st.String('id'), st.String('name'), st.Int('vlan'), st.Cidr('cidr'), st.Boolean('used'), st.LinkObject('project')), required=('name', 'vlan', 'cidr')) @BP.route('/', methods=('GET', )) @root_endpoint('networks') @user_endpoint def list_networks(): parse_collection_request(_SCHEMA) nets = admin_client_set().compute.networks.list() return make_collection_response(u'networks', [_net_to_dict(net) for net in nets]) @BP.route('/<net_id>', methods=('GET', ))
def _node_to_view(name, hosts): result = link_for_node(name) for h in hosts: if h.project == '(total)': result['memory'] = from_mb(h.memory_mb) result['cpus'] = h.cpu elif h.project == '(used_now)': result['memory-used'] = from_mb(h.memory_mb) result['cpus-used'] = h.cpu return result _SCHEMA = Schema(( st.String('name'), st.Int('memory'), st.Int('cpus'), st.Int('memory-used'), st.Int('cpus-used'), )) @BP.route('/', methods=('GET', )) @root_endpoint('nodes') def list_nodes(): parse_collection_request(_SCHEMA) host_mgr = g.client_set.compute.hosts names = [ h._info['host_name'] for h in host_mgr.list_all() if h._info['service'] == 'compute'
def setUp(self): super(ApplyFiltersTestCase, self).setUp() self.schema = Schema([st.String('name'), st.Int('size')]) self.filters = {'name': {'eq': 'test'}, 'size': {'gt': 28, 'lt': 32}}
def setUp(self): super(ParseFiltersTestCase, self).setUp() self.schema = Schema([st.String('name'), st.Int('size')])
def test_doesnt_replace_methods(self): self.assertRaises(ValueError, Schema, (st.Int('test'), ), argument_matcher=('test', ))
def setUp(self): super(SchemaTestCase, self).setUp() self.schema = Schema( (st.String('name'), st.LinkObject('project'), st.Int('intval')))
def test_allowed_missing(self): schema = Schema((st.Int('req'), )) params = {} with self.request_context({}): self.assertEquals(params, parse_request_data(schema))
def test_allowed_wrong(self): schema = Schema((st.Int('test'), )) with self.request_context({'test': '42'}): self.assertRaises(exc.InvalidElementValue, parse_request_data, schema)
len(tenants) - 1, # not counting systenant 'instances': len(servers), 'users': len(users), 'total-images': len(images), 'global-images': len(global_images), 'by-project-stats-href': url_for('stats.list_stats_by_project') }) _SCHEMA = Schema( (st.LinkObject('project'), st.Int('members'), st.Int('instances'), st.Int('local-images'), st.Int('total-images'))) @BP.route('/by-project/', methods=('GET', )) @user_endpoint def list_stats_by_project(): parse_collection_request(_SCHEMA) cs = auth.admin_client_set() if g.my_projects: tenants = g.client_set.identity_public.tenants.list() else: tenants = cs.identity_admin.tenants.list() result = {}
pass if record.project_id is not None and project_name is None: try: project_name = iadm.tenants.get(record.project_id).name except osc_exc.NotFound: pass return _record_to_dict(record, user_name, project_name) _SCHEMA = Schema(( st.String('id'), st.String('message'), st.String('method'), st.String('resource'), st.Ipv4('remote_address'), st.Int('response_status'), st.Timestamp('timestamp'), st.LinkObject('user'), st.LinkObject('project'), )) @BP.route('/') @root_endpoint('audit-log') def list_all_records(): parse_collection_request(_SCHEMA) result = [record_to_view(record) for record in AuditDAO.list_all()] return make_collection_response(u'audit-log', result)
def _instance_type_for_nova(data): return { u'name': data['name'], u'ram': to_mb(data['ram']), u'vcpus': data['cpus'], u'disk': to_gb(data['root-size']), u'ephemeral': to_gb(data['ephemeral-size']) } _SCHEMA = Schema(( st.String('id'), st.String('name'), st.Int('cpus'), st.Int('ram'), st.Int('root-size'), st.Int('ephemeral-size')), required=('name', 'cpus', 'ram', 'root-size', 'ephemeral-size') ) @BP.route('/', methods=('GET',)) @root_endpoint('instance-types') @user_endpoint def list_instance_types(): parse_collection_request(_SCHEMA) all_flavors = bound_client_set().compute.flavors.list() result = [_instance_type_to_view(flavor)