Ejemplo n.º 1
0

@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
Ejemplo n.º 2
0
    role_id = member_role_id()
    for project in projects:
        try:
            g.client_set.identity_admin.roles.add_user_role(user=user,
                                                            role=role_id,
                                                            tenant=project)
        except osc_exc.NotFound:
            raise exc.InvalidElementValue('projects', 'link object', project,
                                          'Project does not exist')


_SCHEMA = Schema(
    (st.String('id'), st.String('name'), st.String(
        'fullname', allow_empty=True), st.String('email'), st.Boolean('admin'),
     st.Boolean('completed-registration'), st.Timestamp('invited-at'),
     st.List(st.LinkObject('projects')), st.Boolean('invite'),
     st.String('password'), st.Boolean('send-invite-mail'),
     st.String('link-template')),
    create_required=('email', ),
    create_allowed=('name', 'fullname', 'admin', 'projects', 'invite',
                    'link-template', 'send-invite-mail', 'password'),
    updatable=('name', 'email', 'fullname', 'admin', 'password'),
    list_args=('id', 'name', 'fullname', 'email', 'projects', 'admin',
               'completed-registration', 'invited-at'))


@BP.route('/', methods=('GET', ))
@root_endpoint('users')
@user_endpoint
def list_users():
    parse_collection_request(_SCHEMA.list_args)
Ejemplo n.º 3
0
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

    client = auth.client_set_for_tenant(tenant_id, fallback_to_api=g.is_admin)
    image_list = client.image.images.list(filters={'is_public': is_public})
Ejemplo n.º 4
0
        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 = {}
Ejemplo n.º 5
0
        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)


@BP.route('/<record_id>')
def get_log_record(record_id):
Ejemplo n.º 6
0
    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', ))
@user_endpoint
Ejemplo n.º 7
0
        u'name': secgroup.name
    }


def _sg_to_view(secgroup, project_name=None):
    result = link_for_security_group(secgroup)
    result.update(
        (('description', secgroup.description),
         ('project', link_for_project(secgroup.tenant_id, project_name)),
         ('rules-href',
          url_for('fw_rules.list_fw_rules', fw_rule_set_id=secgroup.id))))
    return result


_SCHEMA = Schema((st.String('id'), st.String('name'), st.String('description'),
                  st.LinkObject('project')),
                 required=('name', 'project'),
                 allowed=('description', ))


@BP.route('/', methods=('GET', ))
@root_endpoint('fw-rule-sets')
@user_endpoint
def list_fw_rule_sets():
    parse_collection_request(_SCHEMA)
    if g.my_projects:
        tenants = g.client_set.identity_public.tenants.list()
    else:
        tenants = admin_client_set().identity_admin.tenants.list()

    result = []
Ejemplo n.º 8
0
 def setUp(self):
     super(LinkObjectListTestCase, self).setUp()
     self.ll = st.List(st.LinkObject('test'))
Ejemplo n.º 9
0
 def setUp(self):
     super(LinkObjectTestCase, self).setUp()
     self.lo = st.LinkObject('test')
Ejemplo n.º 10
0
 def setUp(self):
     super(SchemaTestCase, self).setUp()
     self.schema = Schema(
         (st.String('name'), st.LinkObject('project'), st.Int('intval')))