def post(self, trigger_id): """Trigger a new event on Solum.""" policy.check('create_trigger', pecan.request.security_context) commit_sha = '' status_url = None collab_url = None try: query = query_dict(pecan.request.query_string) workflow = self._get_workflow(query) body = json.loads(pecan.request.body) if ('sender' in body and 'url' in body['sender'] and 'api.github.com' in body['sender']['url']): action = body.get('action', None) if 'comment' in body: # Process a request for rebuilding commit_sha, collab_url = self._process_request(body) elif 'pull_request' in body: # Process a GitHub pull request commit_sha = body['pull_request']['head']['sha'] else: raise exception.NotImplemented() # An example of Github statuses_url # https://api.github.com/repos/:user/:repo/statuses/{sha} if commit_sha: status_url = body['repository']['statuses_url'].format( sha=commit_sha) else: # Request NOT from a Github repo raise exception.NotImplemented() except Exception as exc: if isinstance(exc, exception.SolumException): raise info_msg = "Expected fields not found in request body." LOG.info(info_msg) raise exception.BadRequest(reason=info_msg) try: # Trigger workflow only on PR create and on rebuild request if action in [ 'created', 'opened', 'edited', 'reopened', 'synchronize', 'closed' ]: handler = app_handler.AppHandler(None) handler.trigger_workflow(trigger_id, commit_sha, status_url, collab_url, workflow=workflow) except exception.ResourceNotFound: LOG.error("Incorrect trigger url.") raise pecan.response.status = 202
def get_du_details(self, ctxt, du_id): du_loc = None du_name = None du_image_backend = cfg.CONF.worker.image_storage if du_image_backend.lower() == 'glance': img = clients.OpenStackClients(ctxt).glance().images.get(du_id) du_loc = img.id du_name = img.name elif du_image_backend.lower() == 'swift': raise exception.NotImplemented() else: LOG.error("Invalid image storage option.") raise exception.ResourceNotFound() return du_loc, du_name
def scale(self, ctxt, assembly_id): # TODO(devkulkarni) Find out scale target by querying the app table # deploy that many number of dus raise exception.NotImplemented()
def post(self): """Create a new application. There are a number of ways to use this method to create a new application. See Section 6.11 of the CAMP v1.1 specification for an explanation of each. Use the Content-Type of request to determine what the client is trying to do. """ if pecan.request.content_type is None: raise exception.UnsupportedMediaType( name=pecan.request.content_type, method='POST') req_content_type = pecan.request.content_type # deploying by reference uses a JSON payload if req_content_type == 'application/json': payload = pecan.request.body if not payload or len(payload) < 1: raise exception.BadRequest(reason='empty request body') try: json_ref_doc = json.loads(payload) except ValueError as excp: raise exception.BadRequest(reason='JSON object is invalid. ' + six.text_type(excp)) if 'plan_uri' in json_ref_doc: plan_uri_str = json_ref_doc['plan_uri'] # figure out if the plan uri is relative or absolute plan_uri = urllib.parse.urlparse(plan_uri_str) uri_path = plan_uri.path if not plan_uri.netloc: # should be something like "../plans/<uuid>" or # "/camp/v1_1/plans/<uuid> (include Solum plans) if (not uri_path.startswith('../plans/') and not uri_path.startswith('../../../v1/plans/') and not uri_path.startswith('/camp/v1_1/plans/') and not uri_path.startswith('/v1/plans/')): msg = 'plan_uri does not reference a plan resource' raise exception.BadRequest(reason=msg) plan_uuid = plan_uri.path.split('/')[-1] else: # We have an absolute URI. Try to figure out if it refers # to a plan on this Solum instance. Note the following code # does not support URI aliases. A request that contains # a 'plan_uri' with a network location that is different # than network location used to make this request but # which, nevertheless, still refers to this Solum instance # will experience a false negative. This code will treat # that plan as if it existed on another CAMP-compliant # server. if plan_uri_str.startswith(pecan.request.host_url): if (not uri_path.startswith('/camp/v1_1/plans/') and not uri_path.startswith('/v1/plans/')): msg = 'plan_uri does not reference a plan resource' raise exception.BadRequest(reason=msg) plan_uuid = plan_uri.path.split('/')[-1] else: # The plan exists on another server. # TODO(gpilz): support references to plans on other # servers raise exception.NotImplemented() # resolve the local plan by its uuid. this will raise a # ResourceNotFound exception if there is no plan with # this uuid phandler = plan_handler.PlanHandler( pecan.request.security_context) plan_obj = phandler.get(plan_uuid) elif 'pdp_uri' in json_ref_doc: # TODO(gpilz): support references to PDPs raise exception.NotImplemented() else: # must have either 'plan_uri' or 'pdp_uri' msg = 'JSON object must contain either plan_uri or pdp_uri' raise exception.BadRequest(reason=msg) else: # TODO(gpilz): support deploying an application by value raise exception.NotImplemented() # at this point we expect to have a reference to a plan database object # for the plan that will be used to create the application ahandler = assembly_handler.AssemblyHandler( pecan.request.security_context) assem_db_obj = ahandler.create_from_plan(plan_obj) assem_model = model.Assembly.from_db_model(assem_db_obj, pecan.request.host_url) pecan.response.status = 201 pecan.response.location = assem_model.uri return wsme_json.tojson(model.Assembly, assem_model)
def get_all(self): """Return all resources, based on the query provided.""" excp = solum_exception.NotImplemented() raise excp
def create(self, data): """Create a new resource.""" excp = solum_exception.NotImplemented() raise excp
def delete(self, id): """Delete a resource.""" excp = solum_exception.NotImplemented() raise excp
def update(self, id, data): """Modify a resource.""" excp = solum_exception.NotImplemented() raise excp
def get(self, id): """Return a resource.""" excp = solum_exception.NotImplemented() raise excp
def error_func(): raise exception.NotImplemented()
def test_not_implemented(self): exc = exception.NotImplemented() self.assertIn("The requested operation is not implemented.", six.text_type(exc)) self.assertEqual(501, exc.code)
def post(self, trigger_id): """Trigger a new event on Solum.""" commit_sha = '' status_url = None collab_url = None workflow = None try: query = query_dict(pecan.request.query_string) if 'workflow' in query: valid_stages = ['unittest', 'build', 'deploy'] workflow = query['workflow'].replace('+', ' ').split(' ') workflow = filter(lambda x: x in valid_stages, workflow) if not workflow: workflow = None body = json.loads(pecan.request.body) if ('sender' in body and 'url' in body['sender'] and 'api.github.com' in body['sender']['url']): if 'comment' in body: # Process a request for rebuilding phrase = body['comment']['body'] commenter = body['comment']['user']['login'] private_repo = body['repository']['private'] # An example of collab_url # https://api.github.com/repos/:user/:repo/collaborators{/collaborator} if not private_repo: # Only verify collaborator for public repos collab_url = ( body['repository']['collaborators_url'].format( **{'/collaborator': '/' + commenter})) if (phrase.strip('. ').lower() != CONF.api.rebuild_phrase.lower()): err_msg = 'Rebuild phrase does not match' raise exception.RequestForbidden(reason=err_msg) else: commit_sha = body['comment']['commit_id'] elif 'pull_request' in body: # Process a GitHub pull request commit_sha = body['pull_request']['head']['sha'] else: raise exception.NotImplemented() # An example of Github statuses_url # https://api.github.com/repos/:user/:repo/statuses/{sha} if commit_sha: status_url = body['repository']['statuses_url'].format( sha=commit_sha) else: # Request NOT from a Github repo raise exception.NotImplemented() except Exception as exc: if isinstance(exc, exception.SolumException): raise info_msg = "Expected fields not found in request body." LOG.info(info_msg) raise exception.BadRequest(reason=info_msg) try: handler = app_handler.AppHandler(None) handler.trigger_workflow(trigger_id, commit_sha, status_url, collab_url, workflow=workflow) except exception.ResourceNotFound as e: LOG.error("Incorrect trigger url.") raise e pecan.response.status = 202