コード例 #1
0
ファイル: RAIDHelper.py プロジェクト: akaushik-vm/omsdk
    def _init_storage(self):
        if self.storage.inited:
            return self.storage

        self.entity.get_partial_entityjson(
            self.entity.ComponentEnum.Controller,
            self.entity.ComponentEnum.Enclosure,
            self.entity.ComponentEnum.VirtualDisk,
            self.entity.ComponentEnum.PhysicalDisk)
        raid_tree = self.entity.ContainmentTree
        logger.debug(PrettyPrint.prettify_json(raid_tree['Storage']))
        self.storage.load(raid_tree["Storage"], self.entity)
        if self.storage.ControllerCount <= 0:
            logger.debug("No Controllers!")
            return self.storage
        self.storage.Controller.remove(PrimaryStatus='0')
        for controller in self.storage.Controller:
            controller.Enclosure.remove(PrimaryStatus='0')
            for encl in controller.Enclosure:
                encl.PhysicalDisk.remove_matching(
                    "entry.RaidStatus != 'Ready' and entry.FreeSize._value == 0"
                )
            controller.PhysicalDisk.remove_matching(
                "entry.RaidStatus != 'Ready' and entry.FreeSize._value == 0")
        return self.storage
コード例 #2
0
ファイル: updaterepo.py プロジェクト: hunter007VN/omsdk
 def filter_by_component(self, model,swidentity, compfqdd=None,ostype="WIN", compare=None):
     if compfqdd and len(compfqdd) <= 0: compfqdd = None
     logger.debug('filter_by_component::compfqdd=' + str(compfqdd))
     logger.debug(PrettyPrint.prettify_json(swidentity))
     if self.source:
         count = self.source.filter_bundle(model, ostype, tosource=self)
         logger.debug('filtered bundle ' + str(count))
     source = self
     if compare: source = compare
     if not self.source: return 0
     count = 0
     for firm in swidentity["Firmware"]:
         if compfqdd and firm['FQDD'] not in compfqdd:
             continue
         logger.debug(firm['FQDD'])
         if 'ComponentID' in firm and firm['ComponentID']:
             count += self.source.filter_by_compid(model,
                          firm['ComponentID'], ostype, firm, tosource=source)
             continue
         pcispec = {}
         if 'VendorID' in firm and firm['VendorID']:
             pcispec['vendorID'] = firm['VendorID']
         if 'DeviceID' in firm and firm['DeviceID']:
             pcispec['deviceID'] = firm['DeviceID']
         if 'SubVendorID' in firm and firm['SubVendorID']:
             pcispec['subVendorID'] = firm['SubVendorID']
         if 'SubDeviceID' in firm and firm['SubDeviceID']:
             pcispec['subDeviceID'] = firm['SubDeviceID']
         if len(pcispec) > 0:
             count += self.source.filter_by_pci(model, pcispec,
                                 ostype, firm, tosource=source)
             continue
     logger.debug('Filtered ' + str(count) + ' entries!')
     return count
コード例 #3
0
ファイル: iDRACLicense.py プロジェクト: akaushik-vm/omsdk
    def _import_license_share_fqdd(self,
                                   license_share_path,
                                   fqdd="iDRAC.Embedded.1",
                                   options=LicenseApiOptionsEnum.NoOptions):
        self._get_license_json()
        if not "License" in self.license:
            return False
        llist = self.license["License"]
        if isinstance(self.license["License"], dict):
            llist = [llist]
        retval = {'Status': 'Success', 'Imported': 0, 'Failed to Import': 0}
        for i in llist:
            entitlementId = i["EntitlementID"]
            rjson = self.entity._import_license_share(
                share=license_share_path,
                creds=license_share_path.creds,
                name="Import",
                fqdd=fqdd,
                options=options)
            rjson = self._job_mgr._job_wait(rjson['Message'], rjson)
            logger.debug(PrettyPrint.prettify_json(rjson))
            if rjson['Status'] == 'Success':
                retval['Imported'] += 1
            else:
                retval['Failed to Import'] += 1
            if retval['Imported'] == 0 and retval['Failed to Import'] > 0:
                retval['Status'] = 'Failed'

        return retval
コード例 #4
0
 def printx(self):
     with self.myentitylistlock:
         for device in self.entityjson["devices"]["Devices"]:
             logger.debug("-======" + str(device) + "----------")
             if not device is None:
                 logger.debug(PrettyPrint.prettify_json(device.entityjson))
             logger.debug("-==================-------")
コード例 #5
0
ファイル: sdksnmp.py プロジェクト: akaushik-vm/omsdk
 def _snmpset(self, defaultIdx, var):
     try:
         newvar = []
         for i in var:
             newvar.append((i + "." + str(defaultIdx), var[i]))
         logger.debug(PrettyPrint.prettify_json(newvar))
         logger.debug("host=" + self.host + ":community=" + self.rwstring)
         errorIndication, errorStatus, errorIndex, varBinds = self.cmdGen.setCmd(
             cmdgen.CommunityData(self.rwstring),
             cmdgen.UdpTransportTarget((self.host, 161)), *newvar)
         if errorIndication:
             rjson = {'Status': 'Failed', 'Message': str(errorIndication)}
         elif errorStatus:
             rjson = {
                 'Status':
                 'Failed',
                 'Message':
                 ('%s at %s' %
                  (errorStatus.prettyPrint(),
                   errorIndex and varBinds[int(errorIndex) - 1] or '?'))
             }
         else:
             rjson = {'Status': 'Success', 'Message': 'None'}
     except Exception as tst:
         rjson = {'Status': 'Failed', 'Message': 'Exception:' + str(tst)}
     return rjson
コード例 #6
0
 def printx(self):
     logger.debug("====")
     for i in self.datasets:
         logger.debug("=====" + i + "=======")
         logger.debug(PrettyPrint.prettify_json(self.datasets[i]))
         logger.debug("=====================")
     logger.debug("====")
     return self
コード例 #7
0
 def get_swidentity(self):
     if self.sw_inited:
         logger.debug("Already present")
         return self.firmware_json
     self.entity._get_entries(self.firmware_json, self.firmware_enum)
     logger.debug(PrettyPrint.prettify_json(self.firmware_json))
     for obj in self.firmware_json:
         self.installed_firmware[obj] = []
         for entry in self.firmware_json[obj]:
             if 'Status' in entry and entry['Status'] == 'Installed':
                 self.installed_firmware[obj].append(entry)
     return self.firmware_json
コード例 #8
0
ファイル: iDRACJobs.py プロジェクト: akaushik-vm/omsdk
    def job_wait(self,
                 jobid,
                 track_jobid=True,
                 show_progress=False,
                 wait_for=2 * 60 * 60):  # wait for a 2 hours (longgg time)
        if track_jobid:
            self.last_job = jobid
        ret_json = {}
        job_ret = False
        wait_till = time.time() + wait_for
        while True:
            status = self.get_job_status(jobid)
            if not 'Status' in status:
                logger.debug("Invalid Status")
            else:
                logger.debug(PrettyPrint.prettify_json(status))

                pcc = "0"
                msg = ""
                if 'PercentComplete' in status:
                    pcc = status['PercentComplete']
                if 'Message' in status:
                    msg = status['Message']
                if show_progress:
                    logger.debug(
                        "{0} : {1} : Percent Complete: {2} | Message = {3}".
                        format(jobid, status['Status'], pcc, msg))
                if status['Status'] == TypeHelper.resolve(
                        JobStatusEnum.Success):
                    if show_progress:
                        logger.debug("Message:" + status['Message'])
                    job_ret = True
                    ret_json = status
                    break
                elif status['Status'] != TypeHelper.resolve(
                        JobStatusEnum.InProgress):
                    if show_progress:
                        logger.debug("Message:" + status['Message'])
                    job_ret = False
                    ret_json = status
                    break
                else:
                    logger.debug(str(status))
            time.sleep(5)
            if time.time() > wait_till:
                ret_json['Status'] = 'Failed'
                ret_json[
                    'Message'] = 'Job wait did not return for {0} seconds'.format(
                        wait_for)
                break
        ret_json['retval'] = job_ret
        return ret_json
コード例 #9
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
コード例 #10
0
 def _parse_status_obj(self, retval):
     if not 'Status' in retval :
         retval['Status'] = "Invalid"
         retval['Message'] = "<empty result>"
         return (False, 'Invalid', None)
     elif retval['Status'] != 'Success':
         return (False, retval['Status'], None)
     logger.debug(PrettyPrint.prettify_json(retval))
     if retval['Return'] != "JobCreated":
         return (False, retval['Status'], None)
     if not 'Job' in retval or not 'JobId' in retval['Job']:
         logger.debug("Error: Jobid is not found, even though return says jobid")
         return (True, retval['Status'], None)
     jobid = retval['Job']['JobId']
     logger.debug("Job is " + jobid)
     if jobid is None:
         return (True, retval['Status'], None)
     return (True, retval['Status'], jobid)
コード例 #11
0
ファイル: iDRACJobs.py プロジェクト: akaushik-vm/omsdk
    def get_job_status(self, jobid):
        jobs = {}
        jobret = {"Status": TypeHelper.resolve(JobStatusEnum.InProgress)}
        if jobid.startswith('DCIM_OSD'):
            # Poll for OSD Concrete Job
            jobs = self._get_osd_job_details()
        else:
            jobs = self.get_job_details(jobid)
        logger.debug(PrettyPrint.prettify_json(jobs))
        if "Status" in jobs and jobs['Status'] != "Success":
            logger.debug("ERROR: get_job_status failed: " + jobs['Status'])
            logger.debug("ERROR: get_job_status failed: " + jobs['Message'])
            return jobs

        jb = jobs['Data']['Jobs']
        if jb['InstanceID'] != jobid:
            logger.debug("ERROR: Job instance not found")
            return jobs
        if 'JobStatus' in jb:
            jobstatus = jb['JobStatus']
            if jobstatus == 'Completed':
                jobstaten = JobStatusEnum.Success
            elif 'Message' in jb and jb['Message'] and 'completed' in jb[
                    'Message']:
                jobstaten = JobStatusEnum.Success
            elif jobstatus == 'Failed':
                jobstaten = JobStatusEnum.Failed
            elif jobstatus == 'Pending':
                jobstaten = JobStatusEnum.InProgress
            elif jobstatus.endswith('In Progress'):
                jobstaten = JobStatusEnum.InProgress
            elif jobstatus.endswith('Scheduled'):
                jobstaten = JobStatusEnum.InProgress
            elif jobstatus.endswith('Running'):
                jobstaten = JobStatusEnum.InProgress
            elif jobstatus.endswith('Invalid'):
                jobstaten = JobStatusEnum.InProgress
            else:
                jobstaten = JobStatusEnum.InProgress
            jb['Status'] = TypeHelper.resolve(jobstaten)
        return jb
コード例 #12
0
ファイル: ArrayType.py プロジェクト: akaushik-vm/omsdk
 def printx(self):
     print(PrettyPrint.prettify_json(self.__dict__))
コード例 #13
0
ファイル: vd_sample.py プロジェクト: akaushik-vm/omsdk
dprint("Driver SDK", "1. Connect to " + ipaddr)
idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds)
if idrac is None:
    print("Error: Not found a device driver for: " + ipaddr)
    exit()

print("INFO: Connected to " + ipaddr)
dprint("Driver SDK", "2. Configure liason share " + str(liason_share))
idrac.config_mgr.set_liason_share(liason_share)

VDName = 'OS'
dprint("Driver SDK", "3. Delete Virtual Disk" + str(VDName))
msg = idrac.config_mgr.delete_virtual_disk(VDName)
print('delete_virtual_disk(' + VDName + ') = ' + msg['Status'])
logger.info(PrettyPrint.prettify_json(msg))

dprint("Driver SDK", "3. Create Virtual Disk" + str(VDName))
msg = idrac.config_mgr.create_virtual_disk(VDName, 1, 1, RAIDLevelsEnum.RAID_0)
print('create_virtual_disk(' + VDName + ') = ' + msg['Status'])
logger.info(PrettyPrint.prettify_json(msg))

dprint("Driver SDK", "4. Get details of Virtual Disk" + str(VDName))
msg = idrac.config_mgr.get_virtual_disk(VDName)
if not msg:
    print('get_virtual_disk(' + VDName + ') = None')
else:
    print('get_virtual_disk(' + VDName + ') = ')
    print(PrettyPrint.prettify_json(msg))

idrac.disconnect()
コード例 #14
0
ファイル: cmc.py プロジェクト: SpootDev/omsdk
import platform
import json
import time
sys.path.append(os.getcwd())

counter = 1
from omsdk.sdkcreds import UserCredentials, ProtocolCredentialsFactory
from omsdk.sdkprint import PrettyPrint
from omsdk.sdkinfra import sdkinfra
import logging

logger = logging.getLogger(__name__)
#logging.basicConfig(level=logging.DEBUG)

creds = ProtocolCredentialsFactory()
creds.add(UserCredentials("root", "calvin"))
ipaddr = "100.96.25.119"

sd = sdkinfra()
sd.importPath()

cmc = sd.get_driver(sd.driver_enum.CMC, ipaddr, creds)
if cmc is None:
    print("Error: Not found a device driver for: " + ipaddr)
    exit()
else:
    print("Connected to " + ipaddr)

idrac_ips = cmc.get_idrac_ips()
print(PrettyPrint.prettify_json(cmc.get_json_device()["ComputeModule"]))
コード例 #15
0
ファイル: sdkcreds.py プロジェクト: akaushik-vm/omsdk
 def printx(self):
     for cred in self.creds_store:
         logger.debug(cred)
         logger.debug(PrettyPrint.prettify_json(self.creds_store[cred]))
コード例 #16
0
 def printx(self):
     logger.debug(PrettyPrint.prettify_json(self.ctree))
     logger.debug(PrettyPrint.prettify_json(self.ctree_flags))
     logger.debug(PrettyPrint.prettify_json(self.assoc))
コード例 #17
0
ファイル: scp_ops.py プロジェクト: hunter007VN/omsdk
sd.importPath()

t1 = time.time()

dprint("Driver SDK", "1.03 Connect to " + ipaddr)
idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds, protopref)
if idrac is None:
        print ("Error: Not found a device driver for: " + ipaddr)
        exit()
else:
        print("Connected to " + ipaddr)

dprint("Driver SDK", "5.04 Export SCP")
scp_file = myshare.new_file('fact_%ip_%Y%m%d_%H%M%S.xml')
msg = idrac.config_mgr.scp_export(scp_file, method=ExportMethodEnum.Clone)
print(PrettyPrint.prettify_json(msg))

if msg['Status'] == "Success":
    print("Saved to file :" + msg['file'])
else:
    print("Operation Failed with Message :" + msg['Message'])

dprint("Driver SDK", "5.04 Export SCP Async")
scp_file = myshare.new_file('fact_%ip_%Y%m%d_%H%M%S.xml')
msg = idrac.config_mgr.scp_export(scp_file, job_wait=False)
print(PrettyPrint.prettify_json(msg))
if msg['Status'] == 'Success':
        print("Saving to file :" + msg['file'])
        jobid = msg['Job']['JobId']
        retVal = idrac.job_mgr.job_wait(jobid, show_progress=True)
        if msg['Status'] == "Success":
コード例 #18
0
        print("Error: Not found a device driver for: " + ipaddr)
        exit()
    else:
        print("Connected to " + ipaddr)
    idrac.config_mgr.set_liason_share(myshare)

if Passed:
    dprint("Driver SDK", "4.01.1 download catalog.xml.gz from ftp.dell.com")
    print(UpdateManager.update_catalog())
    dprint("Driver SDK", "4.01.2 build cache using idracs/models")
    print(UpdateManager.add_devices(idrac))
    dprint("Driver SDK", "4.01.3 Refresh the existing localstore")
    print(UpdateManager.update_cache())

if Passed:
    print(PrettyPrint.prettify_json(idrac.config_mgr.LCReady))
    print(PrettyPrint.prettify_json(idrac.config_mgr.LCStatus))
    print(PrettyPrint.prettify_json(idrac.config_mgr.ServerStatus))
    print(PrettyPrint.prettify_json(idrac.config_mgr.lc_status()))

if Passed:
    print(
        PrettyPrint.prettify_json(
            idrac.job_mgr.delete_job(jobid="JID_966529634181")))

if Passed:
    print(PrettyPrint.prettify_json(idrac.job_mgr.delete_all_jobs()))

if Passed:
    #print(PrettyPrint.prettify_json(idrac.license_mgr._get_license_json()))
    print("============= LicenseDevice FQDDs ======")
コード例 #19
0
        if action == 1:
            idrac.config_mgr._sysconfig.iDRAC.EmailAlert.new(
                Address_EmailAlert=address, CustomMsg_EmailAlert=address)
        else:
            idrac.config_mgr._sysconfig.iDRAC.EmailAlert.remove(
                Address_EmailAlert=address)
    except Exception as ex:
        print(str(ex))
    idrac.config_mgr.apply_changes()
    idrac.config_mgr._sysconfig.iDRAC.EmailAlert._index_helper.printx()
    print("=============")


print("Original Data")
print(
    PrettyPrint.prettify_json(
        idrac.config_mgr._sysconfig.iDRAC.EmailAlert.Json))
print("======")
emailtest(idrac, "*****@*****.**", "added")
emailtest(idrac, "*****@*****.**", "added")
emailtest(idrac, "*****@*****.**", "added")
emailtest(idrac, "*****@*****.**", "deleted", action=2)
emailtest(idrac, "*****@*****.**", "non-existent-delete-no-change", action=2)
emailtest(idrac, "*****@*****.**", "added")
emailtest(idrac, "*****@*****.**", "added")
emailtest(idrac, "*****@*****.**", "should-fail-for-index")
emailtest(idrac, "*****@*****.**", "deleted", action=2)
emailtest(idrac, "*****@*****.**", "deletion-fail", action=2)
emailtest(idrac, "*****@*****.**", "added")
print(
    PrettyPrint.prettify_json(
        idrac.config_mgr._sysconfig.iDRAC.EmailAlert.Json))
コード例 #20
0
ファイル: RAIDHelper.py プロジェクト: akaushik-vm/omsdk
 def load(self, ctree, entity):
     ejson = entity.get_json_device()
     logger.debug(PrettyPrint.prettify_json(ejson))
     self._load_comp('Controller', self, ctree, ejson, entity)
     self.Controller.commit()
     self.inited = True