def deployProject(self, fabric_id): res = {} res['status'] = 'error' session = FabricSession() try: fabric = self._getFabricInfo(session, fabric_id) if fabric and fabric.status == 'ready': fabric.status = 'deploying' session.add(fabric) session.commit() # send message to rabbitmq self._sendDeployMessage(fabric_id) res['status'] = 'success' res['msg'] = 'ok' else : res['status'] = 'error' res['msg'] = 'not_fabric' except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: session.close() return res
def setFabricToReady(self, fabric_id): res = {} res['status'] = 'error' session = FabricSession() try: fabric = self._getFabricInfo(session, fabric_id) if self._getMachineByFabric(fabric_id): if fabric.status == 'edit': fabric.status = 'ready' session.add(fabric) session.commit() res['status'] = 'success' res['msg'] = 'ok' else : res['status'] = 'error' res['msg'] = 'status_error' else : res['status'] = 'error' res['msg'] = 'no_machines' except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: session.close() return res
def addMachine(self, **kwargs): name = kwargs.get('name', None) desc = kwargs.get('desc', None) account = kwargs.get('account', None) password = kwargs.get('password', None) ip = kwargs.get('ip', None) auth_type = kwargs.get('auth_type', 'password') res = {} if not name: res['status'] = 'error' res['msg'] = 'not_name' return res if not desc: res['status'] = 'error' res['msg'] = 'not_desc' return res if not account: res['status'] = 'error' res['msg'] = 'not_account' return res if not password: res['status'] = 'error' res['msg'] = 'not_password' return res if not ip: res['status'] = 'error' res['msg'] = 'not_ip' return res if not auth_type: res['status'] = 'error' res['msg'] = 'no_auth_type' fabric = FabricSession() try: machine = MachineMapping() machine.id = str(uuid.uuid1()) machine.name = name machine.desc = desc machine.auth_type = auth_type machine.ip = ip if auth_type == 'password': machine.account = account machine.password = password if auth_type == 'key': machine.account = None machine.password = None machine.create_time = int(time.time()) fabric.add(machine) fabric.commit() res['status'] = 'success' res['msg'] = 'ok' except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: fabric.close() return res
def addProject(self, **kwargs): name = kwargs.get('name', None) gituser = kwargs.get('gituser', None) gitaddress = kwargs.get('gitaddress', None) localaddress = kwargs.get('localaddress', None) remoteaddress = kwargs.get('remoteaddress', None) deployaddress = kwargs.get('deployaddress', None) desc = kwargs.get('desc', None) create_time = int(time.time()) res = {} if not name : res['status'] = 'error' res['msg'] = 'not_project_name' if not gitaddress: res['status'] = 'error' res['msg'] = 'not_gitaddress' if not localaddress: res['status'] = 'error' res['msg'] = 'not_localaddress' if not remoteaddress: res['status'] = 'error' res['msg'] = 'not_remoteaddress' if not deployaddress: res['status'] = 'error' res['msg'] = 'not_deployaddress' if not gituser: res['status'] = 'error' res['msg'] = 'not_gituser' fabric = FabricSession() try: project = ProjectMapping() project.id = str( uuid.uuid1() ) project.name = name project.gituser = gituser project.gitaddress = gitaddress project.localaddress = localaddress project.remoteaddress = remoteaddress project.deployaddress = deployaddress project.desc = desc project.create_time = create_time fabric.add( project ) fabric.commit() res['status'] = 'success' res['msg'] = 'ok' self._sendCloneMessage( project.id ) except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: fabric.close() return res
def delProjects(self, projects=None): res = {} if not projects: res['status'] = 'error' res['msg'] = 'not_projects' fabric = FabricSession() try: print(projects) fabric.query( ProjectMapping ).filter( ProjectMapping.id.in_(projects) ).delete(synchronize_session=False) fabric.commit() res['status'] = 'success' res['msg'] = 'ok' except Exception as e : res['status'] = 'exception' res['msg'] = str(e) finally: fabric.close() return res
def setFabricToCalcel(self, fabric_id): res = {} res['status'] = 'error' session = FabricSession() try: fabric = self._getFabricInfo(session, fabric_id) if fabric: fabric.status = 'cancel' self.setFabricRelationStatus(fabric_id) session.add(fabric) session.commit() res['status'] = 'success' res['msg'] = 'ok' else: res['status'] = 'error' res['msg'] = 'not_fabric' except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: session.close() return res