def zonecreate(session, zones): """Create new Zone(s) Example usage of the method:: zones = [ { "zone-name": name, "member-entry": { "entry-name": members, } } ] result = zonecreate(session, zones) :param session: session returned by login :param zones: an array of zone and new members :rtype: dictionary of return status matching rest response *use cases* 1. Create new Zone(s) """ new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) return result
def zoneremove(session, zones): """Remove from existing Zone(s) specified member(s) Example usage of the method:: zones = [ { "zone-name": name, "member-entry": { "entry-name": members, } } ] result = zoneremove(session, zones) :param session: session returned by login :param zones: an array of zone and members to be deleted :rtype: dictionary of return status matching rest response *use cases* 1. Delete specific members from an existing Zone(s) """ new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.delete(session) return result
def pzoneadd(session, zones): """Add to an existing Peer Zone(s) additional member(s) Example usage of the method:: zones = [ { "zone-name": name, "zone-type": pyfos_zone.ZONE_TYPE_PEER, "member-entry": { "entry-name": members, "principal-entry-name": pmembers } } ] result = pzoneadd(session, zones) :param session: session returned by login :param zones: an array of zone and new members :rtype: dictionary of return status matching rest response *use cases* 1. add a new member to an existing Peer Zone(s) """ new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) return result
def aliasadd(session, aliases): """Add to an existing alias additional members Example usage of the method:: aliases = [ { "alias-name": name, "member-entry": {"alias-entry-name": members} } ] result = aliasadd(session, aliases) :param session: session returned by login :param aliases: an array of alias and new members :rtype: dictionary of return status matching rest response *use cases* 1. add a new member to an existing alias """ new_defined = pyfos_zone.defined_configuration() new_defined.set_alias(aliases) result = new_defined.post(session) return result
def cfgcreate(session, cfgs): """Create new cfg(s) with member(s) Example usage of the method:: cfgs = [ { "cfg-name": name, "member-zone": {"zone-name": members} } ] result = cfgcreate(session, cfgs) :param session: session returned by login :param cfgs: an array of cfg and members :rtype: dictionary of return status matching rest response *use cases* 1. create new cfg """ new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.post(session) return result
def cfgdelete(session, cfgs): """Delete existing cfg(s) Example usage of the method:: cfgs = [ { "cfg-name": name, } ] result = cfgdelete(session, cfgs) :param session: session returned by login :param cfgs: an array of cfg :rtype: dictionary of return status matching rest response *use cases* 1. delete an existing cfg """ new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.delete(session) return result
def aliasremove(session, aliases): """Remove members from existing alias(es) Example usage of the method:: aliases = [ { "alias-name": name, "member-entry": {"alias-entry-name": members} } ] result = aliasremove(session, aliases) :param session: session returned by login :param aliases: an array of alias and to be removed members :rtype: dictionary of return status matching rest response *use cases* 1. remove members from an existing alias """ new_defined = pyfos_zone.defined_configuration() new_defined.set_alias(aliases) result = new_defined.delete(session) return result
def zonedelete(session, zones): """Delete an existing Zone(s) Example usage of the method:: zones = [ { "zone-name": name, } ] result = zonedelete(session, zones) :param session: session returned by login :param zones: an array of zone and new members :rtype: dictionary of return status matching rest response *use cases* 1. Delete an existing Zone(s) """ new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.delete(session) return result
def aliasdelete(session, aliases): """Delete alisas(es) Example usage of the method:: aliases = [ { "alias-name": name, } ] result = aliadelete(session, aliases) :param session: session returned by login :param aliases: an array of alias to be deleted :rtype: dictionary of return status matching rest response *use cases* 1. delete an alias """ new_defined = pyfos_zone.defined_configuration() new_defined.set_alias(aliases) result = new_defined.delete(session) return result
def zone_allow_pair_to_peer(session, prefix, hostport, targetname, targetport, if_no_cfg, checkmode): """Create/add a pair of host and target to a peer Zone Example usage of the method to create a new peer zone with a pair:: ret_code, result = zone_allow_pair_to_peer.zone_allow_pair_to_peer( session, "az__pz__", "11:22:33:44:55:66:77:88", "mytarget", "88:77:66:55:44:33:22:11", "cfg_if_there_is_non", True) if ret_code > 0: print ("zone db changed", ret_code, result) else: print ("zone db didn't change", ret_code, result) :param session: session returned by login :param prefix: prefix for the peer Zone name :param hostport: WWN of the host port :param targetname: string name of the target :param targetport: WWN of the target port :param if_no_cfg: CFG name to be used if there are no enabled CFG :param checkmode: indicate if Zone DB is to be updated or return status only :rtype: return code and dictionary of status description *use cases* 1. pass in host/target pair to create peer zone 2. pass in host/target pair to create peer zone """ cfgname = if_no_cfg zonename = prefix + targetname prezone_defined = pyfos_zone.defined_configuration.get(session) if pyfos_util.is_failed_resp(prezone_defined): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": prezone_defined}) prezone_effective = pyfos_zone.effective_configuration.get(session) if pyfos_util.is_failed_resp(prezone_effective): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": prezone_effective}) # check to see if we have a cfg for the zone already found_matching_cfg, found_matching_cfg_with_zone = find_matching_cfg( prezone_defined, cfgname, zonename) # check to see if we have a peer zone for the target already (found_matching_zone, found_matching_zone_with_target, found_matching_zone_with_host) = find_matching_zone( prezone_defined, zonename, hostport, targetport) # if didn't find the matching zone with the name, let's create one ZONE_EXISTED = 0 ZONE_CREATED = 1 ZONE_MODIFIED = 2 zone_action = ZONE_EXISTED if not found_matching_zone: if checkmode is False: zones = [ { "zone-name": zonename, "zone-type": pyfos_zone.ZONE_TYPE_PEER, "member-entry": { "principal-entry-name": [targetport], "entry-name": [hostport] } } ] new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) zone_action = ZONE_CREATED else: # I found zone. but it has unknown WWN for the principal target if not found_matching_zone_with_target: return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": "found expected zone but unexpected target WWN"}) else: # I found the zone & the target but the host is missing # let's add to it if not found_matching_zone_with_host: if checkmode is False: zones = [ { "zone-name": zonename, "zone-type": pyfos_zone.ZONE_TYPE_PEER, "member-entry": {"entry-name": [hostport]} } ] new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) zone_action = ZONE_MODIFIED # check to see if we have an enabled cfg # if nothing is enabled, just create a new cfg and add the # zone if prezone_effective.peek_cfg_name() is None: if checkmode is False: if (found_matching_cfg is False or found_matching_cfg_with_zone is False): # if cfg is not found or member is not found, post to create or # add to it. cfgs = [ { "cfg-name": cfgname, "member-zone": {"zone-name": [zonename]} } ] new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) new_effective = pyfos_zone.effective_configuration() new_effective.set_cfg_name(cfgname) new_effective.set_checksum(prezone_effective.peek_checksum()) result = new_effective.patch(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) if zone_action is ZONE_CREATED: return (RET_ZONE_CREATED_ADDED_TO_NEW_CFG, {"return_str": zonename + " created and added to new cfg of " + cfgname}) elif zone_action is ZONE_MODIFIED: return (RET_ZONE_UPDATED_ADDED_TO_NEW_CFG, {"return_str": "host added to " + zonename + " added to new cfg of " + cfgname}) else: return (RET_ZONE_EXIST_ADDED_TO_NEW_CFG, {"return_str": "existing " + zonename + " added to new cfg of " + cfgname}) else: # we have something that is already enabled # let's add to the existing cfg found_in_cfg = False for cfg in prezone_defined.peek_cfg(): if prezone_effective.peek_cfg_name() == cfg["cfg-name"]: for mem in cfg["member-zone"]["zone-name"]: if mem == zonename: found_in_cfg = True break if found_in_cfg: if zone_action is ZONE_EXISTED: return (RET_ZONE_EXIST_IN_CFG, {"return_str": "already zoned in " + zonename + " and effective in " + prezone_effective.peek_cfg_name()}) elif zone_action is ZONE_MODIFIED: # if zone is already part of cfg but modified, # just enable again if checkmode is False: new_effective = pyfos_zone.effective_configuration() new_effective.set_cfg_name( prezone_effective.peek_cfg_name()) new_effective.set_checksum( prezone_effective.peek_checksum()) result = new_effective.patch(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result}) return (RET_ZONE_UPDATED_IN_CFG, {"return_str": "added to " + zonename + " and effective in " + prezone_effective.peek_cfg_name()}) else: # we have a new zone created but already in the cfg? # seems like an error case. but still works nevertheless # just return no change return (RET_ZONE_CREATED_IN_CFG, {"return_str": "created " + zonename + " and already effective in " + prezone_effective.peek_cfg_name()}) else: # not found in cfg. add to the existing cfg and enable if checkmode is False: cfgs = [ { "cfg-name": prezone_effective.peek_cfg_name(), "member-zone": {"zone-name": [zonename]} } ] new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) new_effective = pyfos_zone.effective_configuration() new_effective.set_cfg_name(prezone_effective.peek_cfg_name()) new_effective.set_checksum(prezone_effective.peek_checksum()) result = new_effective.patch(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, {"line": inspect.currentframe().f_lineno, "error": result}) if zone_action is ZONE_CREATED: return (RET_ZONE_CREATED_ADDED_TO_CFG, {"return_str": zonename + " created and added to existing cfg of " + prezone_effective.peek_cfg_name()}) elif zone_action is ZONE_MODIFIED: return (RET_ZONE_UPDATED_ADDED_TO_CFG, {"return_str": "added to " + zonename + " and added to existing cfg of " + prezone_effective.peek_cfg_name()}) else: return (RET_ZONE_EXIST_ADDED_TO_CFG, {"return_str": "existing " + zonename + " added to existing cfg of " + prezone_effective.peek_cfg_name()})
def zone_allow_pair(session, prefix, hostname, hostport, targetname, targetport, if_no_cfg, checkmode): """Create/add a pair of host and target to a tuple Zone Example usage of the method to create a new tuple zone with a pair:: ret_code, result = zone_allow_pair.zone_allow_pair( session, "az__pz__", "myhost", "11:22:33:44:55:66:77:88", "mytarget", "88:77:66:55:44:33:22:11", "cfg_if_there_is_non", True) if ret_code > 0: print ("zone db changed", result) else: print ("zone db didn't change", result) :param session: session returned by login :param prefix: prefix for the peer Zone name :param hostname: string name of the host :param hostport: WWN of the host port :param targetname: string name of the target :param targetport: WWN of the target port :param if_no_cfg: CFG name to be used if there are no enabled CFG :param checkmode: indicate if Zone DB is to be updated or return status only :rtype: return code and dictionary of status description *use cases* 1. pass in host/target pair to create tuple zone 2. pass in host/target pair to create tuple zone """ cfgname = if_no_cfg zonename = zonename_get(prefix, hostname, targetname) cfgmem = [zonename] zonemem = [hostport, targetport] prezonedb = pyfos_zone.effective_configuration.get(session) if pyfos_util.is_failed_resp(prezonedb): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": prezonedb }) # check to see if we have an enabled cfg if prezonedb.peek_cfg_name() is None: if checkmode is False: zones = [{ "zone-name": zonename, "member-entry": { "entry-name": zonemem } }] new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) cfgs = [{ "cfg-name": cfgname, "member-zone": { "zone-name": cfgmem } }] new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) new_effective = pyfos_zone.effective_configuration() new_effective.set_cfg_name(cfgname) checksum = prezonedb.peek_checksum() new_effective.set_checksum(checksum) result = new_effective.patch(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) return (RET_ZONE_CREATED_ADDED_TO_NEW_CFG, { "return_str": zonename + " created and added to new cfg of " + cfgname }) else: # we have something that is already enabled found_in_effective_zone = False found_in_zone = None found_in_cfg = None for zone in prezonedb.peek_enabled_zone(): found_host = False found_target = False for mem in zone["member-entry"]["entry-name"]: if mem == hostport: found_host = True elif mem == targetport: found_target = True if found_host and found_target: found_in_effective_zone = True found_in_zone = zone found_in_cfg = prezonedb.peek_cfg_name() break if found_in_effective_zone is True: return (RET_ZONE_EXIST_IN_CFG, { "return_str": "already zoned in " + found_in_zone["zone-name"] + " and effective in " + found_in_cfg }) else: if checkmode is False: zones = [{ "zone-name": zonename, "member-entry": { "entry-name": zonemem } }] new_defined = pyfos_zone.defined_configuration() new_defined.set_zone(zones) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) cfgs = [{ "cfg-name": prezonedb.peek_cfg_name(), "member-zone": { "zone-name": [zonename] } }] new_defined = pyfos_zone.defined_configuration() new_defined.set_cfg(cfgs) result = new_defined.post(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) new_effective = pyfos_zone.effective_configuration() new_effective.set_cfg_name(prezonedb.peek_cfg_name()) checksum = prezonedb.peek_checksum() new_effective.set_checksum(checksum) result = new_effective.patch(session) if pyfos_util.is_failed_resp(result): return (RET_ERR, { "line": inspect.currentframe().f_lineno, "error": result }) return (RET_ZONE_CREATED_ADDED_TO_CFG, { "return_str": zonename + " created and added to existing cfg of " + prezonedb.peek_cfg_name() })