def main(): global handle parser = argparse.ArgumentParser( description= "Connect to UCS and create Kubernetes Infrastructure. We will create several resources on your UCS domain that will help us install Kubernetes." ) parser.add_argument("user", help='The user account to log into UCS: e.g.: admin') parser.add_argument("password", help='The password to connect to UCS: e.g.: cisco123') parser.add_argument("server", help='UCS Manager: e.g: 192.168.3.1') parser.add_argument('-d', "--delete", help='Deletes kubernetes resources from UCS', action="store_true") parser.add_argument( '-o', "--org", type=str, default='root', help= 'The organization you want these resources created under: e.g: root') args = parser.parse_args() org = args.org # loging handle = UCSSession.login(args.user, args.password, args.server) if handle == "": sys.exit(1) # see what's up with the org. if org == "": org = "org-root" else: # verify org exists. if UCSUtil.query_org(handle, org) == False: UCSUtil.create_org(handle, org) org = "org-root/org-" + org if args.delete == False: UCSNet.createKubeNetworking(handle, org) UCSServer.createKubeServers(handle, org) # destroy the UCS stuff we just created. else: print "Are you sure you want to delete the UCS Kubernetes infrastructure?" print "Running servers will be deleted, no work will be saved or recoverable." print "If this are in production, this could be really bad, and you might lose your job" val = raw_input("If you are really sure, please type: 'yes': ") if val == 'yes': UCSServer.deleteKubeServers(handle, org) UCSNet.deleteKubeNetworking(handle, org) else: print "cool. No harm done." UCSSession.logout(handle)
def create_creds(): if not request.json: return jsonify({'error': 'expected credentials hash'}), 400 credentials = {} credentials['user'] = request.json['credentials']['user'] credentials['password'] = request.json['credentials']['password'] credentials['ip'] = request.json['credentials']['server'] if credentials['ip'] == "": return jsonify({'error': "Please enter a valid UCSM IP address."}), 401 #app.logger.info("starting login attempt to UCS.") h, err = UCSSession.login(credentials['user'], credentials['password'], credentials['ip']) if h == "": return jsonify({'error': err}), 401 # write datafile. YamlDB.update_ucs_creds(KUBAM_CFG, credentials) UCSSession.logout(h) return jsonify({'login': "******"}), 201
class SessionUnitTests(unittest.TestCase): """Tests for `UCSServer.py`.""" handle, err = UCSSession.login("admin", "nbv12345", "172.28.225.163") def test_serverlist(self): msg = UCSSession.ensure_version(self.handle) assert(msg == "") version = UCSSession.get_version(self.handle) assert(version.startswith('3'))
def login(): err, msg, config = YamlDB.open_config(KUBAM_CFG) if err == 0: if "ucsm" in config and "credentials" in config["ucsm"]: creds = config["ucsm"]["credentials"] if "user" in creds and "password" in creds and "ip" in creds: h, msg = UCSSession.login(creds["user"], creds["password"], creds["ip"]) if h != "": return 0, "", h return 1, msg, "" return 1, "error logging in: %s" % msg, ""
class ServerUnitTests(unittest.TestCase): """Tests for `UCSServer.py`.""" handle, err = UCSSession.login("admin", "nbv12345", "172.28.225.163") def test_serverlist(self): servers = UCSServer.list_servers(self.handle) #print servers assert (servers != "") def test_list_blade(self): s = "1/1" blade = UCSServer.list_blade(self.handle, s) #print blade #print blade.oper_state disks = UCSServer.list_disks(self.handle, blade)
def login(): err, msg, config = YamlDB.open_config(KUBAM_CFG) if err == 0: if "ucsm" in config and "credentials" in config["ucsm"]: creds = config["ucsm"]["credentials"] if "user" in creds and "password" in creds and "ip" in creds: h, msg = UCSSession.login(creds["user"], creds["password"], creds["ip"]) if h != "": return 0, "", h return 1, msg, "" else: msg = "kubam.yaml file does not include the user, password, and ip properties to login." err = 1 else: msg = "UCS Credentials have not been entered. Please login to UCS to continue." err = 1 return err, msg, ""
def test_serverlist(self): msg = UCSSession.ensure_version(self.handle) assert(msg == "") version = UCSSession.get_version(self.handle) assert(version.startswith('3'))
def logout(handle): UCSSession.logout(handle)