def get_server_status_ucsm(sg, wanted): """ Get the UCS Manager Server status """ try: handle = UCSUtil.ucs_login(sg) except KubamError as e: UCSUtil.ucs_logout(handle) return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST try: all_servers = UCSServer.list_servers(handle) if not wanted == "all": all_servers = UCSUtil.servers_to_objects(all_servers, wanted) # put in dn name format status = {} for i in all_servers: status[i['dn']] = i out = UCSUtil.dn_hash_to_out(status) except KubamError as e: UCSUtil.ucs_logout(handle) return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST UCSUtil.ucs_logout(handle) return jsonify({"servers": out}), Const.HTTP_OK
def list_ucsm(handle, wanted): """ Get all the drives of the servers listed and print them out. and stuff. """ try: all_servers = UCSServer.list_servers(handle) ucs_servers = UCSUtil.servers_to_objects(all_servers, wanted) except KubamError as e: UCSUtil.ucs_logout(handle) return {"error": str(e)}, Const.HTTP_BAD_REQUEST disks = {} from ucsmsdk.mometa.storage.StorageLocalDisk import StorageLocalDisk for i in ucs_servers: try: server_disks = UCSServer.list_disks(handle, i) disks[i['dn']] = [] for d in server_disks: # d.__dict__ flattens the object to a dictionary. kv = d.__dict__ kv = dict((key, value) for key, value in kv.iteritems() if not key.startswith('_') ) disks[i['dn']].append( kv) except KubamError as e: UCSUtil.ucs_logout(handle) return {"error": str(e)}, Const.HTTP_BAD_REQUEST out = UCSUtil.dn_hash_to_out(disks) UCSUtil.ucs_logout(handle) return out, Const.HTTP_OK
def ucs_fsm(sg, wanted): """ Pass in the server group to get the fsm of the servers """ try: handle = UCSUtil.ucs_login(sg) except KubamError as e: return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST try: all_servers = UCSServer.list_servers(handle) if not wanted == "all": all_servers = UCSUtil.servers_to_objects(all_servers, wanted) # put in dn name format status = {} for i in all_servers: status[i['dn']] = UCSMonitor.get_fsm(handle, i) out = UCSUtil.dn_hash_to_out(status) except KubamError as e: UCSUtil.ucs_logout(handle) return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST UCSUtil.ucs_logout(handle) return jsonify({"servers": out}), Const.HTTP_OK