Example #1
0
def import_imc_backup(handle, remotehost, remotefile, protocol, username, password, passphrase=None, dump_xml=None):
    """
    Imports backUp.
    This operation will upload the IMC backup taken earlier via GUI or backup_imc operation.
    User can perform an import while the system is up and running.

    - remotehost    specifies the host where username need to download the backup.
    - remotefile    specifies the path on remotehost where username need to download the backup.
    - protocol        specifies the protocol used for transferring the file to remotehost.
    - username        specifies the username credential to login to remotehost.
    - password        specifies the password credential to login to remotehost.
    """
    from ImcMos import MgmtImporter

    dn = CoreUtils.make_dn([CoreUtils.make_rn(NamingId.TOP_SYSTEM), CoreUtils.make_rn(NamingId.MGMT_IMPORTER)])
    mgmt_importer = ManagedObject(NamingId.MGMT_IMPORTER)
    mgmt_importer.dn = dn
    mgmt_importer.AdminState = MgmtImporter.CONST_ADMIN_STATE_ENABLED
    mgmt_importer.Hostname = remotehost
    mgmt_importer.User = username
    mgmt_importer.Pwd = password
    mgmt_importer.RemoteFile = remotefile
    mgmt_importer.Proto = protocol
    mgmt_importer.AdminState = MgmtImporter.CONST_ADMIN_STATE_ENABLED
    mgmt_importer.Status = Status.MODIFIED
    mgmt_importer.Passphrase = passphrase
    
    in_config = ConfigConfig()
    in_config.add_child(mgmt_importer)
    ccm = handle.config_conf_mo(dn=dn, in_config=in_config, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
    if ccm.error_code != 0:
        raise ImcException(ccm.error_code, ccm.error_descr)

    time.sleep(10) #Wait for 10 seconds before start checking.
    status = False
    while True:
        cr_dn = handle.config_resolve_dn(dn, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
        if cr_dn.error_code == 0:
            if cr_dn.OutConfig.get_child_count() > 0:
                for cimc_backup in cr_dn.OutConfig.child:
                    if cimc_backup.AdminState == MgmtImporter.CONST_ADMIN_STATE_DISABLED:
                        if cimc_backup.FsmStageDescr == "Completed successfully":
                            status = True
                        if cimc_backup.FsmStageDescr == "Error":
                            raise ImcValidationException("Failed to import the CIMC configuration file." + "Error Code: " + cimc_backup.FsmRmtInvErrCode + " Error Description: " + cimc_backup.FsmRmtInvErrDescr)
            else:
                raise ImcValidationException("Failed to  import the CIMC configuration file.")
        else:
            raise ImcException(cr_dn.error_code, cr_dn.error_descr)
        if status:
            break

    return ccm.OutConfig.child
Example #2
0
def get_imc_techsupport(handle, remotehost, remotefile, protocol, username, password, timeout_sec=ImcConstant.TIME_OUT_IN_SEC, dump_xml=None):
    """
    Creates and downloads the technical support data of IMC server.

    - remotehost    specifies the host where username need to download the technical support data.
    - remotefile    specifies the path on remotehost where username need to download the technical support data.
    - protocol        specifies the protocol used for transferring the file to remotehost.
    - username        specifies the username credential to login to remotehost.
    - password        specifies the password credential to login to remotehost.
    - timeout_sec     specifies the time in seconds for which method waits for the technical support data file
            to generate else exit.Default is 600 Seconds.
    """
    from ImcMos import MgmtImporter

    if timeout_sec == None or timeout_sec == "" or timeout_sec < 1:
        timeout_sec = ImcConstant.TIME_OUT_IN_SEC
        ImcUtils.write_imc_warning('[Warning]: Inappropriate <timeoutsec>. Chosen default value is 600 Seconds')

    #dn = "sys/rack-unit-1/tech-support"
    dn = CoreUtils.make_dn([CoreUtils.make_rn(NamingId.TOP_SYSTEM), CoreUtils.make_rn(NamingId.COMPUTE_RACK_UNIT, ServerId="1"), CoreUtils.make_rn(NamingId.SYSDEBUG_TECH_SUPPORT_EXPORT)])
    sysdebug_techsupport = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT_EXPORT)
    sysdebug_techsupport.DN = dn
    sysdebug_techsupport.AdminState = MgmtImporter.CONST_ADMIN_STATE_ENABLED
    sysdebug_techsupport.RemoteFile = remotefile
    sysdebug_techsupport.Protocol = protocol
    sysdebug_techsupport.Status = Status.MODIFIED
    sysdebug_techsupport.Hostname = remotehost
    sysdebug_techsupport.User = username
    sysdebug_techsupport.Pwd = password

    in_config = ConfigConfig()
    in_config.add_child(sysdebug_techsupport)
    ccm = handle.config_conf_mo(dn=dn, in_config=in_config, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
    time.sleep(10) #Wait for 10 seconds before start checking.

    #TODO: CHECK THE FIELD fsmStageDescr
    duration = timeout_sec
    poll_interval = ImcConstant.POLL_INTERVAL_IN_SEC
    crd = None
    if ccm.error_code == 0:
        ImcUtils.write_imc_warning('Waiting for the Tech Support file to become available (this may take several minutes).')
        status = False
        while True:
            crd = handle.config_resolve_dn(dn, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
            if crd.error_code == 0:
                if crd.OutConfig.get_child_count() > 0:
                    for tech_support in crd.OutConfig.child:
                        if tech_support.AdminState == MgmtImporter.CONST_ADMIN_STATE_DISABLED: #TODO: replace the hard-coded string after schema change
                            if tech_support.FsmStatus == "success":
                                status = True
                            else:
                                raise ImcValidationException('Failed to create the TechSupport file.' + tech_support.FsmStatus)
                else:
                    raise ImcValidationException('Failed to create the TechSupport file.')
            else:
                raise ImcException(crd.error_code, crd.error_descr)
            if status:
                break
            time.sleep(min(duration, poll_interval))
            duration = max(0, (duration-poll_interval))
            if duration == 0:
                raise ImcValidationException('TechSupport generation in progress but get_imc_techsupport process timed out. Exiting Method get_imc_techsupport')
    else:
        raise ImcException(ccm.error_code, ccm.error_descr)

    return crd.OutConfig.child
Example #3
0
def backup_imc(handle, remotehost, remotefile, protocol, username, password, passphrase=None, timeout_sec=ImcConstant.TIME_OUT_IN_SEC, dump_xml=None):
    """
    Creates and downloads the backup of IMC.

    - remotehost    specifies the host where username need to download the backup.
    - remotefile    specifies the path on remotehost where username need to download the backup.
    - protocol        specifies the protocol used for transferring the file to remotehost.
    - username        specifies the username credential to login to remotehost.
    - password        specifies the password credential to login to remotehost.
    - timeout_sec     specifies the time in seconds for which method waits for the backUp file
                    to generate else exit. Default is 600 Seconds.
    """
    from ImcMos import MgmtBackup

    if timeout_sec == None or timeout_sec == "" or timeout_sec < 1:
        timeout_sec = ImcConstant.TIME_OUT_IN_SEC
        ImcUtils.write_imc_warning('[Warning]: Inappropriate <timeoutsec>. Chosen default value is 600 Seconds')

    #dn = "sys/export-config"
    #dn = ImcUtils.make_dn([ManagedObject(NamingId.TOP_SYSTEM).make_rn(),ManagedObject(NamingId.MGMT_BACKUP).make_rn()])
    dn = CoreUtils.make_dn([CoreUtils.make_rn(NamingId.TOP_SYSTEM), CoreUtils.make_rn(NamingId.MGMT_BACKUP)])

    mgmt_backup = ManagedObject(NamingId.MGMT_BACKUP)

    mgmt_backup.Hostname = remotehost
    mgmt_backup.User = username
    mgmt_backup.Pwd = password
    mgmt_backup.Proto = protocol
    mgmt_backup.RemoteFile = remotefile
    mgmt_backup.dn = dn
    mgmt_backup.AdminState = MgmtBackup.CONST_ADMIN_STATE_ENABLED
    mgmt_backup.Status = Status.MODIFIED
    mgmt_backup.Passphrase = passphrase

    in_config = ConfigConfig()
    in_config.add_child(mgmt_backup)
    response = handle.config_conf_mo(dn, in_config=in_config, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
    if response.error_code != 0:
        raise ImcException(response.error_code, response.error_descr)
        #raise Exception('[Error]: backup_imc [Code]:' + ccm.error_code + ' [Description]:' + ccm.error_descr)

    time.sleep(10) #Wait for 10 seconds before start checking.

    duration = timeout_sec
    poll_interval = ImcConstant.POLL_INTERVAL_IN_SEC

    cr_dn = None
    status = False

    while True:
        cr_dn = handle.config_resolve_dn(dn, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
        if cr_dn.error_code == 0:
            for each_mgmt_dn in cr_dn.OutConfig.child:
                if each_mgmt_dn.AdminState == MgmtBackup.CONST_ADMIN_STATE_DISABLED:
                    if each_mgmt_dn.FsmStageDescr == "Completed successfully":
                        status = True
                    if each_mgmt_dn.FsmStageDescr == "Error":
                        raise ImcValidationException("Failed to export the CIMC configuration file." + "Error Code: " + each_mgmt_dn.FsmRmtInvErrCode + " Error Description: " + each_mgmt_dn.FsmRmtInvErrDescr)

        else:
            raise ImcException(cr_dn.error_code, cr_dn.error_descr)

        if status:
            break

        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration-poll_interval))

        if duration == 0:
            raise ImcValidationException('Backup operation in progress but utility backup_imc timed out. Exiting Method backup_imc')

    return cr_dn.OutConfig.child