def _missing_value(self, kwargs): required_value = ['name', 'base_iso', 'type', 'distro', 'version'] for k in required_value: if k not in kwargs.keys(): LOG.info('Missing value %s', k) return True return False
def get(self, name): LOG.info('Get build log request %s', name) try: image_info = self.dbapi.get_build_log_by_name(name) except Exception as e: LOG.error('Get error %s', e.message) return dict(status=500, message=e.message) return dict(status=200, **image_info.__dict__)
def post(self, **body): LOG.info('Get release post request %s', body) try: release_log = self.dbapi.create_release_log(**body) except Exception as e: LOG.error('Get error %s', e.message) return dict(status=500, message=e.message) return dict(status=200, **release_log.__dict__)
def post(self, **kwargs): LOG.info('Get post request %s', kwargs) if self._missing_value(kwargs): return dict(status=400, message='Miss required field') try: guestos_id = self.db_api.create_guestos(kwargs) self._create_project(kwargs.get('name')) self._create_job(kwargs) self._add_webhook(kwargs) except Exception as e: LOG.info('Got error %s', e) return dict(status=500, message=e.message) kwargs['id'] = guestos_id return dict(status=200, **kwargs)
def add_build_log(self, build_log): """ Add build log to database :param kwargs: a dict object example: { "image_name": "ubuntu1604x86_64.qcow2", "os_type": "Linux", "os_distro": "ubuntu" "os_ver": "16.04", "from_iso": "http://releases.ubuntu.com/16.04/ubuntu-16.04.5-server-amd64.iso", "update_contents": "Add cloud-init" } :return: image_uuid: UUID of image :raise: """ if not build_log.get('image_name'): LOG.error("Invalid image name") raise Exception session = sessionmaker(bind=self.engine)() image_uuid = str(uuid.uuid4()) session.add(models.ImageBuildLog( image_uuid=image_uuid, image_name=build_log.get('image_name'), os_type=build_log.get('os_type'), os_distro=build_log.get('os_distro'), os_ver=build_log.get('os_ver'), from_iso=build_log.get('from_iso'), update_contents=build_log.get('update_contents'), build_at=datetime.datetime.now() )) session.commit() session.close() return image_uuid
def add_build_log(self, build_log): """ Add build log to database :param kwargs: a dict object example: { "image_name": "ubuntu1604x86_64_20181128_1.qcow2", "os_name": "ubuntu1604", "update_contents": "Add cloud-init" "get_url": "http://10.110.19.1/images/ubuntu1604/ubuntu1604x86_64_20181128_1.qcow2" } :return: image_uuid: UUID of image :raise: """ if not build_log.get('image_name'): LOG.error("Invalid image name") raise Exception(message='Null image name') image_name = build_log.get('image_name') session = sessionmaker(bind=self.engine)() exist_log = session.query( models.ImageBuildLog).filter_by(image_name=image_name).first() log_id = str(uuid.uuid4()) if not exist_log: session.add( models.ImageBuildLog( id=log_id, image_name=image_name, os_name=build_log.get('os_name'), update_contents=build_log.get('update_contents'), get_url=build_log.get('get_url'), build_at=datetime.datetime.now())) session.commit() session.close() return log_id if not exist_log else exist_log.id
def post(self, **kwargs): LOG.info('New build log received %s', kwargs) try: image_uuid = self.dbapi.add_build_log(kwargs) except Exception as e: LOG.error('Got error %s', e) return dict(status=500, message=e.message) LOG.info('Add build log successfully!') kwargs['id'] = image_uuid return dict(status=200, **kwargs)
def post(self, **kwargs): LOG.info('New test log received %s', kwargs) try: log_id = self.dbapi.create_test_log(kwargs) except Exception as e: LOG.error('Got error %s', e.message) return dict(status=500, message=e.message) if not log_id: LOG.info('Invalid input or unknown error') return dict(status=500, message='Invalid input or unknown error') return dict(status=200, log_id=log_id)
def post(self, **kwargs): LOG.info('New build log received %s', kwargs) image_uuid = None try: image_uuid = self.dbapi.add_build_log(kwargs) except Exception as e: LOG.error('Got error %s', e) return { 'return_value': '1', 'image_name': kwargs.get('image_name'), 'message': e } finally: LOG.info('Add build log successfully!') return { 'return_value': '0', 'image_uuid': image_uuid, 'image_name': kwargs.get('image_name') }