def delete(self, application_name, pod_name): if not acl.check_acl('', __name__, 'd'): LOG.warning('DELETE pod<{}> of application<{}> is rejected'.format( pod_name, application_name)) return make_status_response(403, 'Access denied') try: kube_client.DeletePods(pod_name, namespace=application_name) except KubernetesError, e: LOG.error("failed to delete pod <%s> of application <%s>" % (pod_name, application_name)) return make_status_response(404, e.message)
def delete(self, application_name): if not acl.check_acl('', __name__, 'd'): LOG.warning( 'DELETE application<{}> is rejected'.format(application_name)) return make_status_response(403, 'Access denied') LOG.info('Deleting application <%s>' % (application_name)) try: heat_client.delete_stack(application_name) except HTTPNotFound, e: LOG.warning(e) return make_status_response(404, str(e))
class ApplicationList(Resource): def is_heat_template_valid(self, template): ''' Check if a given template is valid or not. Currently it only checkes if namespace of all components are the same. ''' return True def get(self): LOG.info('get ApplicationList') is_summary = False if 'summary' in request.args and request.args['summary'].upper( ) == 'Y': is_summary = True app_json_list = [] try: names = get_application_name_list() for name in names: app_json_list.append( get_application(name, is_summary).dump_as_dict()) except Exception as e: LOG.error(e) return make_status_response(500, 'Internal error') response_json = {'kind': 'ApplicationList', 'items': app_json_list} response = flask.make_response(json.dumps(response_json)) response.headers['Access-Control-Allow-Origin'] = '*' return response def post(self): ''' create an application ''' template = request.get_json() if template is None: return make_status_response(400, 'Bad application template') namespace = None try: namespace = self.get_namespace_from_template(template) except BadAppTemplate as e: LOG.warning(e.message) return make_status_response(400, e.message) except Exception as e: LOG.warning(e.message) return make_status_response(400, 'Bad application template') finally: temp_file = dump_app_json_into_file(namespace, json.dumps(template, indent=2)) LOG.info('dump template into ' + temp_file) try: # ops platform may attach a field 'token' template.pop('token') except: pass LOG.info("Creating application <%s>" % (namespace)) stack = None try: stack = heat_client.get_stack(namespace) except HTTPNotFound: # The stack does not exist pass except Exception, e: return make_status_response(500, 'Internal error') if stack is not None: if not acl.check_acl('', 'Application', 'u'): LOG.warning( 'UPDATE application<{}> is rejected'.format(namespace)) make_status_response(403, 'Access denied') elif stack.status != 'COMPLETE' and stack.status != 'FAILED': LOG.warning( 'UPDATE application <{}> is rejected'.format(namespace)) return make_status_response( 403, 'UPDATE application <{}> is rejected because its status is {}_{}' .format(namespace, stack.action, stack.status)) try: heat_client.update_stack(namespace, template) except Exception as e: LOG.error( 'Failed to update stack <{}>. Error message is: {}'.format( namespace, str(e))) message = '' if 'CircularDependencyException' in str(e): message = 'found Circulard Dependency' return make_status_response(400, message) else: try: heat_client.create_stack(namespace, template) except Exception as e: LOG.error( 'Failed to create stack <{}>. Error message is: {}'.format( namespace, str(e))) message = '' if 'CircularDependencyException' in str(e): message = 'found Circulard Dependency' return make_status_response(400, message) return make_status_response(200)