class Test(unittest.TestCase):
    def setUp(self):
        log = file('/tmp/ComHP_EVA_SSSU.log','w')
        self.sssu=HP_EVA_SSSU("127.0.0.1", "Administrator", "Administrator", "EVA5000", True, "../ComHP_EVA_SSSU_Sim.py", log)

    def tearDown(self):
        self.sssu.disconnect()

    def testAddVDisk(self):
        try:
            self.sssu.cmd("add", ["vdisk", "myvdisk", "size=100"])
        except Exception, e:
            self.assert_("Caught exception %s during adding vdisk myvdisk." %e)
Esempio n. 2
0
class Test(unittest.TestCase):
    def setUp(self):
        log = file('/tmp/ComHP_EVA_SSSU.log', 'w')
        self.sssu = HP_EVA_SSSU("127.0.0.1", "Administrator", "Administrator",
                                "EVA5000", True, "../ComHP_EVA_SSSU_Sim.py",
                                log)

    def tearDown(self):
        self.sssu.disconnect()

    def testAddVDisk(self):
        try:
            self.sssu.cmd("add", ["vdisk", "myvdisk", "size=100"])
        except Exception, e:
            self.assert_("Caught exception %s during adding vdisk myvdisk." %
                         e)
 def connect(self):
     """ Connects to the storage system """
     if not self.isConnected():
         mylogger.debug("system: %s, manager: %s, cmd: %s" %(self.system,self.manager,self.cmd))
         logfile=cmdlogfile=None
         if self.log:
             logfile = file(self.log, "w")
         if self.cmdlog:
             cmdlogfile = file(self.cmdlog, "w")
         self.sssu=HP_EVA_SSSU(self.manager, self.username, self.password, self.system, self.autoconnect, self.cmd, logfile, cmdlogfile)
         self.sssu.connect()
class HP_EVA_Storage(Storage):
    __logStrLevel__ = "comoonics.storage.hp.HP_EVA_Storage"
    """
    Baseclass for storagesystem implementations. All supported methods should be implemented. If not an exception is
    raised.
    """
    def __init__(self, **kwds):
        """ Default constructor does nothing here """
        super(HP_EVA_Storage, self).__init__(**kwds)
        (self.manager,self.system)=self.system.split("/")

        if not hasattr(self, "timeout"):
            self.timeout=1
        if kwds.has_key("timeout"):
            self.cmd=kwds["timout"]

        if not hasattr(self, "cmd"):
#            mylogger.debug("setting cmd cause not set kwds: %s" %(kwds))
            self.cmd=HP_EVA_SSSU.SSSU_CMD
#        else:
#            mylogger.debug("cmd already set to cause %s" %(self.cmd))
        if kwds.has_key("cmd"):
            self.cmd=kwds["cmd"]

        self.log=None
        if kwds.has_key("log"):
            self.log=kwds["log"]
        else:
            self.log='/tmp/ComHP_EVA_SSSU.log'
        self.cmdlog=None
        if kwds.has_key("cmdlog"):
            self.cmdlog=kwds["cmdlog"]
        else:
            self.cmdlog='/tmp/ComHP_EVA_SSSU_cmd.log'
        self.autoconnect=False
        self.sssu=None
        if kwds.has_key("autoconnect"):
            self.autoconnect=kwds["autoconnect"]
            self.connect()


    def getConnectionName(self):
        """ for singleton implementation if you want to have only one connection per storage system you can use
        this string as unique reference.
        Returns the self.system
        """
        return "%s-%s" %(self.system, self.manager)

    def isConnected(self):
        """ Returns True if this instance is already connected to the storagesystem or otherwise False.
        Default is False."""
        return self.sssu and self.sssu.connected()

    def connect(self):
        """ Connects to the storage system """
        if not self.isConnected():
            mylogger.debug("system: %s, manager: %s, cmd: %s" %(self.system,self.manager,self.cmd))
            logfile=cmdlogfile=None
            if self.log:
                logfile = file(self.log, "w")
            if self.cmdlog:
                cmdlogfile = file(self.cmdlog, "w")
            self.sssu=HP_EVA_SSSU(self.manager, self.username, self.password, self.system, self.autoconnect, self.cmd, logfile, cmdlogfile)
            self.sssu.connect()

    def map_luns(self, *params):
        """ Lunmaps the given disk. Hosts and luns are integrated insite the disk and returns the luns if need be. """
        if not params or len(params)==0:
            raise TypeError("map_luns takes at lease 1 argument 0 given.")
        elif params and len(params)>2:
            raise TypeError("map_luns takes at lease 1 argument %u given." %(len(params)))
        disk=params[0]
        source=None
        if len(params)==2:
            source=params[1]
        luns=list()
        for lun in disk.getLuns():
            for host in disk.getHostNames(lun):
                try:
                    self.sssu.cmd("add lun %s vdisk=\"%s\" host=\"%s\"" %(lun, disk.getAttribute("name"), host))
                    if lun.count("\\")==0:
                        if host.count("\\")==0:
                            host="\Hosts\\%s" %(host)
                        self.sssu.cmd("ls lun \"%s\\%s\" xml" %(host,lun))
                    else:
                        self.sssu.cmd("ls lun \"%s\" xml" %(lun))
                    lun=None
                    if self.sssu.xml_output:
                        lun=HP_EVA_Object.fromXML(self.sssu.xml_output)
                        luns.append(lun)
                except CommandError, ce:
                    raise ErrorDuringExecution("Could not add lun to storage\nExecution errorcode %u: \ncmd: %s" %(self.sssu.last_error_code, self.sssu.last_cmd), ce)
        self.wait()
        return luns
 def setUp(self):
     log = file('/tmp/ComHP_EVA_SSSU.log','w')
     self.sssu=HP_EVA_SSSU("127.0.0.1", "Administrator", "Administrator", "EVA5000", True, "../ComHP_EVA_SSSU_Sim.py", log)
Esempio n. 6
0
 def setUp(self):
     log = file('/tmp/ComHP_EVA_SSSU.log', 'w')
     self.sssu = HP_EVA_SSSU("127.0.0.1", "Administrator", "Administrator",
                             "EVA5000", True, "../ComHP_EVA_SSSU_Sim.py",
                             log)