def run_module(): """ Run the module """ module = AnsibleModule(argument_spec=dict( hostname=dict(type='str', required=True), username=dict(type='str', default='admin'), password=dict(type='str', required=True, no_log=True), name=dict(type='str'), descr=dict(type='str'), state=dict( type='str', default='present', choices=['present', 'absent']))) from ucsmsdk.ucshandle import UcsHandle from ucsmsdk.mometa.org.OrgOrg import OrgOrg handle = UcsHandle(module.params['hostname'], module.params['username'], module.params['password']) handle.login() ucs_mo = OrgOrg(parent_mo_or_dn='org-root', name=module.params['name'], descr=module.params['descr']) handle.add_mo(ucs_mo, modify_present=True) handle.commit() handle.logout() # TODO: Add delete object code result = dict(changed=True) module.exit_json(**result)
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()
def login(self, username, password, server): # Test if the server reachable s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(2) try: result = s.connect_ex((server, 80)) if result != 0: return None, "{0} is not reachable".format(server) s.close() except socket.error as err: return None, "UCS Login Error: {0} {1}".format( server, err.strerror) handle = UcsHandle(server, username, password) try: handle.login() except UcsException as err: print "Login Error: " + err.error_descr return None, err.error_descr except HTTPError as err: print "Connection Error: Bad UCSM? " + err.reason return None, err.reason except Exception as e: print "Issue logging in. Please check that all parameters are correct" print e return None, "Issue logging in. Please check that all parameters are correct." msg = self.ensure_version(handle) return handle, msg
def login(self): from ucsmsdk.ucshandle import UcsHandle # use_proxy=yes (default) and proxy=None (default) should be using the system defined proxy # use_proxy=yes (default) and proxy=value should use the provided proxy # use_proxy=no (user) should not be using a proxy if self.module.params['use_proxy']: proxy = self.module.params['proxy'] else: # force no proxy to be used. Note that proxy=None in UcsHandle will # use the system proxy so we must set to something else proxy = {} try: handle = UcsHandle(ip=self.module.params['hostname'], username=self.module.params['username'], password=self.module.params['password'], port=self.module.params['port'], secure=self.module.params['use_ssl'], proxy=proxy) handle.login() except Exception as e: self.result['msg'] = str(e) self.module.fail_json(**self.result) self.login_handle = handle
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()
def fullGetTechSupport(ucsm_ip, user, password): print "블레이드 샤시 로그를 수집합니다" print "해당 수집 작업은 5분에서 20분 정도 소요될 예정입니다." handle = UcsHandle(ucsm_ip, user, password) handle.login() get_ucs_tech_support(handle, file_dir="/root/techsupport", file_name=s + 'FI_UCSM.tar', timeout_in_sec=600, remove_from_ucs=True) handle.logout()
def ucs_login(self,ip,username,password): results = {} handle = UcsHandle(ip, username, password) try: handle.login() #mo = handle.query_dn("org-root/boot-policy-ciscotest") #print(mo) results['logged_in'] = True #print("Logged In !!!!") except: results['logged_in'] = False return handle
def authenticate_to_ucs_domain(): global handle handle = UcsHandle(ucs_name, login_name, password) try: print('\n*** Logging in') handle.login() print('*** Successfully Logged in \n') except: print( '*** ERROR - UNABLE TO LOGIN. CHECK CREDENTIALS AND TRY AGAIN.\n\n\n' ) exit()
def get_sp_from_domain(domain): # Create a connection handle handle = UcsHandle(domain['ip'], domain['username'], domain['password']) # Login to the server handle.login() # Get all service profiles query = handle.query_classid(class_id="LsServer") # Logout from the server handle.logout() # Convert them in a list with desired attributes sp_list = [[sp.name, sp.type, sp.assign_state, sp.assoc_state] for sp in query] return sp_list
def main(): 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()
def singleGetTechSupport(ucsm_ip, user, password, chassis, blade): print chassis + '-' + blade + "블레이드 로그를 수집합니다." print "해당 수집 작업은 5분에서 20분 정도 소요될 예정입니다." handle = UcsHandle(ucsm_ip, user, password) handle.login() get_ucs_tech_support(handle, file_dir="/root/techsupport", file_name=s + 'FI_BL' + chassis + '-' + blade + '.tar', chassis_id=chassis, cimc_id=blade, timeout_in_sec=600, remove_from_ucs=True) handle.logout()
def main(): handle = UcsHandle("192.168.254.200", "ucspe", "ucspe", secure=False) handle.login() # Query for existing vlan vlan_100 = handle.query_dn("fabric/lan/net-vlan100") # Setup handle entry to remove vlan handle.remove_mo(vlan_100) # Commit changes back to UCS handle.commit() handle.logout()
def custom_setup(): import ConfigParser import os from ucsmsdk.ucshandle import UcsHandle config = ConfigParser.RawConfigParser() config.read(os.path.join(os.path.dirname(__file__), '..', 'connection', 'connection.cfg')) hostname = config.get(host, "hostname") username = config.get(host, "username") password = config.get(host, "password") handle = UcsHandle(hostname, username, password, port=80) handle.login() return handle
def custom_setup(): try: import ConfigParser except: import configparser as ConfigParser import os from ucsmsdk.ucshandle import UcsHandle config = ConfigParser.RawConfigParser() config.read(os.path.join(os.path.dirname(__file__), '..', 'connection', 'connection.cfg')) hostname = config.get(host, "hostname") username = config.get(host, "username") password = config.get(host, "password") handle = UcsHandle(hostname, username, password) handle.login(auto_refresh=True, force=True) return handle
#!/usr/bin/env python from ucsmsdk.ucshandle import UcsHandle # Create a connection handle handle = UcsHandle("172.xx.xx.xx", "admin", "cisco!098") # Put in the VLANs you want to remove first one, and then the last one. vlan_start = 400 vlan_end = 499 vlan_name_prefix = "vmware_client_" # Login to the server handle.login() for a in range(vlan_start, vlan_end + 1): mydn = vlan_name_prefix + str(a) print "Removing " + (mydn) myfulldn = "fabric/lan/net-" + mydn # Query for an existing Mo sp = handle.query_dn(myfulldn) # Remove the object handle.remove_mo(sp) # and commit the changes (actually happens now) handle.commit() # Logout from the server
def ucs_login(hostname, username, password): from ucsmsdk.ucshandle import UcsHandle handle = UcsHandle(hostname, username, password) handle.login() return handle