Ejemplo n.º 1
0
def show_topology(request, instance_id=None, type=None):
    user = osmutils.get_user(request)
    project_id = user.project_id
    raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
    if 'application/json' in raw_content_types:
        client = Client()
        nsr_object = {'nsr': {}, 'vnfr': {}, 'vnfd': {}}
        if type == 'ns':

            nsr_resp = client.ns_get(user.get_token(), instance_id)
            nsr_object['nsr'] = nsr_resp['data']
            if 'constituent-vnfr-ref' in nsr_object['nsr'] :
                for vnfr_id in nsr_object['nsr']['constituent-vnfr-ref']:
                    vnfr_resp = client.vnf_get(user.get_token(), vnfr_id)
                    vnfr = vnfr_resp['data']
                    nsr_object['vnfr'][vnfr['id']] = vnfr
                    if vnfr['vnfd-id'] not in nsr_object['vnfd']:
                        vnfd_resp = client.vnfd_get(user.get_token(), vnfr['vnfd-id'])
                        nsr_object['vnfd'][vnfr['vnfd-id']] = vnfd_resp['vnfd:vnfd-catalog']['vnfd'][0]

        test = OsmParser()

        result = test.nsr_to_graph(nsr_object)
        return __response_handler(request, result)
    else:
        result = {'type': type, 'project_id': project_id, 'instance_id': instance_id}
        return __response_handler(request, result, 'instance_topology_view.html')
Ejemplo n.º 2
0
def updateElement(request,
                  descriptor_type=None,
                  descriptor_id=None,
                  element_type=None):
    user = osmutils.get_user(request)
    client = Client()
    payload = request.POST.dict()
    util = OsmUtil()

    if descriptor_type == 'nsd':
        descriptor_result = client.nsd_get(user.get_token(), descriptor_id)
    elif descriptor_type == 'vnfd':
        descriptor_result = client.vnfd_get(user.get_token(), descriptor_id)

    if element_type == 'graph_params':
        descriptor_updated = util.update_graph_params(
            descriptor_type, descriptor_result, json.loads(payload['update']))
    else:
        descriptor_updated = util.update_node(descriptor_type,
                                              descriptor_result, element_type,
                                              json.loads(payload['old']),
                                              json.loads(payload['update']))

    if descriptor_type == 'nsd':
        result = client.nsd_update(user.get_token(), descriptor_id,
                                   descriptor_updated)
    elif descriptor_type == 'vnfd':
        result = client.vnfd_update(user.get_token(), descriptor_id,
                                    descriptor_updated)
    if result['error'] == True:
        return __response_handler(request,
                                  result['data'],
                                  url=None,
                                  status=result['data']['status']
                                  if 'status' in result['data'] else 500)
    else:
        parser = OsmParser()
        if descriptor_type == 'vnfd':
            result_graph = parser.vnfd_to_graph(descriptor_updated)
        elif descriptor_type == 'nsd':
            result_graph = parser.nsd_to_graph(descriptor_updated)
        return __response_handler(request, result_graph, url=None, status=200)
Ejemplo n.º 3
0
def open_composer(request):
    user = osmutils.get_user(request)
    descriptor_id = request.GET.get('id')
    descriptor_type = request.GET.get('type')
    result = {}
    client = Client()
    if descriptor_id:
        raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
        if 'application/json' not in raw_content_types:
            return __response_handler(request, {'type': descriptor_type},
                                      'composer.html')
        try:
            if descriptor_type == 'nsd':
                descriptor_result = client.nsd_get(user.get_token(),
                                                   descriptor_id)
            elif descriptor_type == 'vnfd':
                descriptor_result = client.vnfd_get(user.get_token(),
                                                    descriptor_id)

        except Exception as e:
            descriptor_result = {'error': True, 'data': str(e)}

        if isinstance(
                descriptor_result, dict
        ) and 'error' in descriptor_result and descriptor_result['error']:
            return render(request, 'error.html')

        test = OsmParser()
        # print nsr_object
        if descriptor_type == 'nsd':
            result = test.nsd_to_graph(descriptor_result)
        elif descriptor_type == 'vnfd':
            result = test.vnfd_to_graph(descriptor_result)
        return __response_handler(request, result, 'composer.html')

    return __response_handler(request, result, 'composer.html')
Ejemplo n.º 4
0
def removeElement(request,
                  descriptor_type=None,
                  descriptor_id=None,
                  element_type=None):
    user = osmutils.get_user(request)
    client = Client()
    if descriptor_type == 'nsd':
        descriptor_result = client.nsd_get(user.get_token(), descriptor_id)
        element_id = request.POST.get('id', '')
        util = OsmUtil()
        descriptor_updated = util.remove_node('nsd', descriptor_result,
                                              element_type, element_id,
                                              request.POST.dict())
        result = client.nsd_update(user.get_token(), descriptor_id,
                                   descriptor_updated)
        if result['error'] == True:
            return __response_handler(request,
                                      result['data'],
                                      url=None,
                                      status=result['data']['status']
                                      if 'status' in result['data'] else 500)
        else:
            parser = OsmParser()
            # print nsr_object
            if descriptor_type == 'nsd':
                result_graph = parser.nsd_to_graph(descriptor_updated)

        return __response_handler(request, result_graph, url=None, status=200)

    elif descriptor_type == 'vnfd':
        descriptor_result = client.vnfd_get(user.get_token(), descriptor_id)
        element_id = request.POST.get('id', '')
        util = OsmUtil()
        descriptor_updated = util.remove_node('vnfd', descriptor_result,
                                              element_type, element_id,
                                              request.POST.dict())
        result = client.vnfd_update(user.get_token(), descriptor_id,
                                    descriptor_updated)
        if result['error'] == True:
            return __response_handler(request,
                                      result['data'],
                                      url=None,
                                      status=result['data']['status']
                                      if 'status' in result['data'] else 500)
        else:
            parser = OsmParser()
            # print nsr_object
            if descriptor_type == 'vnfd':
                result_graph = parser.vnfd_to_graph(descriptor_updated)

            return __response_handler(request,
                                      result_graph,
                                      url=None,
                                      status=200)