def __iter__(self): for i in range(self.num_snaps): yield { 'id': self.snaps[i].id, 'size': self.snaps[i].size, 'name': decode_cstr(self.snaps[i].name), }
def __iter__(self): for i in range(self.num_snaps): yield { 'id' : self.snaps[i].id, 'size' : self.snaps[i].size, 'name' : decode_cstr(self.snaps[i].name), }
def list_lockers(self): """ List clients that have locked the image and information about the lock. :returns: dict - contains the following keys: * ``tag`` - the tag associated with the lock (every additional locker must use the same tag) * ``exclusive`` - boolean indicating whether the lock is exclusive or shared * ``lockers`` - a list of (client, cookie, address) tuples """ clients_size = c_size_t(512) cookies_size = c_size_t(512) addrs_size = c_size_t(512) tag_size = c_size_t(512) exclusive = c_int(0) while True: c_clients = create_string_buffer(clients_size.value) c_cookies = create_string_buffer(cookies_size.value) c_addrs = create_string_buffer(addrs_size.value) c_tag = create_string_buffer(tag_size.value) ret = self.librbd.rbd_list_lockers(self.image, byref(exclusive), byref(c_tag), byref(tag_size), byref(c_clients), byref(clients_size), byref(c_cookies), byref(cookies_size), byref(c_addrs), byref(addrs_size)) if ret >= 0: break elif ret != -errno.ERANGE: raise make_ex(ret, 'error listing images') if ret == 0: return [] clients = [ client.decode("utf-8") for client in c_clients.raw[:clients_size.value - 1].split(b'\0') ] cookies = [ cookie.decode("utf-8") for cookie in c_cookies.raw[:cookies_size.value - 1].split(b'\0') ] addrs = [ addr.decode("utf-8") for addr in c_addrs.raw[:addrs_size.value - 1].split(b'\0') ] return { 'tag': decode_cstr(c_tag), 'exclusive': exclusive.value == 1, 'lockers': list(zip(clients, cookies, addrs)), }
def list_lockers(self): """ List clients that have locked the image and information about the lock. :returns: dict - contains the following keys: * ``tag`` - the tag associated with the lock (every additional locker must use the same tag) * ``exclusive`` - boolean indicating whether the lock is exclusive or shared * ``lockers`` - a list of (client, cookie, address) tuples """ clients_size = c_size_t(512) cookies_size = c_size_t(512) addrs_size = c_size_t(512) tag_size = c_size_t(512) exclusive = c_int(0) while True: c_clients = create_string_buffer(clients_size.value) c_cookies = create_string_buffer(cookies_size.value) c_addrs = create_string_buffer(addrs_size.value) c_tag = create_string_buffer(tag_size.value) ret = self.librbd.rbd_list_lockers(self.image, byref(exclusive), byref(c_tag), byref(tag_size), byref(c_clients), byref(clients_size), byref(c_cookies), byref(cookies_size), byref(c_addrs), byref(addrs_size)) if ret >= 0: break elif ret != -errno.ERANGE: raise make_ex(ret, 'error listing images') if ret == 0: return [] clients = [client.decode("utf-8") for client in c_clients.raw[:clients_size.value - 1].split(b'\0')] cookies = [cookie.decode("utf-8") for cookie in c_cookies.raw[:cookies_size.value - 1].split(b'\0')] addrs = [addr.decode("utf-8") for addr in c_addrs.raw[:addrs_size.value - 1].split(b'\0')] return { 'tag' : decode_cstr(c_tag), 'exclusive' : exclusive.value == 1, 'lockers' : list(zip(clients, cookies, addrs)), }
def list(self, ioctx): """ List image names. :param ioctx: determines which RADOS pool is read :type ioctx: :class:`rados.Ioctx` :returns: list -- a list of image names """ size = c_size_t(512) while True: c_names = create_string_buffer(size.value) ret = self.librbd.rbd_list(ioctx.io, byref(c_names), byref(size)) if ret >= 0: break elif ret != -errno.ERANGE: raise make_ex(ret, 'error listing images') return [decode_cstr(name) for name in c_names.raw.split(b'\0') if len(name) > 0]
def list(self, ioctx): """ List image names. :param ioctx: determines which RADOS pool is read :type ioctx: :class:`rados.Ioctx` :returns: list -- a list of image names """ size = c_size_t(512) while True: c_names = create_string_buffer(size.value) ret = self.librbd.rbd_list(ioctx.io, byref(c_names), byref(size)) if ret >= 0: break elif ret != -errno.ERANGE: raise make_ex(ret, 'error listing images') return [ decode_cstr(name) for name in c_names.raw.split(b'\0') if len(name) > 0 ]