def update_object(self, member_db, id, m): if 'pool_id' in m and self._get_member_pool_id(member_db) != m['pool_id']: try: pool = self._api.loadbalancer_pool_read(id=m['pool_id']) except NoIdError: raise loadbalancer.PoolNotFound(pool_id=m['pool_id']) db_props = member_db.get_loadbalancer_member_properties() members = pool.get_loadbalancer_members() for member in members or []: member_obj = self._api.loadbalancer_member_read( id=member['uuid']) props = member_obj.get_loadbalancer_member_properties() if ((props.get_address() == db_props.get_address()) and (props.get_protocol_port() == db_props.get_protocol_port())): raise loadbalancer.MemberExists( address=props.get_address(), port=props.get_protocol_port(), pool=m['pool_id']) # delete member from old pool props = member_db.get_loadbalancer_member_properties() obj_uuid = member_db.uuid self._api.loadbalancer_member_delete(id=member_db.uuid) # create member for the new pool with same uuid and props id_perms = IdPermsType(enable=True) member_obj = LoadbalancerMember( obj_uuid, pool, loadbalancer_member_properties=props, id_perms=id_perms) member_obj.uuid = obj_uuid self._api.loadbalancer_member_create(member_obj) return True
def create(self, context, member): """ Create a loadbalancer_member object. """ m = member['member'] try: pool = self._api.loadbalancer_pool_read(id=m['pool_id']) except NoIdError: raise loadbalancer.PoolNotFound(pool_id=m['pool_id']) tenant_id = self._get_tenant_id_for_create(context, m) if str(uuid.UUID(tenant_id)) != pool.parent_uuid: raise n_exc.NotAuthorized() obj_uuid = uuidutils.generate_uuid() props = self.make_properties(m) id_perms = IdPermsType(enable=True) member_db = LoadbalancerMember( obj_uuid, pool, loadbalancer_member_properties=props, id_perms=id_perms) member_db.uuid = obj_uuid self._api.loadbalancer_member_create(member_db) return self.make_dict(member_db)
def create(self, context, member): """ Create a loadbalancer_member object. """ m = member['member'] try: pool = self._api.loadbalancer_pool_read(id=m['pool_id']) except NoIdError: raise loadbalancer.PoolNotFound(pool_id=m['pool_id']) tenant_id = self._get_tenant_id_for_create(context, m) if str(uuid.UUID(tenant_id)) != pool.parent_uuid: raise n_exc.NotAuthorized() obj_uuid = uuidutils.generate_uuid() props = self.make_properties(m) id_perms = IdPermsType(enable=True) member_db = LoadbalancerMember(obj_uuid, pool, loadbalancer_member_properties=props, id_perms=id_perms) member_db.uuid = obj_uuid self._api.loadbalancer_member_create(member_db) return self.make_dict(member_db)
def _create_member(self, member_id, pool_id): id_perms = IdPermsType(uuid=member_id, enable=True) props = self._loadbalancer_member_properties_build() member = LoadbalancerMember(loadbalancer_member_properties=props, id_perms=id_perms) member.uuid = member_id member.parent_uuid = pool_id return member
def update_object(self, member_db, id, m): if 'pool_id' in m and self._get_member_pool_id( member_db) != m['pool_id']: try: pool = self._api.loadbalancer_pool_read(id=m['pool_id']) except NoIdError: raise loadbalancer.PoolNotFound(pool_id=m['pool_id']) db_props = member_db.get_loadbalancer_member_properties() members = pool.get_loadbalancer_members() for member in members or []: member_obj = self._api.loadbalancer_member_read( id=member['uuid']) props = member_obj.get_loadbalancer_member_properties() if ((props.get_address() == db_props.get_address()) and (props.get_protocol_port() == db_props.get_protocol_port())): raise loadbalancer.MemberExists( address=props.get_address(), port=props.get_protocol_port(), pool=m['pool_id']) # delete member from old pool props = member_db.get_loadbalancer_member_properties() obj_uuid = member_db.uuid self._api.loadbalancer_member_delete(id=member_db.uuid) # create member for the new pool with same uuid and props id_perms = IdPermsType(enable=True) member_obj = LoadbalancerMember( obj_uuid, pool, loadbalancer_member_properties=props, id_perms=id_perms) member_obj.uuid = obj_uuid self._api.loadbalancer_member_create(member_obj) return True return False