def addMachineToFabric(self, fabric_id, machine_id): res = {} res['status'] = 'error' conn = fabric_engine.connect() try: fabric_info = self.getFabricInfo(fabric_id) if MachineModel().isInProjectByMachine(fabric_info['project_id'], machine_id): if not MachineModel().isInFabricByMachine(fabric_id, machine_id): inst = FabricRelationTB.insert().values( id = str(uuid.uuid1()) , fabric_id = fabric_id , project_id = fabric_info['project_id'], machine_id = machine_id , status = 'not_deploy' , create_time = int(time.time()) ) conn.execute(inst) # update total num upstmt = FabricTB.update().values( total = fabric_info['total'] + 1 ).where( FabricTB.c.id == fabric_id ) conn.execute(upstmt) res['status'] = 'success' res['msg'] = 'ok' else: res['status'] = 'error' res['msg'] = 'already_in_fabric' else : res['status'] = 'error' res['msg'] = 'not_in_project' except Exception as e: res['status'] = 'exception' res['msg'] = str(e) finally: conn.close() return res
def get(self, *args, **kwargs): project_id = self.get_argument('project', default=None) res = MachineModel().getMachines(project_id=project_id) data = res['data'] for x in range(len(data)): if data[x]['auth_type'] == 'key': data[x]['password'] = '******' data[x]['create_time'] = Utils.timeformat(data[x]['create_time']) res['data'] = data self.ajax(res)
def post(self, *args, **kwargs): id = self.get_argument('id', default=None, strip=None) name = self.get_argument('name', default=None, strip=None) account = self.get_argument('account', default=None, strip=None) password = self.get_argument('password', default=None, strip=None) desc = self.get_argument('desc', default=None, strip=None) ip = self.get_argument('ip', default=None, strip=None) auth_type = self.get_argument('auth_type', default=None, strip=None) res = MachineModel().editMachine(id=id, name=name, account=account, password=password, desc=desc, ip=ip, auth_type=auth_type) self.ajax(res)
def get(self, machine_id): res = MachineModel().getMachineInfo(machine_id=machine_id) self.ajax(res)
def get(self, project_id, *args, **kwargs): res = MachineModel().getMachineByProject(project_id) self.ajax(res)
def post(self, *args, **kwargs): machine = self.get_argument('machine', default=None) res = MachineModel().delMachines(machine) self.ajax(res)