def get(self, name, detailed=False): res = self._col.find_one({'n': name}, _field_spec(detailed)) if not res: raise errors.PoolDoesNotExist(name) return _normalize(res, detailed)
def get(self, name, detailed=False): stmt = sa.sql.select([tables.Pools]).where(tables.Pools.c.name == name) pool = self._conn.execute(stmt).fetchone() if pool is None: raise errors.PoolDoesNotExist(name) return _normalize(pool, detailed)
def update(self, name, **kwargs): names = ('uri', 'weight', 'options') fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None, key_transform=lambda x: x[0]) assert fields, '`weight`, `uri`, or `options` not found in kwargs' res = self._col.update({'n': name}, {'$set': fields}, upsert=False) if not res['updatedExisting']: raise errors.PoolDoesNotExist(name)
def create(self, name, pool, project=None, capabilities=None): # NOTE(flaper87): Check if there are pools in this group. # Should there be a `group_exists` method? if not list(self._pools_ctrl.get_group(pool)): raise errors.PoolDoesNotExist(pool) capabilities = {} if capabilities is None else capabilities self._col.update({ 'n': name, 'p': project }, {'$set': { 's': pool, 'c': capabilities }}, upsert=True)
def update(self, name, **kwargs): # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid # overwriting the existing options field with None, since that # one can be null. names = ('uri', 'weight', 'options') fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None) assert fields, '`weight`, `uri`, or `options` not found in kwargs' if 'options' in fields: fields['options'] = utils.json_encode(fields['options']) stmt = sa.sql.update( tables.Pools).where(tables.Pools.c.name == name).values(**fields) res = self._conn.execute(stmt) if res.rowcount == 0: raise errors.PoolDoesNotExist(name)