def delete(allocation): """Delete an allocation""" admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) try: admin_alloc.delete(allocation) except ldap_exceptions.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def reserve(allocation, cell, memory, cpu, disk, rank, max_utilization, features): """Reserve capacity on a given cell.""" admin_cell_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn) data = {} if memory: data['memory'] = memory if cpu: data['cpu'] = cpu if disk: data['disk'] = disk if rank is not None: data['rank'] = rank if max_utilization is not None: data['max_utilization'] = max_utilization if features: data['features'] = features try: admin_cell_alloc.create([cell, allocation], data) except ldap3.LDAPEntryAlreadyExistsResult: admin_cell_alloc.update([cell, allocation], data) try: admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.get(allocation))) except ldap3.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def test_list(self): """Dummy test for treadmill.api.allocation._list()""" alloc_admin = admin.Allocation(None) self.alloc.list(['*-*']) alloc_admin.list.assert_called_with({'_id': '*-*'}) self.alloc.list(['tenant-*']) alloc_admin.list.assert_called_with({'_id': 'tenant*-*'}) self.alloc.list(['tenant-allocation']) alloc_admin.list.assert_called_with({'_id': 'tenant*-allocation'})
def configure(environment, allocation): """Create, get or modify allocation configuration""" admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) attrs = {} if environment: attrs['environment'] = environment if attrs: try: admin_alloc.create(allocation, attrs) except ldap_exceptions.LDAPEntryAlreadyExistsResult: admin_alloc.update(allocation, attrs) try: cli.out(formatter(admin_alloc.get(allocation))) except ldap_exceptions.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def assign(allocation, cell, priority, pattern, delete): """Manage application assignments""" admin_cell_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn) assignment = {'pattern': pattern, 'priority': priority} if delete: assignment['_delete'] = True data = {'assignments': [assignment]} if delete: admin_cell_alloc.update([cell, allocation], data) else: try: admin_cell_alloc.create([cell, allocation], data) except ldap_exceptions.LDAPEntryAlreadyExistsResult: admin_cell_alloc.update([cell, allocation], data) try: admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.get(allocation))) except ldap_exceptions.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def reserve(allocation, cell, memory, cpu, disk, rank, rank_adjustment, max_utilization, traits, partition, delete): """Reserve capacity on a given cell""" admin_cell_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn) if delete: admin_cell_alloc.delete([cell, allocation]) return data = {} if memory: data['memory'] = memory if cpu: data['cpu'] = cpu if disk: data['disk'] = disk if rank is not None: data['rank'] = rank if rank_adjustment is not None: data['rank_adjustment'] = rank_adjustment if max_utilization is not None: data['max_utilization'] = max_utilization if traits: data['traits'] = cli.combine(traits) if partition: if partition == '-': partition = None data['partition'] = partition try: admin_cell_alloc.create([cell, allocation], data) except ldap_exceptions.LDAPEntryAlreadyExistsResult: admin_cell_alloc.update([cell, allocation], data) try: admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.get(allocation, dirty=True))) except ldap_exceptions.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def assign(allocation, cell, priority, pattern, delete): """Manage application assignments""" admin_cell_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn) try: cell_alloc = admin_cell_alloc.get([cell, allocation]) except ldap_exceptions.LDAPNoSuchObjectResult: cell_alloc = {} assignments = cell_alloc.get('assignments', []) if delete: new_assigments = [ assignment for assignment in assignments if assignment['pattern'] != pattern ] assignments = new_assigments else: assignment_attrs = {'priority': priority} for assignment in assignments: if assignment['pattern'] == pattern: assignment.update(assignment_attrs) break else: assignments.append({'pattern': pattern, 'priority': priority}) cell_alloc_attrs = {'assignments': assignments} if cell_alloc: admin_cell_alloc.update([cell, allocation], cell_alloc_attrs) else: admin_cell_alloc.create([cell, allocation], cell_alloc_attrs) try: admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.get(allocation, dirty=True))) except ldap_exceptions.LDAPNoSuchObjectResult: click.echo('Allocation does not exist: %s' % allocation, err=True)
def test_list(self): """Dummy test for treadmill.api.allocation._list()""" alloc_admin = admin.Allocation(None) self.alloc.list() alloc_admin.list.assert_called_with({})
def setUp(self): self.alloc = admin.Allocation( admin.Admin(None, 'dc=xx,dc=com'))
def _list(): """List configured allocations""" admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.list({})))
def _admin_alloc(): """Lazily return admin allocation object. """ return admin.Allocation(context.GLOBAL.ldap.conn)