def _get_lun_map(self, path): """Gets the lun map by lun path.""" tag = None map_list = [] while True: lun_map_iter = NaElement('lun-map-get-iter') lun_map_iter.add_new_child('max-records', '100') if tag: lun_map_iter.add_new_child('tag', tag, True) query = NaElement('query') lun_map_iter.add_child_elem(query) query.add_node_with_children('lun-map-info', **{'path': path}) result = self.client.invoke_successfully(lun_map_iter, True) tag = result.get_child_content('next-tag') if result.get_child_content('num-records') and \ int(result.get_child_content('num-records')) >= 1: attr_list = result.get_child_by_name('attributes-list') lun_maps = attr_list.get_children() for lun_map in lun_maps: lun_m = dict() lun_m['initiator-group'] = lun_map.get_child_content( 'initiator-group') lun_m['lun-id'] = lun_map.get_child_content('lun-id') lun_m['vserver'] = lun_map.get_child_content('vserver') map_list.append(lun_m) if tag is None: break return map_list
def _wait_for_clone_finish(self, clone_op_id, vol_uuid): """Waits till a clone operation is complete or errored out.""" clone_ls_st = NaElement('clone-list-status') clone_id = NaElement('clone-id') clone_ls_st.add_child_elem(clone_id) clone_id.add_node_with_children('clone-id-info', **{'clone-op-id': clone_op_id, 'volume-uuid': vol_uuid}) task_running = True while task_running: result = self._invoke_successfully(clone_ls_st, None) status = result.get_child_by_name('status') ops_info = status.get_children() if ops_info: state = ops_info[0].get_child_content('clone-state') if state == 'completed': task_running = False elif state == 'failed': code = ops_info[0].get_child_content('error') reason = ops_info[0].get_child_content('reason') raise NaApiError(code, reason) else: time.sleep(1) else: raise NaApiError( 'UnknownCloneId', 'No clone operation for clone id %s found on the filer' % (clone_id))
def create_api_request(api_name, query=None, des_result=None, additional_elems=None, is_iter=False, record_step=50, tag=None): """Creates a NetApp api request. :param api_name: api name string :param query: api query as dict :param des_result: desired result as dict :param additional_elems: dict other than query and des_result :param is_iter: is iterator api :param record_step: records at a time for iter api :param tag: next tag for iter api """ api_el = NaElement(api_name) if query: query_el = NaElement('query') query_el.translate_struct(query) api_el.add_child_elem(query_el) if des_result: res_el = NaElement('desired-attributes') res_el.translate_struct(des_result) api_el.add_child_elem(res_el) if additional_elems: api_el.translate_struct(additional_elems) if is_iter: api_el.add_new_child('max-records', str(record_step)) if tag: api_el.add_new_child('tag', tag, True) return api_el
def _get_lun_list(self): """Gets the list of luns on filer. Gets the luns from cluster with vserver. """ tag = None while True: api = NaElement('lun-get-iter') api.add_new_child('max-records', '100') if tag: api.add_new_child('tag', tag, True) lun_info = NaElement('lun-info') lun_info.add_new_child('vserver', self.vserver) query = NaElement('query') query.add_child_elem(lun_info) api.add_child_elem(query) result = self.client.invoke_successfully(api) if result.get_child_by_name('num-records') and\ int(result.get_child_content('num-records')) >= 1: attr_list = result.get_child_by_name('attributes-list') self._extract_and_populate_luns(attr_list.get_children()) tag = result.get_child_content('next-tag') if tag is None: break
def _check_clone_status(self, clone_id, vol_uuid, name, new_name): """Checks for the job till completed.""" clone_status = NaElement("clone-list-status") cl_id = NaElement("clone-id") clone_status.add_child_elem(cl_id) cl_id.add_node_with_children("clone-id-info", **{"clone-op-id": clone_id, "volume-uuid": vol_uuid}) running = True clone_ops_info = None while running: result = self.client.invoke_successfully(clone_status, True) status = result.get_child_by_name("status") ops_info = status.get_children() if ops_info: for info in ops_info: if info.get_child_content("clone-state") == "running": time.sleep(1) break else: running = False clone_ops_info = info break else: if clone_ops_info: fmt = {"name": name, "new_name": new_name} if clone_ops_info.get_child_content("clone-state") == "completed": LOG.debug(_("Clone operation with src %(name)s" " and dest %(new_name)s completed") % fmt) else: LOG.debug(_("Clone operation with src %(name)s" " and dest %(new_name)s failed") % fmt) raise NaApiError( clone_ops_info.get_child_content("error"), clone_ops_info.get_child_content("reason") )
def _get_lun_map(self, path): """Gets the lun map by lun path.""" tag = None map_list = [] while True: lun_map_iter = NaElement("lun-map-get-iter") lun_map_iter.add_new_child("max-records", "100") if tag: lun_map_iter.add_new_child("tag", tag, True) query = NaElement("query") lun_map_iter.add_child_elem(query) query.add_node_with_children("lun-map-info", **{"path": path}) result = self.client.invoke_successfully(lun_map_iter, True) tag = result.get_child_content("next-tag") if result.get_child_content("num-records") and int(result.get_child_content("num-records")) >= 1: attr_list = result.get_child_by_name("attributes-list") lun_maps = attr_list.get_children() for lun_map in lun_maps: lun_m = dict() lun_m["initiator-group"] = lun_map.get_child_content("initiator-group") lun_m["lun-id"] = lun_map.get_child_content("lun-id") lun_m["vserver"] = lun_map.get_child_content("vserver") map_list.append(lun_m) if tag is None: break return map_list
def _get_lun_by_args(self, **args): """Retrives lun with specified args.""" lun_iter = NaElement("lun-get-iter") lun_iter.add_new_child("max-records", "100") query = NaElement("query") lun_iter.add_child_elem(query) query.add_node_with_children("lun-info", **args) luns = self.client.invoke_successfully(lun_iter) attr_list = luns.get_child_by_name("attributes-list") return attr_list.get_children()
def _get_lun_by_args(self, **args): """Retrives lun with specified args.""" lun_iter = NaElement('lun-get-iter') lun_iter.add_new_child('max-records', '100') query = NaElement('query') lun_iter.add_child_elem(query) query.add_node_with_children('lun-info', **args) luns = self.client.invoke_successfully(lun_iter) attr_list = luns.get_child_by_name('attributes-list') return attr_list.get_children()
def _create_vs_get(): """Create vs_get api request.""" vs_get = NaElement("vserver-get-iter") vs_get.add_new_child("max-records", "1") query = NaElement("query") query.add_node_with_children("vserver-info", **{"vserver-type": "node"}) vs_get.add_child_elem(query) desired = NaElement("desired-attributes") desired.add_node_with_children("vserver-info", **{"vserver-name": "", "vserver-type": ""}) vs_get.add_child_elem(desired) return vs_get
def _get_if_info_by_ip(self, ip): """Gets the network interface info by ip.""" net_if_iter = NaElement("net-interface-get-iter") net_if_iter.add_new_child("max-records", "10") query = NaElement("query") net_if_iter.add_child_elem(query) query.add_node_with_children("net-interface-info", **{"address": ip}) result = self._invoke_successfully(net_if_iter) if result.get_child_content("num-records") and int(result.get_child_content("num-records")) >= 1: attr_list = result.get_child_by_name("attributes-list") return attr_list.get_children() raise exception.NotFound(_("No interface found on cluster for ip %s") % (ip))
def _create_vs_get(): """Create vs_get api request.""" vs_get = NaElement('vserver-get-iter') vs_get.add_new_child('max-records', '1') query = NaElement('query') query.add_node_with_children('vserver-info', **{'vserver-type': 'node'}) vs_get.add_child_elem(query) desired = NaElement('desired-attributes') desired.add_node_with_children( 'vserver-info', **{'vserver-name': '', 'vserver-type': ''}) vs_get.add_child_elem(desired) return vs_get
def _create_avl_vol_request(self, vserver, tag=None): vol_get_iter = NaElement('volume-get-iter') vol_get_iter.add_new_child('max-records', '100') if tag: vol_get_iter.add_new_child('tag', tag, True) query = NaElement('query') vol_get_iter.add_child_elem(query) vol_attrs = NaElement('volume-attributes') query.add_child_elem(vol_attrs) if vserver: vol_attrs.add_node_with_children( 'volume-id-attributes', **{"owning-vserver-name": vserver}) vol_attrs.add_node_with_children( 'volume-state-attributes', **{"is-vserver-root": "false", "state": "online"}) desired_attrs = NaElement('desired-attributes') vol_get_iter.add_child_elem(desired_attrs) des_vol_attrs = NaElement('volume-attributes') desired_attrs.add_child_elem(des_vol_attrs) des_vol_attrs.add_node_with_children( 'volume-id-attributes', **{"name": None, "owning-vserver-name": None}) des_vol_attrs.add_node_with_children( 'volume-space-attributes', **{"size-available": None}) des_vol_attrs.add_node_with_children('volume-state-attributes', **{"is-cluster-volume": None, "is-vserver-root": None, "state": None}) return vol_get_iter
def _get_if_info_by_ip(self, ip): """Gets the network interface info by ip.""" net_if_iter = NaElement('net-interface-get-iter') net_if_iter.add_new_child('max-records', '10') query = NaElement('query') net_if_iter.add_child_elem(query) query.add_node_with_children('net-interface-info', **{'address': ip}) result = self._invoke_successfully(net_if_iter) if result.get_child_content('num-records') and\ int(result.get_child_content('num-records')) >= 1: attr_list = result.get_child_by_name('attributes-list') return attr_list.get_children() raise exception.NotFound( _('No interface found on cluster for ip %s') % (ip))
def _get_igroup_by_initiator(self, initiator): """Get igroups by initiator.""" tag = None igroup_list = [] while True: igroup_iter = NaElement('igroup-get-iter') igroup_iter.add_new_child('max-records', '100') if tag: igroup_iter.add_new_child('tag', tag, True) query = NaElement('query') igroup_iter.add_child_elem(query) igroup_info = NaElement('initiator-group-info') query.add_child_elem(igroup_info) igroup_info.add_new_child('vserver', self.vserver) initiators = NaElement('initiators') igroup_info.add_child_elem(initiators) initiators.add_node_with_children('initiator-info', **{'initiator-name': initiator}) des_attrs = NaElement('desired-attributes') des_ig_info = NaElement('initiator-group-info') des_attrs.add_child_elem(des_ig_info) des_ig_info.add_node_with_children('initiators', **{'initiator-info': None}) des_ig_info.add_new_child('vserver', None) des_ig_info.add_new_child('initiator-group-name', None) des_ig_info.add_new_child('initiator-group-type', None) des_ig_info.add_new_child('initiator-group-os-type', None) igroup_iter.add_child_elem(des_attrs) result = self.client.invoke_successfully(igroup_iter, False) tag = result.get_child_content('next-tag') if result.get_child_content('num-records') and\ int(result.get_child_content('num-records')) > 0: attr_list = result.get_child_by_name('attributes-list') igroups = attr_list.get_children() for igroup in igroups: ig = dict() ig['initiator-group-os-type'] = igroup.get_child_content( 'initiator-group-os-type') ig['initiator-group-type'] = igroup.get_child_content( 'initiator-group-type') ig['initiator-group-name'] = igroup.get_child_content( 'initiator-group-name') igroup_list.append(ig) if tag is None: break return igroup_list
def _get_vol_by_junc_vserver(self, vserver, junction): """Gets the volume by junction path and vserver.""" vol_iter = NaElement('volume-get-iter') vol_iter.add_new_child('max-records', '10') query = NaElement('query') vol_iter.add_child_elem(query) vol_attrs = NaElement('volume-attributes') query.add_child_elem(vol_attrs) vol_attrs.add_node_with_children( 'volume-id-attributes', **{'junction-path': junction, 'owning-vserver-name': vserver}) des_attrs = NaElement('desired-attributes') des_attrs.add_node_with_children('volume-attributes', **{'volume-id-attributes': None}) vol_iter.add_child_elem(des_attrs) result = self._invoke_successfully(vol_iter, vserver) if result.get_child_content('num-records') and\ int(result.get_child_content('num-records')) >= 1: attr_list = result.get_child_by_name('attributes-list') vols = attr_list.get_children() vol_id = vols[0].get_child_by_name('volume-id-attributes') return vol_id.get_child_content('name') msg_fmt = {'vserver': vserver, 'junction': junction} raise exception.NotFound(_("""No volume on cluster with vserver %(vserver)s and junction path %(junction)s """) % msg_fmt)
def _get_vol_by_junc_vserver(self, vserver, junction): """Gets the volume by junction path and vserver.""" vol_iter = NaElement('volume-get-iter') vol_iter.add_new_child('max-records', '10') query = NaElement('query') vol_iter.add_child_elem(query) vol_attrs = NaElement('volume-attributes') query.add_child_elem(vol_attrs) vol_attrs.add_node_with_children( 'volume-id-attributes', **{'junction-path': junction, 'owning-vserver-name': vserver}) des_attrs = NaElement('desired-attributes') des_attrs.add_node_with_children('volume-attributes', **{'volume-id-attributes': None}) vol_iter.add_child_elem(des_attrs) result = self._invoke_successfully(vol_iter, vserver) if result.get_child_content('num-records') and\ int(result.get_child_content('num-records')) >= 1: attr_list = result.get_child_by_name('attributes-list') vols = attr_list.get_children() vol_id = vols[0].get_child_by_name('volume-id-attributes') return vol_id.get_child_content('name') raise exception.NotFound(_("""No volume on cluster with vserver %(vserver)s and junction path %(junction)s """) % locals())
def _check_clone_status(self, clone_id, vol_uuid, name, new_name): """Checks for the job till completed.""" clone_status = NaElement('clone-list-status') cl_id = NaElement('clone-id') clone_status.add_child_elem(cl_id) cl_id.add_node_with_children( 'clone-id-info', **{ 'clone-op-id': clone_id, 'volume-uuid': vol_uuid }) running = True clone_ops_info = None while running: result = self.client.invoke_successfully(clone_status, True) status = result.get_child_by_name('status') ops_info = status.get_children() if ops_info: for info in ops_info: if info.get_child_content('clone-state') == 'running': time.sleep(1) break else: running = False clone_ops_info = info break else: if clone_ops_info: fmt = {'name': name, 'new_name': new_name} if clone_ops_info.get_child_content('clone-state')\ == 'completed': LOG.debug( _("Clone operation with src %(name)s" " and dest %(new_name)s completed") % fmt) else: LOG.debug( _("Clone operation with src %(name)s" " and dest %(new_name)s failed") % fmt) raise NaApiError( clone_ops_info.get_child_content('error'), clone_ops_info.get_child_content('reason'))
def _get_vol_by_junc_vserver(self, vserver, junction): """Gets the volume by junction path and vserver.""" vol_iter = NaElement("volume-get-iter") vol_iter.add_new_child("max-records", "10") query = NaElement("query") vol_iter.add_child_elem(query) vol_attrs = NaElement("volume-attributes") query.add_child_elem(vol_attrs) vol_attrs.add_node_with_children( "volume-id-attributes", **{"junction-path": junction, "owning-vserver-name": vserver} ) des_attrs = NaElement("desired-attributes") des_attrs.add_node_with_children("volume-attributes", **{"volume-id-attributes": None}) vol_iter.add_child_elem(des_attrs) result = self._invoke_successfully(vol_iter, vserver) if result.get_child_content("num-records") and int(result.get_child_content("num-records")) >= 1: attr_list = result.get_child_by_name("attributes-list") vols = attr_list.get_children() vol_id = vols[0].get_child_by_name("volume-id-attributes") return vol_id.get_child_content("name") msg_fmt = {"vserver": vserver, "junction": junction} raise exception.NotFound( _( """No volume on cluster with vserver %(vserver)s and junction path %(junction)s """ ) % msg_fmt )
def _get_igroup_by_initiator(self, initiator): """Get igroups by initiator.""" tag = None igroup_list = [] while True: igroup_iter = NaElement("igroup-get-iter") igroup_iter.add_new_child("max-records", "100") if tag: igroup_iter.add_new_child("tag", tag, True) query = NaElement("query") igroup_iter.add_child_elem(query) igroup_info = NaElement("initiator-group-info") query.add_child_elem(igroup_info) igroup_info.add_new_child("vserver", self.vserver) initiators = NaElement("initiators") igroup_info.add_child_elem(initiators) initiators.add_node_with_children("initiator-info", **{"initiator-name": initiator}) des_attrs = NaElement("desired-attributes") des_ig_info = NaElement("initiator-group-info") des_attrs.add_child_elem(des_ig_info) des_ig_info.add_node_with_children("initiators", **{"initiator-info": None}) des_ig_info.add_new_child("vserver", None) des_ig_info.add_new_child("initiator-group-name", None) des_ig_info.add_new_child("initiator-group-type", None) des_ig_info.add_new_child("initiator-group-os-type", None) igroup_iter.add_child_elem(des_attrs) result = self.client.invoke_successfully(igroup_iter, False) tag = result.get_child_content("next-tag") if result.get_child_content("num-records") and int(result.get_child_content("num-records")) > 0: attr_list = result.get_child_by_name("attributes-list") igroups = attr_list.get_children() for igroup in igroups: ig = dict() ig["initiator-group-os-type"] = igroup.get_child_content("initiator-group-os-type") ig["initiator-group-type"] = igroup.get_child_content("initiator-group-type") ig["initiator-group-name"] = igroup.get_child_content("initiator-group-name") igroup_list.append(ig) if tag is None: break return igroup_list
def _get_lun_list(self): """Gets the list of luns on filer. Gets the luns from cluster with vserver. """ tag = None while True: api = NaElement("lun-get-iter") api.add_new_child("max-records", "100") if tag: api.add_new_child("tag", tag, True) lun_info = NaElement("lun-info") lun_info.add_new_child("vserver", self.vserver) query = NaElement("query") query.add_child_elem(lun_info) api.add_child_elem(query) result = self.client.invoke_successfully(api) if result.get_child_by_name("num-records") and int(result.get_child_content("num-records")) >= 1: attr_list = result.get_child_by_name("attributes-list") self._extract_and_populate_luns(attr_list.get_children()) tag = result.get_child_content("next-tag") if tag is None: break
def _wait_for_clone_finish(self, clone_op_id, vol_uuid): """Waits till a clone operation is complete or errored out.""" clone_ls_st = NaElement("clone-list-status") clone_id = NaElement("clone-id") clone_ls_st.add_child_elem(clone_id) clone_id.add_node_with_children("clone-id-info", **{"clone-op-id": clone_op_id, "volume-uuid": vol_uuid}) task_running = True while task_running: result = self._invoke_successfully(clone_ls_st, None) status = result.get_child_by_name("status") ops_info = status.get_children() if ops_info: state = ops_info[0].get_child_content("clone-state") if state == "completed": task_running = False elif state == "failed": code = ops_info[0].get_child_content("error") reason = ops_info[0].get_child_content("reason") raise NaApiError(code, reason) else: time.sleep(1) else: raise NaApiError("UnknownCloneId", "No clone operation for clone id %s found on the filer" % (clone_id))
def _check_clone_status(self, clone_id, vol_uuid, name, new_name): """Checks for the job till completed.""" clone_status = NaElement('clone-list-status') cl_id = NaElement('clone-id') clone_status.add_child_elem(cl_id) cl_id.add_node_with_children( 'clone-id-info', **{'clone-op-id': clone_id, 'volume-uuid': vol_uuid}) running = True clone_ops_info = None while running: result = self.client.invoke_successfully(clone_status, True) status = result.get_child_by_name('status') ops_info = status.get_children() if ops_info: for info in ops_info: if info.get_child_content('clone-state') == 'running': time.sleep(1) break else: running = False clone_ops_info = info break else: if clone_ops_info: fmt = {'name': name, 'new_name': new_name} if clone_ops_info.get_child_content('clone-state')\ == 'completed': LOG.debug(_("Clone operation with src %(name)s" " and dest %(new_name)s completed") % fmt) else: LOG.debug(_("Clone operation with src %(name)s" " and dest %(new_name)s failed") % fmt) raise NaApiError( clone_ops_info.get_child_content('error'), clone_ops_info.get_child_content('reason'))