Exemple #1
0
def sendemail(request):
    try:
        query = request.GET
        receiver = query.get('email')
        cont = json.loads(request.body)
    except Exception as e:
        return rest_utils.JSONResponse("Receiver or Content is None", 500)
    if receiver is None:
        return rest_utils.JSONResponse("Receiver or Content is None", 500)

    value_list = []
    for key in [
            'alarm_name', 'alarm_resource', 'alarm_meter', 'alarm_description',
            'previous', 'current', 'reason'
    ]:
        value = cont.get(key)
        if value:
            value_list.append(value)
        else:
            value_list.append('')

    subject = "Easystack Alarm Notification  (alarm name:%s)" % value_list[0]
    alarm_mail = """
    <html>
        <head></head>
        <body>
        <p>
        <b>Alarm Info</b><br>
        alarm_name: %s<br>
        alarm_resource: %s<br>
        alarm_meter: %s<br>
        alarm_description: %s<br>
        </p>
        <p>
        <b>Alarm State Transition</b><br>
         From '%s' To '%s'<br>
        <p>
        <b>Reason</b><br>
        %s<br>
        </p>
       </body>
    </html>""" % tuple(value_list)

    server = getattr(settings, 'SMTP_SERVER', 'smtp.ym.163.com')
    sender = getattr(settings, 'SENDER', '*****@*****.**')
    password = getattr(settings, 'SMTP_PW', None)
    email = Email(server, sender, password)
    email.send_email(receiver, subject, alarm_mail)
    return rest_utils.JSONResponse("Successfully send the mail", 202)
Exemple #2
0
 def get(self, request, extpolicytarget_id):
     result = api.gbp.ext_policy_target_get(request, extpolicytarget_id)
     result = rest_utils.ensure_policy_rule_set(request, [result],
                                                'provided')[0]
     result = rest_utils.ensure_policy_rule_set(request, [result],
                                                'consumed')[0]
     return rest_utils.JSONResponse(result, 200)
Exemple #3
0
 def get(self, request):
     ldap_enable = getattr(settings, 'LDAP_ENABLE', False)
     ldap_editable = getattr(settings, 'LDAP_EDITABLE', True)
     return rest_utils.JSONResponse(
         {
             "enable": ldap_enable,
             "editable": ldap_editable
         }, 200)
Exemple #4
0
 def get(self, request):
     result = api.gbp.policy_target_list(request, request.user.tenant_id,
                                         **request.GET)
     result = rest_utils.ensure_l2_policy_name(request, result)
     result = rest_utils.ensure_policy_rule_set_name(
         request, result, 'provided')
     result = rest_utils.ensure_policy_rule_set_name(
         request, result, 'consumed')
     return rest_utils.JSONResponse(result, 200)
Exemple #5
0
 def patch(self, request, policyaction_id):
     body = {}
     body['name'] = request.DATA.get('name')
     body['description'] = request.DATA.get('description')
     if (body['description'] == None):
         body['description'] = ''
     body['shared'] = request.DATA.get('shared')
     result = api.gbp.policyaction_update(request, policyaction_id, **body)
     return rest_utils.JSONResponse(result, 200)
Exemple #6
0
    def post(self, request):
        user_id = request.DATA.get('user_id')
        if user_id == 'current':
            user_id = request.user.id
        project_id = request.DATA.get('project_id')

        result = api.keystone.user_is_project_admin(request,
                                                    user_id, project_id)\
            or api.keystone.is_cloud_admin(request)\
            or api.keystone.is_domain_admin(request)
        return rest_utils.JSONResponse(result, 200)
Exemple #7
0
 def post(self, request):
     body = {}
     body['name'] = request.DATA.get('name')
     body['description'] = request.DATA.get('description')
     if (body['description'] == None):
         body['description'] = ''
     body['policy_rules'] = request.DATA.get('policyRules')
     body['shared'] = request.DATA.get('shared')
     if (body['shared'] == None):
         body['shared'] = False
     result = api.gbp.policy_rule_set_create(request, **body)
     return rest_utils.JSONResponse(result, 200)
Exemple #8
0
 def patch(self, request, policy_classifier_id):
     body = {}
     body['name'] = request.DATA.get('name')
     body['description'] = request.DATA.get('description')
     if (body['description'] == None):
         body['description'] = ''
     body['protocol'] = request.DATA.get('protocol')
     body['port_range'] = request.DATA.get('port_range')
     body['direction'] = request.DATA.get('direction')
     body['shared'] = request.DATA.get('shared')
     result = api.gbp.policyclassifier_update(request, policy_classifier_id,
                                              **body)
     return rest_utils.JSONResponse(result, 200)
Exemple #9
0
 def patch(self, request, policy_rule_id):
     body = {}
     body['name'] = request.DATA.get('name')
     body['description'] = request.DATA.get('description')
     if (body['description'] == None):
         body['description'] = ''
     body['policy_actions'] = request.DATA.get('policyActions')
     body['policy_classifier_id'] = request.DATA.get('policyClassifier')
     body['shared'] = request.DATA.get('shared')
     if (body['shared'] == None):
         body['shared'] = False
     result = api.gbp.policyrule_update(request, policy_rule_id, **body)
     return rest_utils.JSONResponse(result, 200)
Exemple #10
0
    def get(self, request, policytargetgroup_id):
        result = api.gbp.policy_target_get(request, policytargetgroup_id)
        result = rest_utils.ensure_policy_rule_set(request, [result],
                                                   'provided')[0]
        result = rest_utils.ensure_policy_rule_set(request, [result],
                                                   'consumed')[0]
        l2_policy = api.gbp.l2policy_get(request, result.l2_policy_id)
        result.get_dict()['l2_policy_name'] = \
            l2_policy['name'] + ':' + l2_policy['id']
        l3_policy = api.gbp.l3policy_get(request, l2_policy.l3_policy_id)
        result.get_dict()['l3_policy_name'] = \
            l3_policy['name'] + ':' + l3_policy['id']

        return rest_utils.JSONResponse(result, 200)
Exemple #11
0
    def put(self, request):
        """Update notify list of current user"""
        user_id = request.user.id
        admin = request.user.is_superuser
        user = api.keystone.user_get(request, user_id, admin)
        dic = user.to_dict()
        name = request.DATA.get('name')
        notify_list = dic.get('notify_list')
        if notify_list:
            for item in notify_list:
                if item.get('name') == name:
                    notify_list.remove(item)
                    notify_list.append(request.DATA)
                    break
        data = {'notify_list': notify_list}
        api.keystone.user_update(request, user, admin, **data)

        return rest_utils.JSONResponse(request.DATA, 202)
Exemple #12
0
 def post(self, request):
     body = {}
     body['name'] = request.DATA.get('name')
     if (request.DATA.has_key('description')):
         body['description'] = request.DATA.get('description')
     body['l2_policy_id'] = request.DATA.get('networkPolicy')
     body['network_service_policy_id'] = request.DATA.get(
         'networkServicePolicy')
     consumePRS = request.DATA.get('consumePolicyRuleSet')
     body['consumed_policy_rule_sets'] = {}
     for prs in consumePRS:
         body['consumed_policy_rule_sets'][prs] = None
     providedPRS = request.DATA.get('providePolicyRuleSet')
     body['provided_policy_rule_sets'] = {}
     for prs in providedPRS:
         body['provided_policy_rule_sets'][prs] = None
     body['shared'] = request.DATA.get('shared')
     if (body['shared'] == None):
         body['shared'] = False
     result = api.gbp.policy_target_create(request, **body)
     return rest_utils.JSONResponse(result, 200)
Exemple #13
0
    def delete(self, request, subnet_id):
        """Delete a single subnet by id.

        This method returns HTTP 204 (no content) on success.
        """
        port_can_delete = []
        if id == 'default':
            raise django.http.HttpResponseNotFound('default')
        relate_port = api.neutron.port_list(request,
                                            fixed_ips='subnet_id=' + subnet_id)
        for p in relate_port:
            if not p.device_id:
                port_can_delete.append(p)
            else:
                device_owner = p.device_owner or ''
                if not device_owner.startswith('network:dhcp'):
                    return rest_utils.JSONResponse(
                        'One or more ports have an IP allocation from this subnet.',
                        409)
        for pcd in port_can_delete:
            api.neutron.port_delete(request, pcd.id)
        api.neutron.subnet_delete(request, subnet_id)
Exemple #14
0
    def delete(self, request, network_id):
        """Delete a single network by id.

        This method returns HTTP 204 (no content) on success.
        """
        relate_port = []
        port_can_delete = []
        if id == 'default':
            raise django.http.HttpResponseNotFound('default')
        relate_port = api.neutron.port_list(request, network_id=network_id)
        for p in relate_port:
            if not p.device_id:
                port_can_delete.append(p)
            else:
                device_owner = p.device_owner or ''
                if not device_owner.startswith('network:dhcp'):
                    return rest_utils.JSONResponse(
                        'There are one or more ports still in use on the network',
                        409)
        for pcd in port_can_delete:
            api.neutron.port_delete(request, pcd.id)
        api.neutron.network_delete(request, network_id)
Exemple #15
0
    def post(self, request):
        body = {}
        body['name'] = request.DATA.get('name')
        if (request.DATA.has_key('description')):
            body['description'] = request.DATA.get('description')
        extConnect = request.DATA.get('externalConnectivity')

        body['external_segments'] = []
        for conn in extConnect:
            body['external_segments'].append(conn)
        consumePRS = request.DATA.get('consumePolicyRuleSet')
        body['consumed_policy_rule_sets'] = {}
        for prs in consumePRS:
            body['consumed_policy_rule_sets'][prs] = None
        providedPRS = request.DATA.get('providePolicyRuleSet')
        body['provided_policy_rule_sets'] = {}
        for prs in providedPRS:
            body['provided_policy_rule_sets'][prs] = None
        body['shared'] = request.DATA.get('shared')
        if (body['shared'] == None):
            body['shared'] = False
        result = api.gbp.ext_policy_target_create(request, **body)
        return rest_utils.JSONResponse(result, 200)
Exemple #16
0
 def get(self, request):
     if not keystone.is_public_region(request):
         fixing = billing.get_active_pricefixing(request)
         if fixing is None:
             return rest_utils.JSONResponse(False, 200)
     return rest_utils.JSONResponse(True, 200)
Exemple #17
0
 def get(self, request):
     enable_billing = False
     if not keystone.is_public_region(request):
         if not keystone.is_dedicated_context(request):
             enable_billing = getattr(settings, 'ENABLE_BILLING', True)
     return rest_utils.JSONResponse(enable_billing, 200)
Exemple #18
0
 def get(self, request):
     result = api.gbp.is_project_admin(request)[1]
     return rest_utils.JSONResponse(result, 200)
Exemple #19
0
 def get(self, request, serviceprofile_id):
     result = api.gbp.get_service_profile(request, serviceprofile_id)
     return rest_utils.JSONResponse(result, 200)
Exemple #20
0
 def post(self, request):
     result = api.gbp.create_service_profile(request, request.DATA)
     return rest_utils.JSONResponse(result, 200)
Exemple #21
0
 def post(self, request):
     result = api.gbp.create_natpool(request, **request.DATA)
     return rest_utils.JSONResponse(result, 200)
Exemple #22
0
 def get(self, request, servicechaininstance_id):
     result = api.gbp.get_servicechain_instance(request,
                                                servicechaininstance_id)
     return rest_utils.JSONResponse(result, 200)
Exemple #23
0
 def post(self, request):
     result = api.gbp.create_servicechain_instance(request, request.DATA)
     return rest_utils.JSONResponse(result, 200)
Exemple #24
0
 def patch(self, request, natpool_id):
     result = api.gbp.update_natpool(request, natpool_id, **request.DATA)
     return rest_utils.JSONResponse(result, 200)
Exemple #25
0
 def get(self, request, natpool_id):
     result = api.gbp.get_natpool(request, natpool_id)
     return rest_utils.JSONResponse(result, 200)
Exemple #26
0
 def get(self, request):
     balance = billing.get_balance(request)
     return rest_utils.JSONResponse(balance, 200)
Exemple #27
0
 def patch(self, request, servicechaininstance_id):
     result = api.gbp.update_servicechain_instance(request,
                                                   servicechaininstance_id,
                                                   request.DATA)
     return rest_utils.JSONResponse(result, 200)
Exemple #28
0
 def get(self, request):
     result = api.gbp.serviceprofile_list(request, request.user.tenant_id,
                                          **request.GET)
     return rest_utils.JSONResponse(result, 200)
Exemple #29
0
 def patch(self, request, servicechain_node_id):
     result = api.gbp.update_servicechain_node(request,
                                               servicechain_node_id,
                                               **request.GET)
     return rest_utils.JSONResponse(result, 200)
Exemple #30
0
 def get(self, request):
     result = api.gbp.natpool_list(request, request.user.tenant_id)
     return rest_utils.JSONResponse(result, 200)