def is_supported_firmware(self): """Check firmware version is v6.4 or higher. This API checks if the firmware version per the plug-in support level. This only checks major and minor version. """ cmd = ['version'] firmware = 0 try: stdout, stderr = self._execute_shell_cmd(cmd) if (stdout): for line in stdout: if 'Fabric OS: v' in line: LOG.debug("Firmware version string:%s", line) ver = line.split('Fabric OS: v')[1].split('.') if (ver): firmware = int(ver[0] + ver[1]) return firmware > 63 else: LOG.error(_("No CLI output for firmware version check")) return False except processutils.ProcessExecutionError as e: msg = _("Error while getting data via ssh: (command=%(cmd)s " "error=%(err)s).") % {'cmd': cmd, 'err': e} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)
def _get_switch_info(self, cmd_list): stdout, stderr, sw_data = None, None, None try: stdout, stderr = self._run_ssh(cmd_list, True, 1) if (stdout): sw_data = stdout.splitlines() return sw_data except processutils.ProcessExecutionError as e: msg = _("Error while getting data via ssh: (command=%(cmd)s " "error=%(err)s).") % {'cmd': cmd_list, 'err': e} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)
def _is_trans_abortable(self): is_abortable = False stdout, stderr = None, None stdout, stderr = self._run_ssh([ZoneConstant.CFG_SHOW_TRANS], True, 1) output = stdout.splitlines() is_abortable = False for line in output: if (ZoneConstant.TRANS_ABORTABLE in line): is_abortable = True break if stderr: msg = _("Error while checking transaction status: %s") % stderr raise exception.BrocadeZoningCliException(reason=msg) else: return is_abortable
def apply_zone_change(self, cmd_list): """Execute zoning cli with no status update. Executes CLI commands such as addZone where status return is not expected. """ stdout, stderr = None, None LOG.debug("Executing command via ssh: %s", cmd_list) stdout, stderr = self._run_ssh(cmd_list, True, 1) # no output expected, so output means there is an error if stdout: msg = _("Error while running zoning CLI: (command=%(cmd)s " "error=%(err)s).") % {'cmd': cmd_list, 'err': stdout} LOG.error(msg) self._cfg_trans_abort() raise exception.BrocadeZoningCliException(reason=msg)
def delete_zones(self, zone_names, activate, active_zone_set=None): """Delete zones from fabric. Method to delete the active zone config zones params zone_names: zoneNames separated by semicolon params activate: True/False params active_zone_set: the active zone set dict retrieved from get_active_zone_set method """ active_zoneset_name = None zone_list = [] if not active_zone_set: active_zone_set = self.get_active_zone_set() active_zoneset_name = active_zone_set[ZoneConstant.ACTIVE_ZONE_CONFIG] zone_list = active_zone_set[ZoneConstant.CFG_ZONES] zones = self.patrn.split(''.join(zone_names)) cmd = None try: if len(zones) == len(zone_list): self.deactivate_zoneset() cmd = 'cfgdelete "%(active_zoneset_name)s"' \ % {'active_zoneset_name': active_zoneset_name} # Active zoneset is being deleted, hence reset activate flag activate = False else: cmd = 'cfgremove "%(active_zoneset_name)s", "%(zone_names)s"' \ % {'active_zoneset_name': active_zoneset_name, 'zone_names': zone_names } LOG.debug("Delete zones: Config cmd to run: %s", cmd) self.apply_zone_change(cmd.split()) for zone in zones: self._zone_delete(zone) if activate: self.activate_zoneset(active_zoneset_name) else: self._cfg_save() except Exception as e: msg = _( "Deleting zones failed: (command=%(cmd)s error=%(err)s).") % { 'cmd': cmd, 'err': six.text_type(e) } LOG.error(msg) self._cfg_trans_abort() raise exception.BrocadeZoningCliException(reason=msg)
def add_zones(self, zones, activate): """Add zone configuration. This method will add the zone configuration passed by user. input params: zones - zone names mapped to members. zone members are colon separated but case-insensitive { zonename1:[zonememeber1,zonemember2,...], zonename2:[zonemember1, zonemember2,...]...} e.g: {'openstack50060b0000c26604201900051ee8e329': ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:29'] } activate - True/False """ LOG.debug("Add Zones - Zones passed: %s", zones) cfg_name = None iterator_count = 0 zone_with_sep = '' active_zone_set = self.get_active_zone_set() LOG.debug("Active zone set:%s", active_zone_set) zone_list = active_zone_set[ZoneConstant.CFG_ZONES] LOG.debug("zone list:%s", zone_list) for zone in zones.keys(): # if zone exists, its an update. Delete & insert # TODO(skolathur): This can be optimized to an update call later LOG.debug("Update call") if (zone in zone_list): try: self.delete_zones(zone, activate) except exception.BrocadeZoningCliException: with excutils.save_and_reraise_exception(): LOG.error(_("Deleting zone failed %s"), zone) LOG.debug("Deleted Zone before insert : %s", zone) zone_members_with_sep = ';'.join(str(member) for member in zones[zone]) LOG.debug("Forming command for add zone") cmd = 'zonecreate "%(zone)s", "%(zone_members_with_sep)s"' % { 'zone': zone, 'zone_members_with_sep': zone_members_with_sep} LOG.debug("Adding zone, cmd to run %s", cmd) self.apply_zone_change(cmd.split()) LOG.debug("Created zones on the switch") if(iterator_count > 0): zone_with_sep += ';' iterator_count += 1 zone_with_sep += zone try: cfg_name = active_zone_set[ZoneConstant.ACTIVE_ZONE_CONFIG] cmd = None if not cfg_name: cfg_name = ZoneConstant.OPENSTACK_CFG_NAME cmd = 'cfgcreate "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} else: cmd = 'cfgadd "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} LOG.debug("New zone %s", cmd) self.apply_zone_change(cmd.split()) self._cfg_save() if activate: self.activate_zoneset(cfg_name) except Exception as e: self._cfg_trans_abort() msg = _("Creating and activating zone set failed: " "(Zone set=%(cfg_name)s error=%(err)s)." ) % {'cfg_name': cfg_name, 'err': e} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)
def add_zones(self, zones, activate, active_zone_set=None): """Add zone configuration. This method will add the zone configuration passed by user. input params: zones - zone names mapped to members. zone members are colon separated but case-insensitive { zonename1:[zonememeber1,zonemember2,...], zonename2:[zonemember1, zonemember2,...]...} e.g: {'openstack50060b0000c26604201900051ee8e329': ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:29'] } activate - True/False active_zone_set - active zone set dict retrieved from get_active_zone_set method """ LOG.debug("Add Zones - Zones passed: %s", zones) cfg_name = None iterator_count = 0 zone_with_sep = '' if not active_zone_set: active_zone_set = self.get_active_zone_set() LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[zone_constant.CFG_ZONES] zone_updated = [] LOG.debug("zone list: %s", zone_list) for zone in zones.keys(): # If zone exists, its an update. Delete & insert # TODO(skolathur): This still need to be optimized # to an update call later. Now we just handled the # same zone name with same zone members. if (zone in zone_list): if set(zones[zone]) == set(zone_list[zone]): break try: self.delete_zones(zone, activate, active_zone_set) zone_updated.append(zone) except exception.BrocadeZoningCliException: with excutils.save_and_reraise_exception(): LOG.error(_LE("Deleting zone failed %s"), zone) LOG.debug("Deleted Zone before insert : %s", zone) zone_members_with_sep = ';'.join( str(member) for member in zones[zone]) LOG.debug("Forming command for add zone") cmd = 'zonecreate "%(zone)s", "%(zone_members_with_sep)s"' % { 'zone': zone, 'zone_members_with_sep': zone_members_with_sep } LOG.debug("Adding zone, cmd to run %s", cmd) self.apply_zone_change(cmd.split()) LOG.debug("Created zones on the switch") if (iterator_count > 0): zone_with_sep += ';' iterator_count += 1 zone_with_sep += zone if not zone_with_sep: return try: # If all existing zones are to be updated, the active zone config # will require a recreate, since all zones have been deleted. if len(zone_list) == len(zone_updated): cfg_name = None else: cfg_name = active_zone_set[zone_constant.ACTIVE_ZONE_CONFIG] cmd = None if not cfg_name: cfg_name = zone_constant.OPENSTACK_CFG_NAME cmd = 'cfgcreate "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} else: cmd = 'cfgadd "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} LOG.debug("New zone %s", cmd) self.apply_zone_change(cmd.split()) if activate: self.activate_zoneset(cfg_name) else: self._cfg_save() except Exception as e: self._cfg_trans_abort() msg = _("Creating and activating zone set failed: " "(Zone set=%(cfg_name)s error=%(err)s).") % { 'cfg_name': cfg_name, 'err': six.text_type(e) } LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)
def update_zones(self, zones, activate, operation, active_zone_set=None): """Update the zone configuration. This method will update the zone configuration passed by user. :param zones: zone names mapped to members. Zone members are colon separated but case-insensitive .. code-block:: python { zonename1:[zonememeber1, zonemember2,...], zonename2:[zonemember1, zonemember2,...]...} e.g: { 'openstack50060b0000c26604201900051ee8e329': ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:29'] } :param activate: True/False :param operation: zone add or zone remove :param active_zone_set: active zone set dict retrieved from get_active_zone_set method """ LOG.debug("Update Zones - Zones passed: %s", zones) cfg_name = None iterator_count = 0 zone_with_sep = '' if not active_zone_set: active_zone_set = self.get_active_zone_set() LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[zone_constant.CFG_ZONES] LOG.debug("Active zone list: %s", zone_list) for zone in zones.keys(): zone_members_with_sep = ';'.join( str(member) for member in zones[zone]) cmd = '%(operation)s "%(zone)s", "%(zone_members_with_sep)s"' % { 'operation': operation, 'zone': zone, 'zone_members_with_sep': zone_members_with_sep } LOG.debug("Updating zone, cmd to run %s", cmd) self.apply_zone_change(cmd.split()) if (iterator_count > 0): zone_with_sep += ';' iterator_count += 1 zone_with_sep += zone if not zone_with_sep: return try: cfg_name = active_zone_set[zone_constant.ACTIVE_ZONE_CONFIG] if activate: self.activate_zoneset(cfg_name) else: self._cfg_save() except Exception as e: self._cfg_trans_abort() msg = _("Activating zone set failed: " "(Zone set=%(cfg_name)s error=%(err)s).") % { 'cfg_name': cfg_name, 'err': six.text_type(e) } LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)
def add_zones(self, zones, activate, active_zone_set=None): """Add zone configuration. This method will add the zone configuration passed by user. :param zones: zone names mapped to members. Zone members are colon separated but case-insensitive .. code-block:: python { zonename1:[zonememeber1, zonemember2,...], zonename2:[zonemember1, zonemember2,...]...} e.g: { 'openstack50060b0000c26604201900051ee8e329': ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:29'] } :param activate: True/False :param active_zone_set: active zone set dict retrieved from get_active_zone_set method """ LOG.debug("Add Zones - Zones passed: %s", zones) cfg_name = None iterator_count = 0 zone_with_sep = '' if not active_zone_set: active_zone_set = self.get_active_zone_set() LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[zone_constant.CFG_ZONES] LOG.debug("zone list: %s", zone_list) for zone in zones.keys(): zone_members_with_sep = ';'.join( str(member) for member in zones[zone]) LOG.debug("Forming command for create zone") cmd = 'zonecreate "%(zone)s", "%(zone_members_with_sep)s"' % { 'zone': zone, 'zone_members_with_sep': zone_members_with_sep } LOG.debug("Creating zone, cmd to run %s", cmd) self.apply_zone_change(cmd.split()) if (iterator_count > 0): zone_with_sep += ';' iterator_count += 1 zone_with_sep += zone if not zone_with_sep: return try: # If zone_list exists, there are active zones, # so add new zone to existing active config. # Otherwise, create the zone config. if zone_list: cfg_name = active_zone_set[zone_constant.ACTIVE_ZONE_CONFIG] else: cfg_name = None cmd = None if not cfg_name: cfg_name = zone_constant.OPENSTACK_CFG_NAME cmd = 'cfgcreate "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} else: cmd = 'cfgadd "%(zoneset)s", "%(zones)s"' \ % {'zoneset': cfg_name, 'zones': zone_with_sep} LOG.debug("Zone config cmd to run %s", cmd) self.apply_zone_change(cmd.split()) if activate: self.activate_zoneset(cfg_name) else: self._cfg_save() except Exception as e: self._cfg_trans_abort() msg = _("Creating and activating zone set failed: " "(Zone set=%(cfg_name)s error=%(err)s).") % { 'cfg_name': cfg_name, 'err': six.text_type(e) } LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg)