Esempio n. 1
0
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
Esempio n. 2
0
 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
Esempio n. 3
0
 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))
Esempio n. 4
0
 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())
Esempio n. 5
0
 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
Esempio n. 6
0
 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()
Esempio n. 7
0
 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
Esempio n. 8
0
 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))
Esempio n. 9
0
 def _get_ontapi_version(self):
     """Gets the supported ontapi version."""
     ontapi_version = NaElement('system-get-ontapi-version')
     res = self._invoke_successfully(ontapi_version, False)
     major = res.get_child_content('major-version')
     minor = res.get_child_content('minor-version')
     return (major, minor)
Esempio n. 10
0
 def _get_igroup_by_initiator(self, initiator):
     """Get igroups by initiator."""
     igroup_list = NaElement('igroup-list-info')
     result = self.client.invoke_successfully(igroup_list, True)
     igroups = []
     igs = result.get_child_by_name('initiator-groups')
     if igs:
         ig_infos = igs.get_children()
         if ig_infos:
             for info in ig_infos:
                 initiators = info.get_child_by_name('initiators')
                 init_infos = initiators.get_children()
                 if init_infos:
                     for init in init_infos:
                         if init.get_child_content('initiator-name')\
                                 == initiator:
                             d = dict()
                             d['initiator-group-os-type'] = \
                                 info.get_child_content(
                                     'initiator-group-os-type')
                             d['initiator-group-type'] = \
                                 info.get_child_content(
                                     'initiator-group-type')
                             d['initiator-group-name'] = \
                                 info.get_child_content(
                                     'initiator-group-name')
                             igroups.append(d)
     return igroups
Esempio n. 11
0
 def _get_vol_luns(self, vol_name):
     """Gets the luns for a volume."""
     api = NaElement('lun-list-info')
     if vol_name:
         api.add_new_child('volume-name', vol_name)
     result = self.client.invoke_successfully(api, True)
     luns = result.get_child_by_name('luns')
     return luns.get_children()
Esempio n. 12
0
def check_apis_on_cluster(na_server, api_list=None):
    """Checks api availability and permissions on cluster.

    Checks api availability and permissions for executing user.
    Returns a list of failed apis.
    """
    api_list = api_list or []
    failed_apis = []
    if api_list:
        api_version = na_server.get_api_version()
        if api_version:
            major, minor = api_version
            if major == 1 and minor < 20:
                for api_name in api_list:
                    na_el = NaElement(api_name)
                    try:
                        na_server.invoke_successfully(na_el)
                    except Exception as e:
                        if isinstance(e, NaApiError):
                            if (e.code == NaErrors['API_NOT_FOUND'].code
                                    or e.code
                                    == NaErrors['INSUFFICIENT_PRIVS'].code):
                                failed_apis.append(api_name)
            elif major == 1 and minor >= 20:
                failed_apis = copy.copy(api_list)
                result = invoke_api(na_server,
                                    api_name='system-user-capability-get-iter',
                                    api_family='cm',
                                    additional_elems=None,
                                    is_iter=True)
                for res in result:
                    attr_list = res.get_child_by_name('attributes-list')
                    if attr_list:
                        capabilities = attr_list.get_children()
                        for capability in capabilities:
                            op_list = capability.get_child_by_name(
                                'operation-list')
                            if op_list:
                                ops = op_list.get_children()
                                for op in ops:
                                    apis = op.get_child_content('api-name')
                                    if apis:
                                        api_list = apis.split(',')
                                        for api_name in api_list:
                                            if (api_name and api_name.strip()
                                                    in failed_apis):
                                                failed_apis.remove(api_name)
                                    else:
                                        continue
            else:
                msg = _("Unsupported Clustered Data ONTAP version.")
                raise exception.VolumeBackendAPIException(data=msg)
        else:
            msg = _("Api version could not be determined.")
            raise exception.VolumeBackendAPIException(data=msg)
    return failed_apis
Esempio n. 13
0
 def _get_iscsi_service_details(self):
     """Returns iscsi iqn."""
     iscsi_service_iter = NaElement('iscsi-service-get-iter')
     result = self.client.invoke_successfully(iscsi_service_iter, True)
     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')
         iscsi_service = attr_list.get_child_by_name('iscsi-service-info')
         return iscsi_service.get_child_content('node-name')
     LOG.debug(_('No iscsi service found for vserver %s') % (self.vserver))
     return None
Esempio n. 14
0
 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'))
Esempio n. 15
0
    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
Esempio n. 16
0
 def _get_target_details(self):
     """Gets the target portal details."""
     iscsi_if_iter = NaElement('iscsi-portal-list-info')
     result = self.client.invoke_successfully(iscsi_if_iter, True)
     tgt_list = []
     portal_list_entries = result.get_child_by_name(
         'iscsi-portal-list-entries')
     if portal_list_entries:
         portal_list = portal_list_entries.get_children()
         for iscsi_if in portal_list:
             d = dict()
             d['address'] = iscsi_if.get_child_content('ip-address')
             d['port'] = iscsi_if.get_child_content('ip-port')
             d['tpgroup-tag'] = iscsi_if.get_child_content('tpgroup-tag')
             tgt_list.append(d)
     return tgt_list
Esempio n. 17
0
 def _get_target_details(self):
     """Gets the target portal details."""
     iscsi_if_iter = NaElement('iscsi-interface-get-iter')
     result = self.client.invoke_successfully(iscsi_if_iter, True)
     tgt_list = []
     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')
         iscsi_if_list = attr_list.get_children()
         for iscsi_if in iscsi_if_list:
             d = dict()
             d['address'] = iscsi_if.get_child_content('ip-address')
             d['port'] = iscsi_if.get_child_content('ip-port')
             d['tpgroup-tag'] = iscsi_if.get_child_content('tpgroup-tag')
             d['interface-enabled'] = iscsi_if.get_child_content(
                 'is-interface-enabled')
             tgt_list.append(d)
     return tgt_list
Esempio n. 18
0
 def _create_ems(stats, netapp_backend, server_type):
     """Create ems api request."""
     ems_log = NaElement('ems-autosupport-log')
     host = socket.getfqdn() or 'Cinder_node'
     dest = "cluster node" if server_type == "cluster"\
            else "7 mode controller"
     ems_log.add_new_child('computer-name', host)
     ems_log.add_new_child('event-id', '0')
     ems_log.add_new_child('event-source',
                           'Cinder driver %s' % netapp_backend)
     ems_log.add_new_child('app-version',
                           stats.get('driver_version', 'Undefined'))
     ems_log.add_new_child('category', 'provisioning')
     ems_log.add_new_child('event-description',
                           'OpenStack volume created on %s' % dest)
     ems_log.add_new_child('log-level', '6')
     ems_log.add_new_child('auto-support', 'true')
     return ems_log
Esempio n. 19
0
 def _create_ems(netapp_backend, app_version, server_type):
     """Create ems api request."""
     ems_log = NaElement('ems-autosupport-log')
     host = socket.getfqdn() or 'Cinder_node'
     if server_type == "cluster":
         dest = "cluster node"
     else:
         dest = "7 mode controller"
     ems_log.add_new_child('computer-name', host)
     ems_log.add_new_child('event-id', '0')
     ems_log.add_new_child('event-source',
                           'Cinder driver %s' % netapp_backend)
     ems_log.add_new_child('app-version', app_version)
     ems_log.add_new_child('category', 'provisioning')
     ems_log.add_new_child('event-description',
                           'OpenStack Cinder connected to %s' % dest)
     ems_log.add_new_child('log-level', '6')
     ems_log.add_new_child('auto-support', 'false')
     return ems_log
Esempio n. 20
0
 def _is_filer_ip(self, ip):
     """Checks whether ip is on the same filer."""
     try:
         ifconfig = NaElement('net-ifconfig-get')
         res = self._invoke_successfully(ifconfig, None)
         if_info = res.get_child_by_name('interface-config-info')
         if if_info:
             ifs = if_info.get_children()
             for intf in ifs:
                 v4_addr = intf.get_child_by_name('v4-primary-address')
                 if v4_addr:
                     ip_info = v4_addr.get_child_by_name('ip-address-info')
                     if ip_info:
                         address = ip_info.get_child_content('address')
                         if ip == address:
                             return True
                         else:
                             continue
     except Exception:
         return False
     return False
Esempio n. 21
0
 def _get_avl_volume_by_size(self, size):
     """Get the available volume by size."""
     vol_request = NaElement('volume-list-info')
     res = self.client.invoke_successfully(vol_request, True)
     volumes = res.get_child_by_name('volumes')
     vols = volumes.get_children()
     for vol in vols:
         avl_size = vol.get_child_content('size-available')
         state = vol.get_child_content('state')
         if float(avl_size) >= float(size) and state == 'online':
             avl_vol = dict()
             avl_vol['name'] = vol.get_child_content('name')
             avl_vol['block-type'] = vol.get_child_content('block-type')
             avl_vol['type'] = vol.get_child_content('type')
             avl_vol['size-available'] = avl_size
             if self.volume_list:
                 if avl_vol['name'] in self.volume_list:
                     return avl_vol
             else:
                 if self._check_vol_not_root(avl_vol):
                     return avl_vol
     return None
Esempio n. 22
0
 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
Esempio n. 23
0
 def _get_iscsi_service_details(self):
     """Returns iscsi iqn."""
     iscsi_service_iter = NaElement('iscsi-node-get-name')
     result = self.client.invoke_successfully(iscsi_service_iter, True)
     return result.get_child_content('node-name')