コード例 #1
0
    def opget(self, index, selector):
        if not index in self.views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return {'Status': 'Success', 'Message': 'Not supported'}
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) +
                     "...")
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid,
                                              clsName)
        else:
            retval = self.proto.opget(self.views[index], clsName, selector)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr, self.enumid, clsName,
                                       retval)
        if not 'Data' in retval or retval['Data'] is None:
            return retval

        counter = 0
        for i in retval['Data']:
            counter = counter + 1
            retval['Data'][clsName] = retval['Data'][i]
            del retval['Data'][i]
            if counter <= 1:
                break
        return retval
コード例 #2
0
    def connect(self, ipaddr, creds, pOptions):
        self.ipaddr = ipaddr
        self.creds = None
        for supported_cred in self.supported_creds:
            if isinstance(creds, ProtocolCredentialsFactory):
                self.creds = creds.get(supported_cred)
            elif TypeHelper.resolve(
                    creds.enid) == TypeHelper.resolve(supported_cred):
                self.creds = creds
            else:
                logger.debug("Invalid credentials provided!")
        if self.creds is None:
            return False

        logger.debug("Connecting to " + ipaddr + " using " + str(self.creds))
        if Simulator.is_simulating():
            return Simulator.simulator_connect(self.ipaddr, self.enumid, self)
        self.pOptions = None
        if pOptions is None:
            pOptions = ProtocolOptionsFactory()
        for supported_pOp in [self.enumid]:
            if isinstance(pOptions, ProtocolOptionsFactory):
                self.pOptions = pOptions.get(supported_pOp)
            elif TypeHelper.resolve(
                    pOptions.enid) == TypeHelper.resolve(supported_pOp):
                self.pOptions = pOptions
            else:
                logger.debug("Invalid pOptions provided!")
        return self.my_connect(ipaddr, self.creds, self.pOptions)
コード例 #3
0
    def _enumerate_view(self, index, views, bTrue):
        if not index in views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return {'Status': 'Success', 'Message': 'Not supported'}
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) + "...")
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid, clsName)
        else:
            # Changed True to False for having single session
            wsprof = views[index]
            filter = None
            if isinstance(views[index], list) and self.enumid == ProtocolEnum.WSMAN:
                wsprof = views[index][0]
                filter = views[index][1]
            retval = self.proto.enumerate(clsName, wsprof, self.selectors, False, filter)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr, self.enumid, clsName, retval)
        if not 'Data' in retval or retval['Data'] is None or len(retval['Data']) <= 0:
            return retval
        if index in self.classifier_cond:
            chk_func = self.classifier_cond[index].get(self.enumid, None)
            if chk_func:
                (valid, flist) = chk_func(retval['Data'][clsName], clsName)
                if valid:
                    retval['Data'][clsName] = flist
                else:
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier condition not satisfied'
                    }
        if index in self.classifier:
            for attr in self.classifier[index]:
                if not clsName in retval['Data']:
                    return {
                        'Status': 'Failed',
                        'Message': clsName + ' instance is not found!'
                    }
                if not attr in retval['Data'][clsName]:
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier attribute not found!'
                    }
                if not re.search(self.classifier[index][attr],
                                 retval['Data'][clsName][attr]):
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier did not match!'
                    }

        for en in self.view_fieldspec:
            if en != index:
                continue
            for retobj in retval['Data']:
                if isinstance(retval['Data'][retobj], dict):
                    self._apply_spec(retval['Data'][retobj], en)
                else:
                    for i in retval['Data'][retobj]:
                        self._apply_spec(i, en)
        return retval
コード例 #4
0
ファイル: sdkproto.py プロジェクト: hunter007VN/omsdk
    def _enumerate_view(self, index, views, bTrue):
        if not index in views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return { 'Status' : 'Success', 'Message' : 'Not supported' }
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) + "..." )
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid, clsName)
        else:
            retval = self.proto.enumerate(clsName, views[index], self.selectors, True)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr,self.enumid, clsName, retval)
        if not 'Data' in retval or retval['Data'] is None:
            return retval
        if index in self.classifier:
            for attr in self.classifier[index]:
                if not clsName in retval['Data']:
                    return {
                        'Status' : 'Failed',
                        'Message': clsName + ' instance is not found!'
                    }
                if not attr in retval['Data'][clsName]:
                    return {
                        'Status' : 'Failed',
                        'Message': 'Classifier attribute not found!'
                    }
                if not re.search(self.classifier[index][attr],
                           retval['Data'][clsName][attr]):
                    return {
                        'Status' : 'Failed',
                        'Message': 'Classifier did not match!'
                    }

        for en in self.view_fieldspec:
            if en != index:
                continue
            for retobj in retval['Data']:
                if isinstance(retval['Data'][retobj], dict):
                    self._apply_spec(retval['Data'][retobj], en)
                else:                        
                    for i in retval['Data'][retobj]:
                        self._apply_spec(i, en)
        return retval
コード例 #5
0
ファイル: sdkproto.py プロジェクト: hunter007VN/omsdk
    def operation(self, cmdname, **kwargs):
        argvals = {}
        counter = 1
        fcmd = self.cmds[cmdname]
        for name, value in kwargs.items():
            logger.debug(str(counter) + ":"+ str(name) + "=" + str(value))
            counter = counter + 1
            if not name in fcmd["Args"]:
                str_err = name + " argument is invalid!"
                logger.debug(str_err)
                return { 'Status' : 'Failed', 'Message' : str_err }
            argtype = fcmd["Args"][name]
            if not TypeHelper.belongs_to(argtype, value):
                str_err = name + " argument is invalid type! "
                str_err = str_err + "Expected "+ str(argtype) + ". "
                str_err = str_err + "But got "+ str(type(value))
                str_err = str_err + "But got "+ str(value)
                logger.debug(str_err)
                return { 'Status' : 'Failed', 'Message' : str_err }
            argvals[name] = value
    
        for name in fcmd["Args"]:
            if not name in argvals:
                str_err = name + " argument is empty!"
                logger.debug(str_err)
                return { 'Status' : 'Failed', 'Message' : str_err }
        paramlist = []
        for (pname, argname, field, ftype, dest) in fcmd["Parameters"]:
            if field is None:
                argval = argvals[argname]
            else:
                argval = getattr(argvals[argname], field)
            paramlist.append(argval)

        logger.debug(PrettyPrint.prettify_json(paramlist))
    
        if Simulator.is_simulating():
            str_out = cmdname + "("
            comma = ""
            for i in paramlist:
                str_out = str_out + comma + type(i).__name__ + str(i)
            comma = ","
            str_out = str_out + ")"
            logger.debug(str_out)
            rjson= { 'Status' : 'Success' }
        else:
            rjson = self.proto.operation(self.cmds, cmdname, *paramlist)
        rjson['retval' ] = True
        if not 'Message' in rjson:
            rjson['Message'] = 'none'
        return rjson
コード例 #6
0
logging.basicConfig(level=logging.ERROR)
from omsdk.sdkfile import FileOnShare
from omsdk.sdkprint import PrettyPrint
import logging
from omdrivers.lifecycle.iDRAC.RAIDHelper import *

myshare = FileOnShare(remote="\\\\<share>\\Share",
                      mount_point='Z:\\',
                      isFolder=True,
                      creds=UserCredentials("user@domain", "password"))

ipaddr = '192.168.0.1'
logging.basicConfig(level=logging.DEBUG)
myshare.valid = True

Simulator.start_simulating()
sd = sdkinfra()
sd.importPath()
idrac = sd.get_driver('iDRAC', ipaddr, UserCredentials('user', 'pass'))
idrac.config_mgr.set_liason_share(myshare)


def emailtest(idrac, address, expected, action=1):
    print(expected)
    idrac.config_mgr._sysconfig.iDRAC.EmailAlert._index_helper.printx()
    try:
        if action == 1:
            idrac.config_mgr._sysconfig.iDRAC.EmailAlert.new(
                Address_EmailAlert=address, CustomMsg_EmailAlert=address)
        else:
            idrac.config_mgr._sysconfig.iDRAC.EmailAlert.remove(