示例#1
0
def show_tenant():
    """
    List VMs for the project
    """
    c = clients.user_clients(flask.g.tenant_id)
    servers = c.compute.servers.list(detailed=True)
    vms_data = [s._info for s in servers]
    vms_data = sorted(vms_data, key=lambda x: x['name'])
    p = pagination.Pagination(vms_data)
    data = p.slice(vms_data)
    user_id2name = {}
    uuid_regex = re.compile(
        r'[a-f0-9]{8}-?[a-f0-9]{4}-?[a-f0-9]{4}-?[a-f0-9]{4}-?[a-f0-9]{12}')
    for x in data:
        user_id = x['user_id']
        try:
            x['user_id'] = user_id2name[user_id]
            pass
        except KeyError:
            if user_id.isdigit() or uuid_regex.match(user_id):
                try:
                    user = clients.admin_clients().keystone.users.get(user_id)
                    user_id2name[user_id] = user.name
                    x['user_id'] = user.name
                except:
                    pass
    return {
        'vms': data,
        'pagination': p,
        'title': 'Virtual Machines',
        'subtitle': 'List of virtual machines'
    }
示例#2
0
def index():
    try:
        notifications = utils.notifications_api_call("/parameter")
    except HttpException as ex:
        notifications = []
    item_list = utils.notifications_api_call("/item")
    item_by_key = dict(((item["key_"], item) for item in item_list))
    for notif in notifications:
        notification_normalize(notif)
        try:
            notif["name"] = item_by_key[notif["key_"]]["name"]
        except KeyError:
            notif["name"] = notif["key_"]
    notifications = sorted(notifications,
                           key=lambda n: (n["is_email"], n["name"]))
    p = pagination.Pagination(len(notifications))
    offset = p.limit_offset()
    notifications = notifications[offset[0]:offset[1]]
    return {
        'objects': notifications,
        'pagination': p,
        'delete_form': forms.DeleteForm(),
        'title': bp.name.replace('global_', '').replace('_', ' ').capitalize(),
        'subtitle': 'List of notifications'
    }
示例#3
0
def index():
    """List users.

    TODO(apugachev): find way to count users without fetching all users.
    This would allow to use marker and limit to fetch one page only.
    """
    identity_admin = clients.admin_clients().identity_admin
    users = sorted(identity_admin.users.list(limit=1000000),
                   key=lambda x: x.name)
    p = pagination.Pagination(users)
    data = p.slice(users)
    potential_admins = set([
        user.id
        for user in (identity_admin.users.list(clients.get_systenant_id()))
    ])
    for user in data:
        # TODO(apugachev) modify to work with form.DeleteUser
        form = forms.DeleteUserForm()
        form.user_id.data = user.id
        user.delete_form = form
        if user.id in potential_admins:
            for role in (identity_admin.roles.roles_for_user(user.id)):
                if clients.role_tenant_is_admin(role):
                    user.is_global_admin = True
                    break
    return {
        'pagination': p,
        'data': data,
        'title': bp.name.replace('global_', '').replace('_', ' ').capitalize(),
        'subtitle': 'List of users'
    }
示例#4
0
def list_users():
    """
    List users.
    """
    users = flask.g.tenant.list_users()
    p = pagination.Pagination(users)
    return {
        'pagination': p,
        'objects': p.slice(users),
        'title': 'Users',
        'subtitle': 'List of users'
    }
示例#5
0
 def index():
     """List security groups.
     """
     security_groups = (clients.user_clients(
         flask.g.tenant_id).compute.security_groups.list())
     p = pagination.Pagination(security_groups)
     data = p.slice(security_groups)
     return {
         'security_groups': data,
         'pagination': p,
         'delete_form': forms.DeleteForm(),
         'title': bp.name.replace('global_', '').replace('_',
                                                         ' ').capitalize(),
         'subtitle': 'List of existing security groups'
     }
示例#6
0
def index():
    total_count = flask.g.store.execute(
        'SELECT count(*) from email_masks').get_one()[0]
    p = pagination.Pagination(total_count)
    rows = flask.g.store.execute(
        'SELECT * from email_masks ORDER BY email_mask LIMIT ?, ?',
        p.limit_offset()).get_all()
    objects = map(lambda row: dict(zip(('id', 'email_mask'), row)), rows)
    return {
        'pagination': p,
        'objects': objects,
        'delete_form': forms.DeleteForm(),
        'title': bp.name.replace('global_', '').replace('_', ' ').capitalize(),
        'subtitle': 'Invitation domains list'
    }
示例#7
0
文件: projects.py 项目: altai/focus
def index():
    """List projects.

    List only enabled, sort by name.
    """

    tenants = utils.get_visible_tenants()
    ordered = sorted(tenants, key=lambda x: x.name)
    pagina = pagination.Pagination(ordered)
    delete_form = forms.DeleteForm()
    return {
        'objects': pagina.slice(ordered),
        'pagination': pagina,
        'delete_form': delete_form,
        'title': bp.name.replace('global_', '').replace('_', ' ').capitalize(),
        'subtitle': 'List of projects'
    }
示例#8
0
def index():
    try:
        networks = clients.admin_clients().compute.networks.list()
    except HttpException as ex:
        networks = []
    tenants = clients.admin_clients().identity_admin.tenants.list()
    tenants = dict(((t.id, t.name) for t in tenants))
    p = pagination.Pagination(len(networks))
    offset = p.limit_offset()
    networks = [net._info for net in networks[offset[0]:offset[1]]]
    for net in networks:
        net["label"] = tenants.get(net["project_id"], net["label"])
    return {
        'objects': networks,
        'pagination': p,
        'delete_form': forms.DeleteForm(),
        'title': bp.name.replace('global_', '').replace('_', ' ').capitalize(),
        'subtitle': 'List of networks'
    }
示例#9
0
    def index():
        """List images.

        Admin (global visibility level) should see only images from
        systenant. Project members should see images for projects only.
        """
        images = get_images_list()
        if not hasattr(flask.g, 'tenant_id'):
            images = filter(lambda x: getattr(x, 'is_public', False), images)
        p = pagination.Pagination(images)
        data = p.slice(images)
        return {
            'images': data,
            'pagination': p,
            'delete_form': forms.DeleteForm(),
            'title': bp.name.replace('global_', '').replace('_',
                                                            ' ').capitalize(),
            'subtitle': 'List of existing images'
        }
示例#10
0
def list_vms():
    '''
    List all virtual machines in the cloud.
    '''
    # not in visible tenants, but in all tenants
    tenants = dict(
        [(x.id, x) for x in clients.admin_clients().keystone.tenants.list()])

    class ProjectNameColumn(dataset.StrColumn):
        def __call__(self, x):
            try:
                tenant = tenants[x.tenant_id]
            except KeyError:
                return '[deleted] %s' % x.tenant_id
            else:
                return tenant.name
    default_columns = ['id', 'name', 'project_name', 'ram']
    #creating and adjusting columns vector, columns ordering
    columns = dataset.ColumnKeeper({
        'id': dataset.StrColumn('id', 'ID'),
        'name': dataset.StrColumn('name', 'Name'),
        'user_id': dataset.StrColumn('user_id', 'User'),
        'tenant_id': dataset.StrColumn('tenant_id', 'Project ID'),
        'project_name': ProjectNameColumn(
            'project_name', 'Project Name'),
        'ram': dataset.IntColumn('ram', 'RAM'),
        'vcpus': dataset.IntColumn('vcpus', 'Number of CPUs')
    }, default_columns)
    if 'columns' in flask.request.args:
        columns.adjust(
            [x for x in flask.request.args['columns'].split(',') if x])
    if 'asc' in flask.request.args or 'desc' in flask.request.args:
        columns.order(
            flask.request.args.getlist('asc'),
            flask.request.args.getlist('desc'))
    if 'groupby' in flask.request.args:
        columns.adjust_groupby(flask.request.args['groupby'])
    vms = clients.admin_clients().nova.servers.list(search_opts={
        'all_tenants': 1})
    flavors = dict(
        [(x.id, x) for x in clients.admin_clients().nova.flavors.list()])
    for server in vms:
        try:
            flavor = flavors[server.flavor['id']]
        except KeyError:
            flavor = clients.admin_clients().nova.flavors.get(server.flavor[
                'id'])
            flavors[server.flavor['id']] = flavor
        server.ram = flavor.ram
        server.vcpus = flavor.vcpus

    current_dataset = dataset.DataSet(vms, columns)
    if 'export' in flask.request.args:
        try:
            export = exporter.Exporter(
                flask.request.args['export'],
                current_dataset.data, columns, 'vms')
        except KeyError:
            d = flask.request.args.copy()
            d.pop('export')
            query = urllib.urlencode(datastructures.iter_multi_items(d))
            url = flask.request.path + '?' + query
            return flask.redirect(url)
        response = export()
    else:
        p = pagination.Pagination(current_dataset.data)
        visible_data = p.slice(current_dataset.data)
        response = dict(
            pagination=p,
            columns=columns,
            data=visible_data)
        if 'project_name' in columns.current_names:
            response['distinct_projects_names'] = sorted(
                current_dataset.get_distinct_values("project_name"))
    response.update({
        'title': 'Virtual Machines',
        'subtitle': 'List of virtual machines'
    })
    return response