def __persistConnection(self, direction, headers=dict()): headers['persistent-connection'] = direction #message body is actually irrellevant and is not read on the other # side. #we just need to conform to the http protocol fields = [] fields.append(Input('cmd', "persist-connection")) #sending along the connection parameters for this server conf = ServerConf() connectionParams = dict() connectionParams['serverId'] = conf.getServerId() connectionParams['hostname'] = conf.getHostName() connectionParams['fqdn'] = conf.getFqdn() connectionParams['client_secure_port'] = conf\ .getClientSecurePort() connectionParams['server_secure_port'] = conf\ .getServerSecurePort() input2 = Input( 'connectionParams', json.dumps(connectionParams, default=json_serializer.toJson, indent=4)) # a json structure that needs to be dumped fields.append(input2) response = self.putRequest( ServerRequest.prepareRequest(fields, [], headers)) return response
def addNodeAccepted(self): conf = ServerConf() inf = open(conf.getCACertFile(), "r") key = inf.read() #only sending fqdn the requesting should already know the unqualified # hostname node = NodeConnectRequest(conf.getServerId(), conf.getClientSecurePort(), conf.getServerSecurePort(), key, conf.getFqdn(), None) cmdstring = 'node-connection-accepted' fields = [] input = Input('cmd', cmdstring) input2 = Input( 'connectRequest', json.dumps(node, default=json_serializer.toJson, indent=4)) fields.append(input) fields.append(input2) fields.append(Input('version', "1")) # this goes over client secure port , and we don't want the server to use # cookies response = self.postRequest(ServerRequest.prepareRequest(fields), require_certificate_authentication=False, disable_cookies=True) return response
def sendAddNodeRequest(self, host): """ """ conf = ServerConf() cmdstring = 'connect-server-request' fields = [] input = Input('cmd', cmdstring) inf = open(conf.getCACertFile(), "r") key = inf.read() nodeConnectRequest = NodeConnectRequest(conf.getServerId(), conf.getClientSecurePort(), conf.getServerSecurePort(), key, conf.getFqdn(), conf.getHostName()) input2 = Input( 'nodeConnectRequest', json.dumps(nodeConnectRequest, default=json_serializer.toJson, indent=4)) input3 = Input('unqalifiedDomainName', host) fields.append(input) fields.append(input2) fields.append(input3) fields.append(Input('version', "1")) # this goes over the client Secure Port, and we don't want the server to use # cookies response = self.postRequest(ServerRequest.prepareRequest(fields), require_certificate_authentication=False, disable_cookies=True) return response
def projectsRequest(self): """List all projects""" cmdstring = "projects" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def listModules(self): cmdString = "list-modules" fields = [] input = Input('cmd', cmdString) fields.append(input) fields.append(Input('version', "1")) msg = ServerRequest.prepareRequest(fields, []) return self.postRequest(msg)
def projectRollbackRequest(self, project): """Cancel a series of previously scheduled set&connect requests.""" cmdstring = "project-rollback" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def projectGetDefaultRequest(self): """Get the default project project name""" cmdstring = "project-get-default" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def projectStartRequest(self, name): """Start a new empty project """ cmdstring = "project-start" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) fields.append(Input('name', name)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def saveStateRequest(self): """Tell the server to save its state now.""" cmdstring = "save-state" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def readConfRequest(self): """Tell the server to re-read its configuration.""" cmdstring = "readconf" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def revokeNode(self, serverId): cmdString = "revoke-node" fields = [] input = Input('cmd', cmdString) fields.append(input) fields.append(Input('version', "1")) fields.append(Input('serverId', serverId)) msg = ServerRequest.prepareRequest(fields, []) return self.postRequest(msg)
def grantAccess(self, user): cmdstring = "grant-access" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('name', user)) msg = ServerRequest.prepareRequest(fields, []) response = self.postRequest(msg) return response
def projectCommitRequest(self, project): """Commit a series of previously scheduled set&connect requests, atomically.""" cmdstring = "project-commit" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def deleteUser(self, user): cmdstring = "delete-user" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('user', user)) msg = ServerRequest.prepareRequest(fields, []) response = self.postRequest(msg) return response
def stopRequest(self): cmdstring = "stop" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) #response= self.putRequest(ServerRequest.prepareRequest(fields, [])) return response
def serverInfo(self): cmdstring = 'server-info' fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) msg = ServerRequest.prepareRequest(fields, []) response = self.postRequest(msg) return response
def projectSaveRequest(self, project): """Get a data item from a project.""" cmdstring = "project-save" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) #if project is not None: fields.append(Input('project', project)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def grantNodeConnection(self, serverId): cmdString = "grant-node-connection" input = Input('cmd', cmdString) fields = [] fields.append(input) fields.append(Input('version', "1")) fields.append(Input('serverId', serverId)) msg = ServerRequest.prepareRequest(fields, []) return self.postRequest(msg)
def grantAllNodeConnections(self): cmdString = "grant-all-node-connections" input = Input('cmd', cmdString) fields = [] fields.append(input) fields.append(Input('version', "1")) msg = ServerRequest.prepareRequest(fields, []) return self.postRequest(msg)
def projectDebugRequest(self, project, item): """Get debug info for project items""" cmdstring = "project-debug" fields = [] fields.append(Input('cmd', cmdstring)) if project is not None: fields.append(Input('project', project)) fields.append(Input('item', item)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def projectInfoRequest(self, project, item): """List descriptions of project items""" cmdstring = "project-info" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) if project is not None: fields.append(Input('project', project)) fields.append(Input('item', item)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def networkTopology(self): cmdstring = "network-topology-client" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) msg = ServerRequest.prepareRequest(fields, []) response = self.postRequest(msg) return response
def addUser(self, user, password): cmdstring = "add-user" fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('user', user)) fields.append(Input('password', password)) msg = ServerRequest.prepareRequest(fields, []) response = self.postRequest(msg) return response
def projectImportRequest(self, project, module): """Import a module in a network""" cmdstring = "project-import" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) if project is not None: fields.append(Input('project', project)) fields.append(Input('module', module)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def projectHoldRequest(self, project, item): """List all projects""" cmdstring = "project-deactivate" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) if project is not None: fields.append(Input('project', project)) fields.append(Input('item', item)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def statusRequest(self, project): """Fetches an aggregated general information about the server and and its projects. The argument project is optional""" cmdstring = "status" fields = [] fields.append(Input('cmd', cmdstring)) if project is not None: fields.append(Input('project', project)) fields.append(Input('version', "1")) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def projectDeleteRequest(self, project, deleteDir): """Delete a project and optionally also its directory """ cmdstring = "project-delete" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) fields.append(Input('project', project)) if deleteDir: fields.append(Input('delete-dir', 1)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def workerRequest(self, workerID, archdata): cmdstring='worker-ready' fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) fields.append(Input('worker', archdata)) fields.append(Input('worker-id', workerID)) headers = dict() response= self.putRequest(ServerRequest.prepareRequest(fields, [], headers)) return response
def projectGraphRequest(self, project, item): """Graph item's network in a project""" cmdstring = "project-graph" fields = [] fields.append(Input('cmd', cmdstring)) fields.append(Input('version', "1")) if project is not None: fields.append(Input('project', project)) fields.append(Input('item', item)) response = self.postRequest(ServerRequest.prepareRequest(fields, [])) return response
def pingServer(self, serverId): cmdstring = 'ping' fields = [] input = Input('cmd', cmdstring) fields.append(input) fields.append(Input('version', "1")) headers = dict() if serverId != None: headers['server-id'] = serverId msg = ServerRequest.prepareRequest(fields, [], headers) response = self.putRequest(msg) return response