Ejemplo n.º 1
0
def load_ucs_manager_config():
    """
        loads the test configuration into the UCS Manger
        """
    logs.info_1('Loading UCSPE emulator from {0}'.format(
        fit_common.fitcfg()['ucsm_config_file']))

    try:
        handle = ucshandle.UcsHandle(UCSM_IP, UCSM_USER, UCSM_PASS)
        if not handle.login():
            logs.error('Failed to log into UCS Manger!')
            return False
    except Exception as e:
        logs.info_1("error trying to log into UCS Manger!")
        logs.info_1(str(e))
        return False

    # now try to update the UCSPE config, if this fails we can still continue
    try:
        path, file = os.path.split(fit_common.fitcfg()['ucsm_config_file'])
        import_ucs_backup(handle, file_dir=path, file_name=file)
    except Exception as e:
        logs.info_1("error trying to configure UCSPE, continuing to test")
        logs.info_1(str(e))
        # log the error but do not return a failure, we can still run some tests with the default config

    if not handle.logout():
        logs.error('Failed to log out of UCS Manger during exit!')
        return False

    return True
Ejemplo n.º 2
0
def ucsmUpload():
#while(True):

    time.sleep(90)
    os.system(r'echo "Starting UCSM Config Upload Script..."  >> /root/logs/importUcsmBackupA.log')
    try:
        os.system(r'echo "Will Connect to UCSM now..."  >> /root/logs/importUcsmBackupA.log')
        handle=UcsHandle("198.18.134.220","admin","C1sco12345",secure=False)
        handle.login()
        os.system(r'echo "Connected to UCSM, will push config now..."  >> /root/logs/importUcsmBackupA.log')
        import_ucs_backup(handle, file_dir=file_dir, file_name=file_name, merge=True)
        os.system(r'echo "Configuration uploaded. Disconnecting..."  >> /root/logs/importUcsmBackupA.log')
        handle.logout()
        os.system(r' echo "Done" >  /root/logs/ucsmA.status')
        os.system(r'echo "Done"  >> /root/logs/importUcsmBackupA.log')
        return True

    except Exception as e:
        if ("HTTP Error 503" in str(e)):
            errorMessage=str(e)
            os.system(r'echo "Error while pushing the config to UCS.Will restart the services and try again in 90 sec."  >> /root/logs/importUcsmBackupA.log')
            os.system(r' echo ' + errorMessage + ' >> /root/logs/importUcsmBackupA.log')
            os.system(r' curl --data "Submit=Restart UCS Emulator with Current Settings&confirm=yes" http://198.18.134.220:8082/settings/restart/emulator >> /root/logs/importUcsmBackupA.log')
            return 60
        else:
            errorMessage=str(e)
            os.system(r'echo "Error while connecting to UCSM .Will try to connect again in 90 sec."  >> /root/logs/importUcsmBackupA.log')
            #os.system(r' echo ' + errorMessage + ' >> /root/logs/importUcsmBackupA.log')
            return 5
Ejemplo n.º 3
0
def load_ucs_manager_config():
        """
        loads the test configuration into the UCS Manger
        """
        logs.info_1('Loading UCSPE emulator from {0}'.format(fit_common.fitcfg()['ucsm_config_file']))

        try:
            handle = ucshandle.UcsHandle(UCSM_IP, UCSM_USER, UCSM_PASS)
            if not handle.login():
                logs.error('Failed to log into UCS Manger!')
                return False
        except Exception as e:
            logs.info_1("error trying to log into UCS Manger!")
            logs.info_1(str(e))
            return False

        # now try to update the UCSPE config, if this fails we can still continue
        try:
            path, file = os.path.split(fit_common.fitcfg()['ucsm_config_file'])
            import_ucs_backup(handle, file_dir=path, file_name=file)
        except Exception as e:
            logs.info_1("error trying to configure UCSPE, continuing to test")
            logs.info_1(str(e))
            # log the error but do not return a failure, we can still run some tests with the default config

        if not handle.logout():
            logs.error('Failed to log out of UCS Manger during exit!')
            return False

        return True
Ejemplo n.º 4
0
def ucsm_config_import(ucsm_ip, user, password):
    handle = UcsHandle(ucsm_ip, user, password)
    handle.login()
    import_ucs_backup(handle,
                      file_dir=r"C:\py\config",
                      file_name=ucsm_ip + "_" + "config-all.xml")
    handle.logout()
Ejemplo n.º 5
0
def main():
    ucsm_ip = raw_input('Target UCS IP address [{}]: '.format(default_ip)) or default_ip
    ucsm_user = raw_input('UCS user name [{}]: '.format(default_user)) or default_user
    ucsm_password = getpass('UCS password: '******'Filename for backup (in current directory) [{}]: '.format(default_filename)) or default_filename
    handle = ucshandle.UcsHandle(ucsm_ip, ucsm_user, ucsm_password, secure=True)
    handle.login()
    import_ucs_backup(handle, file_dir="./", file_name=filename)
    handle.logout()
Ejemplo n.º 6
0
 def test13_load_ucs_manager_config(self):
     """
     loads the test configuration into the UCS Manger
     """
     handle = ucshandle.UcsHandle(fit_common.fitcfg()['ucsm_ip'], fit_common.fitcfg()['ucsm_user'],
                                  fit_common.fitcfg()['ucsm_pass'])
     self.assertTrue(handle.login(), 'Failed to log in to UCS Manager!')
     path, file = os.path.split(fit_common.fitcfg()['ucsm_config_file'])
     import_ucs_backup(handle, file_dir=path, file_name=file)
     self.assertTrue(handle.logout(), 'Failed to log out from UCS Manager!')
Ejemplo n.º 7
0
    def test13_load_ucs_manager_config(self):
        """
        loads the test configuration into the UCS Manger
        """
        UCSM_USER, UCSM_PASS = get_ucs_cred()
        UCSM_IP = fit_common.fitcfg().get('ucsm_ip')

        handle = ucshandle.UcsHandle(UCSM_IP, UCSM_USER, UCSM_PASS)
        self.assertTrue(handle.login(), 'Failed to log in to UCS Manager!')
        path, file = os.path.split(fit_common.fitcfg()['ucsm_config_file'])
        try:
            import_ucs_backup(handle, file_dir=path, file_name=file)
        except Exception as e:
            log.info_5("error trying to configure UCSPE, continue testing")
            log.info_5(str(e))
        self.assertTrue(handle.logout(), 'Failed to log out from UCS Manager!')
Ejemplo n.º 8
0
from ucsmsdk import ucshandle
from ucsmsdk.utils.ucsbackup import import_ucs_backup

if __name__ == "__main__":
    try:
        if len(sys.argv) < 2:
            print "Usage: %s <JSON settings file> [backup filename]" % sys.argv[0]
            sys.exit(0)
        f = open(sys.argv[1], 'r')
        settings_file = json.load(f)
	is_secure = True
	if settings_file['secure'] == "False":
	    is_secure = False
        handle = ucshandle.UcsHandle(settings_file['ip'], settings_file['user'], settings_file['pw'], secure=is_secure)
	handle.login()
        if len(sys.argv) > 2:
            import_name = sys.argv[2]
        else:
            import_name = 'backup.xml'
	print "Importing UCSM settings from %s" % import_name
        import_ucs_backup(handle, file_dir="./", file_name=import_name)
	handle.logout()

    except Exception, err:
        print "Exception:", str(err)
        import traceback, sys
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60