def safe_delete(self): # flush dev's buf first try: if self.dev_file != "": check_output([BLOCKDEV_CMD, "--flushbufs", self.dev_file]) except Exception: pass delete_path = os.path.join("/sys/class/scsi_device/", self.scsi_id, "device/delete") write_file_entry(delete_path, "1\n")
def flush_page_cache(self): """flush page cache from memory""" # sync check_output(["/bin/sync"]) # clean cache write_file_entry("/proc/sys/vm/drop_caches", "3\n")
def offline_dev(self, scsi_id): state_path = os.path.join("/sys/class/scsi_device/", self.scsi_id, "device/state") write_file_entry(state_path, "offline\n")
def rescan_dev(self): '''rescan the device can update the device's state(including size) in host system''' state_path = os.path.join("/sys/class/scsi_device/", self.scsi_id, "device/rescan") write_file_entry(state_path, "1\n")
def del_group(self, bond_name, user="******"): # check exist group_name_list = self.group_name_list() if bond_name not in group_name_list: raise StorLeverError("%s not found" % bond_name, 404) if bond_name == "bond0": # if want to delete bond0, there must be no other # group, because bonding driver would auto create bond0 interface # if there is another bond interface beyond bond0 if (len(group_name_list) > 1) or \ (group_name_list[0] != bond_name): raise StorLeverError("Other bonding group must be " "deleted before bond0 can be deleted", 400) bond_group = BondGroup(bond_name) bond_slaves = bond_group.slaves check_output([IFDOWN, bond_name]) # get mutex with self.lock: # change bond.conf self._del_bond_from_conf(bond_name) # modify the slaves conf, especial for the first one, # copy the bond ip config to it is_first = True for slave in bond_slaves: slave_object = EthInterface(slave) if is_first: slave_object.conf["IPADDR"] = \ bond_group.conf.get("IPADDR", "") slave_object.conf["NETMASK"] = \ bond_group.conf.get("NETMASK", "") slave_object.conf["GATEWAY"] = \ bond_group.conf.get("GATEWAY", "") is_first = False else: slave_object.conf["IPADDR"] = "" slave_object.conf["NETMASK"] = "" slave_object.conf["GATEWAY"] = "" slave_object.conf.delete("MASTER") slave_object.conf.delete("SLAVE") slave_object.save_conf() # delete ifcfg-bond* ifcfg_name = os.path.join(IF_CONF_PATH, "ifcfg-%s" % bond_name) if os.path.isfile(ifcfg_name): os.remove(ifcfg_name) # restart network if os.path.exists(BONDING_MASTERS): write_file_entry(BONDING_MASTERS, "-%s\n" % bond_name) for slave_if in bond_slaves: check_output([IFUP, slave_if]) # if_mgr()._restart_network() logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "bond group %s (slaves:[%s]) " "is deleted by user(%s)" % (bond_name, ",".join(bond_slaves), user))