Exemplo n.º 1
0
def ucsm_config_backup(ucsm_ip, user, password):
    handle = UcsHandle(ucsm_ip, user, password)
    handle.login()
    backup_ucs(handle,
               backup_type="config-all",
               file_dir=r"C:\py\config",
               file_name=ucsm_ip + "_" + "config-all.xml")
    handle.logout()
Exemplo n.º 2
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()
    backup_ucs(handle, backup_type="config-all", file_dir="./", file_name=filename)
    handle.logout()
Exemplo n.º 3
0
def get_the_backup():
    global local_filename, ucs_name, handle, backup_selection, local_dcty
    try:
        print('*** Filename: ' + local_filename + '\n')
        print('*** Requesting backup from UCS Domain ' + ucs_name + '\n')
        backup_ucs(handle, backup_selection, local_dcty, local_filename)
        print('\n*** BACKUP COMPLETE\n')
    except:
        print('*** ERROR - Unable to complete backup request')
Exemplo n.º 4
0
def backup_ucsm():
    # Create a connection handle
    handle = UcsHandle("r143b-ucs.rich.ciscolabs.com", "admin", "N3ptune1")

    # Login to the server
    handle.login()

    backup_ucs(handle,
               backup_type="config-logical",
               file_dir=backup_dir,
               file_name=backup_filename)

    # Logout from the server
    handle.logout()
Exemplo n.º 5
0
def ucsmbackup(handle):
    backup_dir = "/home/user/backup"
    full_state_backup_filename = "full-state_config_backup.xml"
    backup_ucs(handle,
               backup_type="full-state",
               file_dir=backup_dir,
               file_name=full_state_backup_filename)

    config_all_backup_filename = "config-all_config_backup,xml"
    backup_ucs(handle,
               backup_type="config-all",
               file_dir=backup_dir,
               file_name=config_all_backup_filename,
               preserve_pooled_values=True)
Exemplo n.º 6
0
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-i", "--ip", help="IP Address")
parser.add_argument("-u", "--username", help="Username")
parser.add_argument("-p", "--password", help="Password")

args = parser.parse_args()

#Log into UCS using UcsHandle
handle = UcsHandle(ip=args.ip, username=args.username, password=args.password)
handle.login()

#Start backup scripts here
backup_dir = 'c:\ucsbackup'
full_state_backup_filename = "full-state_config_backup.xml"
backup_ucs(handle,
           backup_type = "full-state",
           file_dir = backup_dir,
           file_name = full_state_backup_filename)

config_all_backup_filename = "config-all_config_backup.xml"
backup_ucs(handle,
           backup_type = "config-all",
           file_dir = backup_dir,
           file_name = config_all_backup_filename,
           preserve_pooled_values = True)

#Log out of UCS
handle.logout()
Exemplo n.º 7
0
def main():
    """
    Main routine to be executed
    """
    # Get the CLI arguements
    args = get_parser().parse_args()
    section_platform = args.platform

    parser = SafeConfigParser()

    # Since when the script executes, it is difficult to assume the relative path - as depends on where you run your Python script from.
    # Especially if calling it via absolute path and you're not in the actual directory
    # Hence, use the following to effectively obtain the config file as if it were '../my_credentials.ini'
    parent_configFilePath = os.path.join(
        os.path.abspath(os.path.dirname(__file__)), '..', MY_CONFIG_FILE)
    local_configFilePath = os.path.join(
        os.path.abspath(os.path.dirname(__file__)), '.', MY_CONFIG_FILE)

    # Check if MY_CONFIG_FILE is in the current local directory, otherwise check the parent directory. If missing in both, then fail
    if os.path.exists(local_configFilePath):
        # Use the local directory
        # print ("Found in local directory")
        configFilePath = local_configFilePath
    elif os.path.exists(parent_configFilePath):
        # Use the parent directory
        # print ("Found in parent directory")
        configFilePath = parent_configFilePath
    else:
        # Missing completely. Fail
        print(
            "Unable to locate your Config File: {}. Please ensure that you have it created and available"
            .format(MY_CONFIG_FILE))
        print("Not found in the local directory: {}".format(
            local_configFilePath))
        print("Not found in the Parent directory: {}".format(
            parent_configFilePath))
        exit(0)

    if args.debug:
        print("Config File: {}".format(configFilePath))

    # Attempt to read the configuration file
    try:
        result = parser.read(configFilePath)
    except Exception as e:
        print(str(e))
        exit(0)

    if section_platform not in parser.sections():
        print(
            "Please ensure you select a Platform that you have defined in your {} file"
            .format(MY_CONFIG_FILE))
        print("Current Platforms defined: " + str(parser.sections()))
        exit(0)
    else:
        try:
            UCSM = parser.get(section_platform, 'UCSM')
            USER = parser.get(section_platform, 'USER')
            PASS = parser.get(section_platform, 'PASS')
        except Exception as e:
            print(str(e), ' could not read configuration file')

            for section_name in parser.sections():
                print 'Section:', section_name
                print '  Options:', parser.options(section_name)
                if args.debug:
                    for name, value in parser.items(section_name):
                        print '  %s = %s' % (name, value)
                print
            # Exit due to exception
            exit(0)

    # Rest of normal flow would take place here
    handle = UcsHandle(UCSM, USER, PASS, secure=False)
    handle.login()

    # Obtain current date and time
    now = datetime.datetime.now()
    timestamp = now.strftime("%d_%b_%Y_%H_%M")

    # Path to location where you want the UCS Backup to be saved
    backup_dir = "./ucsBackup"
    # NOTE: There is a 128 char limit for the full path of backup_dir + backup_filename.
    # If exceeded, ucsmsdk will throw a vague validation exception error
    '''
    'full-state' system backup creates a snapshot of the entire system and places it in a binary file. In the event of a disaster, the file generated from this backup can be used to perform a full restoration of the system using
    the same or a different fabric interconnect. You can restore from this file, but you cannot import the file using the Cisco UCS Manager GUI.

    'config-all' backup creates an XML file that includes all the system and logical configuration settings. You can use these to import the configuration settings to the original or different Cisco UCS domain. This backup
    cannot be used for a full-state system restoration operation, and it does not include passwords for locally authenticated users.

    'config-logical' backup creates an XML file that includes all logical configuration settings such as Cisco UCS service profiles, VLANs, VSANs, pools, and policies.

    'config-system' backup creates an XML file that includes all system configuration settings such as user names, roles, and locales.
    '''
    # BACKUP Types. Simply uncomment the type that you are interested in

    #backup_type = "full-state"   # Is currently timing out. Need to fix
    backup_type = "config-all"
    #backup_type = "config-logical"
    #backup_type = "config-system"

    # Ensure the right backup extension is automatically used
    if backup_type == "full-state":
        backup_extension = ".tar.gz"
    else:
        backup_extension = ".xml"

    # Auto generated filename, including UCSM Name, Backup, Timestamp and the correct extension
    backup_filename = handle.ucs + "_" + backup_type + "_" + timestamp + backup_extension

    # Perform the actual backup
    backup_ucs(handle,
               backup_type,
               backup_dir,
               backup_filename,
               timeout_in_sec=600,
               preserve_pooled_values=True)

    handle.logout()
Exemplo n.º 8
0
def _test_ucs_backup(handle, file_dir, file_name, backup_type):
    backup_ucs(handle,
               backup_type=backup_type,
               file_dir=file_dir,
               file_name=file_name)
Exemplo n.º 9
0
    if find_ext > -1:
        # WAS THE INCLUDED EXTENSION .XML?
        if local_filename[len(local_filename) -
                          4:len(local_filename)].lower() != ".xml":
            print('***ERROR - FILENAME MUST END IN .XML\n\n\n')
            exit()

    #IF THERE'S NO EXTENSION, ADD .XML
    else:
        local_filename = local_filename + ".xml"

# ----------------------------------------------
# ----------------------------------------------
# GOOD TO GO - LETS GET A BACKUP
# ----------------------------------------------
# ----------------------------------------------

try:
    print('*** Filename: ' + local_filename + '\n')
    print('*** Requesting backup from UCS Domain ' + ucs_name + '\n')
    backup_ucs(handle, backup_selection, local_dcty, local_filename)
    print('\n*** BACKUP COMPLETE\n')
except:
    print('*** ERROR - Unable to complete backup request')

# --------------------------------
# LOGOUT OF THE UCS DOMAIN
# --------------------------------
handle.logout
print("LOGGED OUT OF " + ucs_name.upper() + '\n\n\n')
Exemplo n.º 10
0
                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:
            backup_name = sys.argv[2]
        else:
            backup_name = 'backup.xml'
        print "Backing up UCSM settings to %s" % backup_name

        backup_ucs(handle,
                   backup_type="config-all",
                   file_dir="./",
                   file_name=backup_name)
        handle.logout()

    except Exception, err:
        print "Exception:", str(err)
        import traceback, sys
        print '-' * 60
        traceback.print_exc(file=sys.stdout)
        print '-' * 60
Exemplo n.º 11
0
from ucsmsdk.utils.ucsbackup import backup_ucs
from ucsmsdk.ucshandle import UcsHandle

backup_dir = "/home/cisco/backup_ucs"
backup_filename = "config_backup.xml"

handle = UcsHandle("10.10.86.191", "admin", "cisco123")
handle.login()
backup_ucs(handle,
           backup_type="config-logical",
           file_dir=backup_dir,
           file_name=backup_filename)
handle.commit()
handle.logout()
Exemplo n.º 12
0
'config-logical' backup creates an XML file that includes all logical configuration settings such as Cisco UCS service profiles, VLANs, VSANs, pools, and policies.

'config-system' backup creates an XML file that includes all system configuration settings such as user names, roles, and locales.
'''
# BACKUP Types. Simply uncomment the type that you are interested in

#backup_type = "full-state"   # Is currently timing out. Need to fix
backup_type = "config-all"
#backup_type = "config-logical"
#backup_type = "config-system"

# Ensure the right backup extension is automatically used
if backup_type == "full-state":
    backup_extension = ".tar.gz"
else:
    backup_extension = ".xml"

# Auto generated filename, including UCSM Name, Backup, Timestamp and the correct extension
backup_filename = handle.ucs + "_" + backup_type + "_" + timestamp + backup_extension

# Perform the actual backup
backup_ucs(handle,
           backup_type,
           backup_dir,
           backup_filename,
           timeout_in_sec=600,
           preserve_pooled_values=True)

handle.logout()