def main(): src_ucs_params = get_parameters('Source', default_src_ip, default_username) dst_ucs_params = get_parameters('Destination', default_dst_ip, default_username) src_handle = ucshandle.UcsHandle(src_ucs_params['ip'], src_ucs_params['user'], src_ucs_params['password'], secure=True) dst_handle = ucshandle.UcsHandle(dst_ucs_params['ip'], dst_ucs_params['user'], dst_ucs_params['password'], secure=True) src_handle.login() dst_handle.login() src_vlans = get_vlans(src_handle) dst_vlans = get_vlans(dst_handle) diff_vlans = comparesyncmo.compare_ucs_mo(dst_vlans, src_vlans) if diff_vlans: print 'Following VLANs will be synced:\n' comparesyncmo.write_mo_diff(diff_vlans) print '\nSyncing VLANs...\n' comparesyncmo.sync_ucs_mo(dst_handle, diff_vlans, delete_not_present=True) else: print 'VLANs are already in sync.' src_handle.logout() dst_handle.logout()
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
def main(): handle = ucshandle.UcsHandle(IP, username=USERNAME, password=PASSWORD) handle.login() network = mynet.Network(DN, handle) network.get_vnic_templates()
def main(): handle = ucshandle.UcsHandle(IP, username=USERNAME, password=PASSWORD) handle.login() myboot = boot.Bootpolicy(DN, handle) # Creating boot policy (uefi mode) myboot.boot_policy_sp()
def ucsm_connection(ucsm_ip, username, password): """ this function will connect to ucsm IP and return handle """ handle = ucshandle.UcsHandle(ucsm_ip.strip(), username.strip(), password.strip()) return handle
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()
def main(): ucs_params = get_parameters() handle = ucshandle.UcsHandle(ucs_params['ip'], ucs_params['user'], ucs_params['password'], secure=True) handle.login() vlans = get_vlans(handle) write_vlans_to_csv(ucs_params['filename'], vlans) handle.logout()
def main(): handle = ucshandle.UcsHandle(IP, username=USERNAME, password=PASSWORD) handle.login() blade = firm.BladeServer( handle, "org-root/org-Finance", version="2.2(6g)", policy_name="onecloudfirmware" ) # Provide the version number that the blade should be upgrade. blade.discover_blade_server()
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!')
def launch(hostname, username, password): if not _check_host_reachable(hostname): sys.exit("UCSM is unreachable check network/config") # Login to the server handle = ucshandle.UcsHandle(hostname, username, password) try: handle.login() except URLError: sys.exit("Error logging into UCSM. Check hostname/ip is correct.") except ucsexception.UcsException: sys.exit("Authentication error. Check username/password.") # launch the UCSM GUI ucsguilaunch.ucs_gui_launch(handle)
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!')
import sys import json 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
def check_fault(handle, ucs_obj): faults = handle.query_classid("FaultInst") fault_obj = [] for fault in faults: for obj in ucs_obj: if re.search(obj.dn, fault.dn) and (fault.severity == 'critical' or fault.severity == 'major'): fault_obj.append(fault) return fault_obj os.system("clear") ucs_details = get_ucs_params() if ucs_details: print("Connecting UCS as user '%s' and IP address '%s'" % (ucs_details[1], ucs_details[0])) handle = ucshandle.UcsHandle(ucs_details[0], ucs_details[1], ucs_details[2]) handle.login() else: print("Cannot reach the UCS server specified, please try again!!!") exit() racks = handle.query_classid("ComputeRackUnit") blades = handle.query_classid("ComputeBlade") all_servers = blades + racks assoc_servers = [] loop_count = 0 print("-----------------------------------------") for server in all_servers: if server.association == "associated":
from ucsmsdk import ucshandle import re import time # prepare arguments for ucsm ip address, user name, and password to access UCSM parser = argparse.ArgumentParser() parser.add_argument("ucsm_ip") parser.add_argument("ucsm_user") parser.add_argument("ucsm_password") args = parser.parse_args() handle = ucshandle.UcsHandle(args.ucsm_ip, args.ucsm_user, args.ucsm_password) handle.login() fault_filter = '(severity, "critical|major")' blade_filter = '(association, "associated")' list_of_blades = handle.query_classid("ComputeBlade", filter_str=blade_filter) list_of_racks = handle.query_classid("ComputeRackUnit", filter_str=blade_filter) handle.logout() fault_ctr = 0 print("Started fault monitor for blade and rack servers on ucsm %s" % args.ucsm_ip) while not fault_ctr: handle.login() list_of_faults = handle.query_classid("FaultInst", filter_str=fault_filter) for fault in list_of_faults: for server in (list_of_blades + list_of_racks): if re.search(server.dn, fault.dn): fault_ctr+=1