コード例 #1
0
    def removegroups(self):
        response.content_type = "application/json"
        if 'ids[]' in request.params:
            ids = [v for k, v in request.params.items() if 'ids[]' in k]
        else:
            session['flash'] = 'No ids were sent'
            session.save()
            return '{"success": false}'

        data = {}
        data['remove_groups'] = True
        if 'groups' in request.params:
            data['groups'] = [\
                    v for k,v in request.params.items() if 'groups' in k]
        else:
            session['flash'] = 'No groups were sent'
            session.save()
            return '{"success": false}'

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.update_many('group', ids, data)

        session['flash'] = status
        session.save()
        return '{"success": true}'
コード例 #2
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def removegroups(self):
        response.content_type = "application/json"
        if 'ids[]' in request.params:
            ids = [v for k,v in request.params.items() if 'ids[]' in k]
        else:
            session['flash'] = 'No ids were sent'
            session.save()
            return '{"success": false}'

        data = {}
        data['remove_groups'] = True
        if 'groups' in request.params:
            data['groups'] = [\
                    v for k,v in request.params.items() if 'groups' in k]
        else:
            session['flash'] = 'No groups were sent'
            session.save()
            return '{"success": false}'

        activity_engine = ActivityEngine(
                Session, session['active_user']['user_id'])
        status = activity_engine.update_many('group', ids, data)

        session['flash'] = status
        session.save()
        return '{"success": true}'
コード例 #3
0
    def updatebyname(self, name, format='html'):
        id = Session.query(Node).filter(Node.hostname == name).first()
        if id:
            id = id.id
        else:
            return 'Host: %s is not in nodetraq' % name

        ignore = ['Submit', 'username']

        params = [
            (p, request.params[p]) for p in request.params \
                if p not in ignore]
        data = {}
        for key, value in params:
            if value:
                if key == 'cpu_speed' and not value:
                    continue
                data[key] = value

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.update('node', id, data)

        if format == 'html':
            session['flash'] = status
            session.save()
            return redirect(url(controller='nodes', action='show', id=id))
        elif format == 'json':
            request.content_type = 'application/json'
            return status
コード例 #4
0
ファイル: groups.py プロジェクト: seryl/Nodetraq
 def destroy(self, id):
     activity_engine = ActivityEngine(Session,
             session['active_user']['user_id'])
     status = activity_engine.destroy('group', id)
     session['flash'] = status
     session.save()
     return redirect(url(controller='groups', action='index'))
コード例 #5
0
    def update(self, id, format='html'):
        ignore = ['Submit', 'username']

        params = [
            (p, request.params[p]) for p in request.params \
                if p not in ignore]
        data = {}
        for key, value in params:
            if key == 'cpu_speed' and not value:
                continue
            elif key == 'game' and not value:
                continue
            data[key] = value

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.update('node', id, data)

        if format == 'html':
            session['flash'] = status
            session.save()
            return redirect(url(controller='nodes', action='show', id=id))
        elif format == 'json':
            request.content_type = 'application/json'
            return status
コード例 #6
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def updatebyname(self, name, format='html'):
        id = Session.query(Node).filter(Node.hostname == name).first()
        if id:
            id = id.id
        else:
            return 'Host: %s is not in nodetraq' % name

        ignore = ['Submit',
                'username']

        params = [
            (p, request.params[p]) for p in request.params \
                if p not in ignore]
        data = {}
        for key, value in params:
            if value:
                if key == 'cpu_speed' and not value:
                    continue
                data[key] = value

        activity_engine = ActivityEngine(Session,
                session['active_user']['user_id'])
        status = activity_engine.update('node', id, data)

        if format =='html':
            session['flash'] = status
            session.save()
            return redirect(url(controller='nodes', action='show', id=id))
        elif format == 'json':
            request.content_type = 'application/json'
            return status
コード例 #7
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def update(self, id, format='html'):
        ignore = ['Submit',
                'username']

        params = [
            (p, request.params[p]) for p in request.params \
                if p not in ignore]
        data = {}
        for key, value in params:
            if key == 'cpu_speed' and not value:
                continue
            elif key == 'game' and not value:
                continue
            data[key] = value

        activity_engine = ActivityEngine(Session,
                session['active_user']['user_id'])
        status = activity_engine.update('node', id, data)

        if format =='html':
            session['flash'] = status
            session.save()
            return redirect(url(controller='nodes', action='show', id=id))
        elif format == 'json':
            request.content_type = 'application/json'
            return status
コード例 #8
0
 def destroy(self, id):
     activity_engine = ActivityEngine(Session,
                                      session['active_user']['user_id'])
     status = activity_engine.destroy('group', id)
     session['flash'] = status
     session.save()
     return redirect(url(controller='groups', action='index'))
コード例 #9
0
    def enablehost(self, format=None):
        valid = False
        response.content_type = "application/json"
        ids = None
        ips = None
        data = {}
        ports = []
        if 'ids[]' in request.params:
            ids = [v for k, v in request.params.items() if 'ids[]' in k]
        elif 'ips[]' in request.params:
            ips = [v for k, v in request.params.items() if 'ips[]' in k]
        if 'pool' in request.params:
            pool = request.params['pool']
            if 'ports[]' in request.params:
                ports = [v for k,v in request.params.items()\
                        if 'ports[]' in k]
                if ips or ids:
                    valid = True

        if not valid:
            session['flash'] = 'No ids were sent'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(controller='loadbalancer', action='index'))

        lb = LoadBalancer(ip='your_lb_ip')
        if ids:
            data['hosts'] = [
                Session.query(Node.hostname)\
                    .filter(Node.id == id)\
                    .first()[0] for id in ids ]
            members = [
                    ':'.join([Session.query(Node.primary_ip)\
                        .filter(Node.id == id)\
                        .first()[0], ports[i]])\
                        for i,id in enumerate(ids)]
        elif ips:
            data['hosts'] = [
                Session.query(Node.hostname)\
                    .filter(or_(Node.primary_ip == ip,
                                Node.secondary_ip == ip))\
                    .first()[0] for ip in ips ]
            members = [':'.join([ip, ports[i]])\
                    for i,ip in enumerate(ips)]

        lb.enable_members(pool, members)
        data['pool'] = pool
        data['type'] = 'enable'
        ae = ActivityEngine(Session, session['active_user']['user_id'])

        status = ae.update('loadbalancer', None, data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(controller='loadbalancer', action='index'))
コード例 #10
0
ファイル: loadbalancer.py プロジェクト: seryl/Nodetraq
    def disablehost(self, format=None):
        valid = False
        response.content_type = "application/json"
        ids = None
        ips = None
        data = {}
        if 'ids[]' in request.params:
            ids = [v for k,v in request.params.items() if 'ids[]' in k]
        elif 'ips[]' in request.params:
            ips = [v for k,v in reuqest.params.items() if 'ips[]' in k]
        if 'pool' in request.params:
            pool = request.params['pool']
            if 'ports[]' in request.params:
                ports = [v for k,v in request.params.items()\
                        if 'ports[]' in k]
                if ids or ips:
                    valid = True

        if not valid:
            session['flash'] = 'No ids were sent'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(
                        controller='loadbalancer', action='index'))

        lb = LoadBalancer(ip='your_lb_ip')
        if ids:
            data['hosts'] = [ q[0] for q in\
                    Session.query(Node.hostname)\
                .filter(Node.id.in_(ids)).all() ]
            members = [
                ':'.join([Session.query(Node.primary_ip)\
                        .filter(Node.id == id)\
                        .first()[0], ports[i]])\
                    for i,id in enumerate(ids)]
        elif ips:
            data['hosts'] = [q[0] for q in Session.query(Node.hostname)\
                .filter(or_(Node.primary_ip.in_(ips),
                            Node.secondary_ip.in_(ips)))\
                            .all() ]
            members = [
                ':'.join([ip, ports[i]]) for i,ip in enumerate(ips)]

        lb.disable_members(pool, members)
        data['type'] = 'disable'
        data['pool'] = pool
        ae = ActivityEngine(
            Session, session['active_user']['user_id'])

        status = ae.update('loadbalancer', None, data)
        session['flash'] = status
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(
                    controller='loadbalancer', action='index'))
コード例 #11
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def destroy(self, id):
        activity_engine = ActivityEngine(Session,
                session['active_user']['user_id'])
        status = activity_engine.destroy('node', id)

        if status:
            session['flash'] = 'Successfully %s' % status
            session.save()
        return redirect(url(controller='nodes', action='index'))
コード例 #12
0
    def destroy(self, id):
        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.destroy('node', id)

        if status:
            session['flash'] = 'Successfully %s' % status
            session.save()
        return redirect(url(controller='nodes', action='index'))
コード例 #13
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def sendbatchedit(self):
        response.content_type = 'application/json'
        user_id = int(request.params['user_id'])
        field = request.params['field']
        info = [json.loads(d[1]) for d in request.params.items()\
                    if 'items[]' in d]

        if field == 'hostname':
            for item in info:
                data = {}
                data['hostname'] = item['hostname']
                activity_engine = ActivityEngine(Session,
                        user_id)
                status = activity_engine.update(
                    'node', item['node_id'], data)
            session['flash'] = "Success"
            session.save()

        elif field == 'groups':
            for item in info:
                node = Session.query(Node)\
                    .filter(Node.id == item['node_id']).first()
                group_list = item['groups']\
                    .replace(' ', '').split(',')
                node.groups = Session.query(Group)\
                    .filter(Group.name.in_(group_list)).all()
                Session.add(node)
                Session.commit()
            session['flash'] = "Success"
            session.save()

        elif field == 'db_backups':
            for item in info:
                backup = Session.query(NodeDatabaseBackup)\
                    .filter(NodeDatabaseBackup.id == item['backup_id'])\
                    .first()
                node = Session.query(Node)\
                    .filter(Node.id == item['node_id']).first()
                backup.server_id = node.id

                if item['data_type'] == 'storage':
                    storage = Session.query(Node)\
                        .filter(Node.hostname == item['value']).first()
                    backup.storage_id = storage.id

                elif item['data_type'] == 'directory':
                    backup.directory = item['value']

            Session.add(backup)
            Session.commit()
            session['flash'] = "Success"
            session.save()
        else:
            return '{"success": false}'
        return '{"success": true}'
コード例 #14
0
ファイル: groups.py プロジェクト: seryl/Nodetraq
    def update(self):
        id = request.params['group_id']
        data = {}
        data['name'] = request.params['name']
        data['description'] = request.params['description']

        activity_engine = ActivityEngine(Session,
                session['active_user']['user_id'])
        status = activity_engine.update('group', id, data)
        session['flash'] = status
        session.save()
        return redirect(url(controller='groups', action='index'))
コード例 #15
0
    def sendbatchedit(self):
        response.content_type = 'application/json'
        user_id = int(request.params['user_id'])
        field = request.params['field']
        info = [json.loads(d[1]) for d in request.params.items()\
                    if 'items[]' in d]

        if field == 'hostname':
            for item in info:
                data = {}
                data['hostname'] = item['hostname']
                activity_engine = ActivityEngine(Session, user_id)
                status = activity_engine.update('node', item['node_id'], data)
            session['flash'] = "Success"
            session.save()

        elif field == 'groups':
            for item in info:
                node = Session.query(Node)\
                    .filter(Node.id == item['node_id']).first()
                group_list = item['groups']\
                    .replace(' ', '').split(',')
                node.groups = Session.query(Group)\
                    .filter(Group.name.in_(group_list)).all()
                Session.add(node)
                Session.commit()
            session['flash'] = "Success"
            session.save()

        elif field == 'db_backups':
            for item in info:
                backup = Session.query(NodeDatabaseBackup)\
                    .filter(NodeDatabaseBackup.id == item['backup_id'])\
                    .first()
                node = Session.query(Node)\
                    .filter(Node.id == item['node_id']).first()
                backup.server_id = node.id

                if item['data_type'] == 'storage':
                    storage = Session.query(Node)\
                        .filter(Node.hostname == item['value']).first()
                    backup.storage_id = storage.id

                elif item['data_type'] == 'directory':
                    backup.directory = item['value']

            Session.add(backup)
            Session.commit()
            session['flash'] = "Success"
            session.save()
        else:
            return '{"success": false}'
        return '{"success": true}'
コード例 #16
0
    def update(self):
        id = request.params['group_id']
        data = {}
        data['name'] = request.params['name']
        data['description'] = request.params['description']

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.update('group', id, data)
        session['flash'] = status
        session.save()
        return redirect(url(controller='groups', action='index'))
コード例 #17
0
ファイル: users.py プロジェクト: seryl/Nodetraq
    def enable_user(self, account):
        dh = DirectoryHelper(
            directoryCN, directoryPassword, directoryDomain)
        result = dh.enable_user(account)
        if result:
            session['flash'] = 'Successfully enabled %s' % account
            session.save()
        else:
            session['flash'] = 'Error disabling %s' % account
            session.save()

        ae = ActivityEngine(Session, session['active_user']['user_id'])
        ae.update('user', None,
                  { 'nsAccountLock': 'false', 'account': account })

        return redirect(url(
                controller='users', action='edit', account=account))
コード例 #18
0
    def create(self):
        data = {}
        data['hostname'] = request.params['hostname']
        data['service_tag'] = request.params['service_tag']
        data['primary_ip'] = request.params['primary_ip']
        data['location'] = request.params['location']
        data['description'] = request.params['description']

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
        status = activity_engine.create('node', data)

        if status:
            session['flash'] = status['status']
            session.save()

        return redirect(
            url(controller='nodes', action='show', id=status['info']['id']))
コード例 #19
0
ファイル: nodes.py プロジェクト: seryl/Nodetraq
    def create(self):
        data = {}
        data['hostname'] = request.params['hostname']
        data['service_tag'] = request.params['service_tag']
        data['primary_ip'] = request.params['primary_ip']
        data['location'] = request.params['location']
        data['description'] = request.params['description']

        activity_engine = ActivityEngine(Session,
                session['active_user']['user_id'])
        status = activity_engine.create('node', data)

        if status:
            session['flash'] = status['status']
            session.save()

        return redirect(url(controller='nodes',
            action='show', id=status['info']['id']))
コード例 #20
0
    def deletepool(self, format=None):
        if 'pools[]' in request.params:
            pool = [v for k, v in request.params.items() if 'pools[]' in k]
        else:
            return '{"success": false}'

        lb = LoadBalancer(ip='your_lb_ip')
        lb.delete_pool(pool)
        data = {}
        data['pools'] = pool
        ae = ActivityEngine(Session, session['active_user']['user_id'])

        status = ae.destroy('loadbalancer', data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(controller='loadbalancer', action='index'))
コード例 #21
0
ファイル: loadbalancer.py プロジェクト: seryl/Nodetraq
    def deletepool(self, format=None):
        if 'pools[]' in request.params:
            pool = [v for k,v in request.params.items() if 'pools[]' in k]
        else:
            return '{"success": false}'

        lb = LoadBalancer(ip='your_lb_ip')
        lb.delete_pool(pool)
        data = {}
        data['pools'] = pool
        ae = ActivityEngine(
            Session, session['active_user']['user_id'])

        status = ae.destroy('loadbalancer', data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(
                    controller='loadbalancer', action='index'))
コード例 #22
0
ファイル: users.py プロジェクト: seryl/Nodetraq
    def update(self, account):
        update_items = (
            'cn', 'uidNumber', 'mail',
            'loginShell', 'title', 'manager',
            'departmentNumber', 'roomNumber',
            'deploycode', 'orgchartmanager', 'utilityaccount')

        dh = DirectoryHelper(
            directoryCN, directoryPassword, directoryDomain)

        updates = {}
        groups = [v for k,v in request.params.items() if k == 'group']
        for item in update_items:
            if item in request.params:
                if item == 'cn':
                    updates['cn'] = request.params[item]
                    updates['gecos'] = request.params[item]
                    splitname = request.params[item].split()
                    updates['givenName'] = splitname[0]
                    if len(splitname) > 1:
                        updates['sn'] = splitname[1]
                updates[item] = request.params[item]

        # for key in updates, update ldap and ad
        for k, v in updates.iteritems():
            dh.update_attribute(account, k, v)
        # for group in groups, update ldap groups
        dh.set_groups(account, groups)

        session['flash'] = 'Successfully updated %s' % account
        session.save()

        updates['account'] = account
        ae = ActivityEngine(Session, session['active_user']['user_id'])
        ae.update('user', None, updates)

        return redirect(url(controller='users', action='edit', account=account))
コード例 #23
0
ファイル: users.py プロジェクト: seryl/Nodetraq
    def create(self):
        hash_params = ('username', 'name', 'mail',
                       'loginShell', 'title', 'manager',
                       'departmentNumber', 'roomNumber',
                       'orgchartmanager', 'utilityaccount', 'deploycode')
        dh = DirectoryHelper(
                directoryCN, directoryPassword, directoryDomain)

        data_map = {}
        groups = []
        for k,v in request.params.items():
            if k in hash_params:
                data_map[k] = v
            elif k == 'group':
                groups.append(v)

        data_map['username'] = data_map['username'].lower()

        dh.ldap.create(data_map['username'], data_map['name'],
                       data_map['mail'], data_map['loginShell'],
                       data_map['title'], data_map['manager'],
                       data_map['departmentNumber'], data_map['roomNumber'],
                       data_map['deploycode'], data_map['orgchartmanager'],
                       data_map['utilityaccount'] )

        dh.set_groups(data_map['username'], groups)

        session['flash'] = 'Successfully created %s' % data_map['username']
        session.save()

        data_map['account'] = data_map['username']
        ae = ActivityEngine(Session, session['active_user']['user_id'])
        ae.create('user', data_map)

        return redirect(url(
                controller='users', action='edit',
                account=data_map['username']))
コード例 #24
0
    def updatemany(self):
        ignore = ['Submit', 'username']
        ids = []
        if 'ids[]' in request.params:
            for id in request.params['ids[]']:
                ids.append(id)

        data = {}
        for key, value in params:
            if key == 'cpu_speed' and not value:
                continue
            data[key] = value

        activity_engine = ActivityEngine(Session,
                                         session['active_user']['user_id'])
コード例 #25
0
ファイル: loadbalancer.py プロジェクト: seryl/Nodetraq
    def addhost(self, format=None):
        valid = False
        response.content_type = "application/json"
        ids = []
        ips = []
        ports = []
        if 'ids[]' in request.params:
            ids = [v for k,v in request.params.items() if 'ids[]' in k]
        if 'ips[]' in request.params:
            ips = [v for k,v in request.params.items() if 'ips[]' in k]
        if 'pool' in request.params:
            pool = request.params['pool']
            if 'ports[]' in request.params:
                ports = [v for k,v in request.params.items()\
                        if 'ports[]' in k]
        if ids or ips:
            if ports:
                valid = True

        if not valid:
            session['flash'] = 'No ids were sent'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(
                        controller='loadbalancer', action='index'))

        lb = LoadBalancer(ip='your_lb_ip')
        members = lb.b.LocalLB.Pool.typefactory.create(
                'Common.IPPortDefinitionSequence')

        data = {}
        if ids:
            data['hosts'] = [
                Session.query(Node.hostname)\
                    .filter(Node.id == id)\
                    .first()[0] for id in ids ]
            iplist = [ip[0] for ip in Session.query(Node.primary_ip)\
                .filter(Node.id.in_(ids)).all()]

            members.item = [lb._member_factory(
                ':'.join([ip, ports[i]]))\
                                for i,ip in enumerate(iplist)]
        if ips:
            data['hosts'] = [ q[0] for q in\
                Session.query(Node.hostname)\
                    .filter(or_(Node.primary_ip == ip,
                                Node.secondary_ip == ip))\
                    .all() for ip in ips ]
            members.item = [lb._member_factory(
                ':'.join([ip, port]))\
                                for i,ip in enumerate(ips)]

        lb.add_members(pool, members)
        data['pool'] = pool
        data['type'] = 'add'
        ae = ActivityEngine(
            Session, session['active_user']['user_id'])
        if len(ids) > 2 or len(ips) > 2:
            status = ae.update_many('loadbalancer', data)
        else:
            status = ae.update('loadbalancer', None, data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(
                    controller='loadbalancer', action='index'))
コード例 #26
0
ファイル: loadbalancer.py プロジェクト: seryl/Nodetraq
    def createpool(self, format=None):
        response.content_type = "application/json"
        has_members = False
        ids = None
        ips = None
        use_primary = True

        if 'pool' in request.params:
            pool = request.params['pool']
        else:
            session['flash'] = 'Pool was not created'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(
                        controller='loadbalancer', action='index'))

        if 'ids[]' in request.params:
            ids = [v for k,v in request.params.items() if 'ids[]' in k]
            if 'use_secondary' in request.params:
                use_primary = False
        if 'ips[]' in request.params:
            ips = [v for k,v in request.params.items() if 'ips[]' in k]
        if ips or ids:
            if 'port' in request.params:
                port = request.params['port']
                has_members = True
        else:
            ids,ips,port = None,None,None

        lb = LoadBalancer(ip='your_lb_ip')
        mem_seq = lb.b.LocalLB.Pool.typefactory.create(
                'Common.IPPortDefinitionSequence')
        if ids:
            if use_primary:
                mem_seq.item = [lb._member_factory(
                    ':'.join([Session.query(Node.primary_ip)\
                            .filter(Node.id == id)\
                            .first()[0], port])) for id in ids]
            else:
                mem_seq.item = [lb._member_factory(
                    ':'.join([Session.query(Node.secondary_ip)\
                            .filter(Node.id == id)\
                            .first()[0], port])) for id in ids]
        elif ips:
            mem_seq.item = [lb._member_factory(
                ':'.join([ip, port])) for ip in ips]

        if not has_members:
            mem_seq = []

        lb.create_pool(pool, mem_seq)
        data = {}
        data['pool'] = pool
        if ids:
            data['hosts'] = [
                Session.query(Node)\
                    .filter(Node.id == id).first()\
                    for id in ids ]
        if ips:
            data['hosts'] = [
                Session.query(Node)\
                    .filter(or_(Node.primary_ip.in_([ips]),
                                Node.secondary_ip.in_([ips])))\
                    .first() for id in ids ]
        ae = ActivityEngine(
            Session, session['active_user']['user_id'])

        status = ae.create('loadbalancer', data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(
                    controller='loadbalancer', action='index'))
コード例 #27
0
    def removehost(self, format=None):
        valid = False
        response.content_type = "application/json"
        ids = []
        ips = []
        data = {}
        ports = []
        if 'ids[]' in request.params:
            ids = [v for k, v in request.params.items() if 'ids[]' in k]
        if 'ips[]' in request.params:
            ips = [v for k, v in request.params.items() if 'ips[]' in k]
        if 'pool' in request.params:
            pool = request.params['pool']
            if 'ports[]' in request.params:
                ports = [v for k,v in request.params.items()\
                        if 'ports[]' in k]
        if ids or ips:
            if ports:
                valid = True

        if not valid:
            session['flash'] = 'No ids were sent'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(controller='loadbalancer', action='index'))
        lb = LoadBalancer(ip='your_lb_ip')
        members = lb.b.LocalLB.Pool.typefactory.create(
            'Common.IPPortDefinitionSequence')

        if ids:
            data['hosts'] = [
                q[0] for q in\
                    Session.query(Node.hostname)\
                    .filter(Node.id.in_(ids)).all() ]

            members.item = [lb._member_factory(
                ':'.join([Session.query(Node.primary_ip)\
                        .filter(Node.id == id).first()[0],
                        ports[i]])) for i,id in enumerate(ids)]
        if ips:
            data['hosts'] = [ q[0] for q in \
                    Session.query(Node.hostname)\
                    .filter(or_(Node.primary_ip.in_(ips),
                            Node.secondary_ip.in_(ips)))\
                            .all() ]
            members.item = [
                lb._member_factory(':'.join(ip, ports[i]))
                for i, ip in enumerate(ips)
            ]

        lb.remove_members(pool, members)
        data['type'] = 'remove'
        data['pool'] = pool
        ae = ActivityEngine(Session, session['active_user']['user_id'])
        status = ae.update('loadbalancer', None, data)
        session['flash'] = status
        session.save()
        if format == 'json':

            return '{"success": true}'
        else:
            return redirect(url(controller='loadbalancer', action='index'))
コード例 #28
0
    def createpool(self, format=None):
        response.content_type = "application/json"
        has_members = False
        ids = None
        ips = None
        use_primary = True

        if 'pool' in request.params:
            pool = request.params['pool']
        else:
            session['flash'] = 'Pool was not created'
            session.save()
            if format == 'json':
                return '{"success": false}'
            else:
                return redirect(url(controller='loadbalancer', action='index'))

        if 'ids[]' in request.params:
            ids = [v for k, v in request.params.items() if 'ids[]' in k]
            if 'use_secondary' in request.params:
                use_primary = False
        if 'ips[]' in request.params:
            ips = [v for k, v in request.params.items() if 'ips[]' in k]
        if ips or ids:
            if 'port' in request.params:
                port = request.params['port']
                has_members = True
        else:
            ids, ips, port = None, None, None

        lb = LoadBalancer(ip='your_lb_ip')
        mem_seq = lb.b.LocalLB.Pool.typefactory.create(
            'Common.IPPortDefinitionSequence')
        if ids:
            if use_primary:
                mem_seq.item = [lb._member_factory(
                    ':'.join([Session.query(Node.primary_ip)\
                            .filter(Node.id == id)\
                            .first()[0], port])) for id in ids]
            else:
                mem_seq.item = [lb._member_factory(
                    ':'.join([Session.query(Node.secondary_ip)\
                            .filter(Node.id == id)\
                            .first()[0], port])) for id in ids]
        elif ips:
            mem_seq.item = [
                lb._member_factory(':'.join([ip, port])) for ip in ips
            ]

        if not has_members:
            mem_seq = []

        lb.create_pool(pool, mem_seq)
        data = {}
        data['pool'] = pool
        if ids:
            data['hosts'] = [
                Session.query(Node)\
                    .filter(Node.id == id).first()\
                    for id in ids ]
        if ips:
            data['hosts'] = [
                Session.query(Node)\
                    .filter(or_(Node.primary_ip.in_([ips]),
                                Node.secondary_ip.in_([ips])))\
                    .first() for id in ids ]
        ae = ActivityEngine(Session, session['active_user']['user_id'])

        status = ae.create('loadbalancer', data)
        session['flash'] = status
        session.save()
        if format == 'json':
            return '{"success": true}'
        else:
            return redirect(url(controller='loadbalancer', action='index'))