示例#1
0
def edit_optical_path(request, handle_id):
    # Get needed data from node
    nh, path = helpers.get_nh_node(handle_id)
    relations = path.get_relations()
    depends_on = path.get_dependencies()
    dependency_categories = 'odf,optical-link,optical-multiplex-section,optical-node,router,switch,optical-path'
    if request.POST:
        form = forms.EditOpticalPathForm(request.POST)
        if form.is_valid():
            # Generic node update
            helpers.form_update_node(request.user, path.handle_id, form)
            # Optical Path node updates
            if form.cleaned_data['relationship_provider']:
                owner_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_provider'])
                helpers.set_provider(request.user, path, owner_nh.handle_id)
            if form.cleaned_data['relationship_depends_on']:
                depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_depends_on'])
                helpers.set_depends_on(request.user, path, depends_on_nh.handle_id)
            if 'saveanddone' in request.POST:
                return redirect(nh.get_absolute_url())
            else:
                return redirect('%sedit' % nh.get_absolute_url())
    else:
        form = forms.EditOpticalPathForm(path.data)
    return render(request, 'noclook/edit/edit_optical_path.html',
                  {'node_handle': nh, 'form': form, 'node': path, 'relations': relations,
                   'depends_on': depends_on, 'dependency_categories': dependency_categories})
示例#2
0
def edit_optical_link(request, handle_id):
    # Get needed data from node
    nh, link = helpers.get_nh_node(handle_id)
    relations = link.get_relations()
    depends_on = link.get_dependencies()
    if request.POST:
        form = forms.EditOpticalLinkForm(request.POST)
        if form.is_valid():
            if 'type' in form.cleaned_data:
                form.cleaned_data['type'] = form.cleaned_data['type'].name
            # Generic node update
            helpers.form_update_node(request.user, link.handle_id, form)
            # Optical Link node updates
            if form.cleaned_data['relationship_provider']:
                owner_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_provider'])
                helpers.set_provider(request.user, link, owner_nh.handle_id)
            if form.cleaned_data['relationship_end_a']:
                depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_end_a'])
                helpers.set_depends_on(request.user, link, depends_on_nh.handle_id)
            if form.cleaned_data['relationship_end_b']:
                depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_end_b'])
                helpers.set_depends_on(request.user, link, depends_on_nh.handle_id)
            if 'saveanddone' in request.POST:
                return redirect(nh.get_absolute_url())
            else:
                return redirect('%sedit' % nh.get_absolute_url())
    else:
        form = forms.EditOpticalLinkForm(link.data)
    return render(request, 'noclook/edit/edit_optical_link.html',
                  {'node_handle': nh, 'form': form, 'node': link, 'relations': relations,
                   'depends_on': depends_on})
示例#3
0
文件: resources.py 项目: SUNET/ni
 def obj_update(self, bundle, **kwargs):
     bundle = super(ServiceL2VPNResource, self).obj_update(bundle, **kwargs)
     end_point_nodes = self.get_end_point_nodes(bundle)
     node = bundle.obj.get_node()
     if end_point_nodes:
         for item in node.get_dependencies().get('Depends_on', []):
             helpers.delete_relationship(bundle.request.user,
                                         item['relationship_id'])
         for end_point in end_point_nodes:
             helpers.set_depends_on(bundle.request.user, node,
                                    end_point.handle_id)
     return bundle
示例#4
0
def edit_pdu(request, handle_id):
    # Get needed data from node
    nh, pdu = helpers.get_nh_node(handle_id)
    location = pdu.get_location()
    relations = pdu.get_relations()
    depends_on = pdu.get_dependencies()
    host_services = pdu.get_host_services()
    ports = pdu.get_ports()
    dependency_categories = 'service'
    ports_form = forms.BulkPortsForm(request.POST or None)
    if request.POST:
        form = forms.EditPDUForm(request.POST)
        if form.is_valid():
            # Generic node update
            helpers.form_update_node(request.user, pdu.handle_id, form)
            # Host specific updates
            if form.cleaned_data['relationship_user']:
                user_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_user'])
                helpers.set_user(request.user, pdu, user_nh.handle_id)
            if form.cleaned_data['relationship_owner']:
                owner_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_owner'])
                helpers.set_owner(request.user, pdu, owner_nh.handle_id)
            # You can not set location and depends on at the same time
            if form.cleaned_data['relationship_depends_on']:
                depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_depends_on'])
                helpers.set_depends_on(request.user, pdu, depends_on_nh.handle_id)
            elif form.cleaned_data['relationship_location']:
                _handle_location(request.user,
                                 pdu,
                                 form.cleaned_data['relationship_location'])
            if form.cleaned_data['services_locked'] and form.cleaned_data['services_checked']:
                helpers.remove_rogue_service_marker(request.user, pdu.handle_id)
            if ports_form.is_valid() and not ports_form.cleaned_data['no_ports']:
                data = ports_form.cleaned_data
                helpers.bulk_create_ports(pdu, request.user, **data)
            _handle_ports(pdu,
                          form.cleaned_data['relationship_ports'],
                          request.user)
            if 'saveanddone' in request.POST:
                return redirect(nh.get_absolute_url())
            else:
                return redirect('%sedit' % nh.get_absolute_url())
    else:
        form = forms.EditPDUForm(pdu.data)
    return render(request, 'noclook/edit/edit_pdu.html',
                  {'node_handle': nh, 'node': pdu, 'form': form, 'location': location,
                   'relations': relations, 'depends_on': depends_on, 'ports': ports,
                   'host_services': host_services, 'dependency_categories': dependency_categories,
                   'ports_form': ports_form})
示例#5
0
def edit_host(request, handle_id):
    # Get needed data from node
    nh, host = helpers.get_nh_node(handle_id)
    location = host.get_location()
    relations = host.get_relations()
    depends_on = host.get_dependencies()
    host_services = host.get_host_services()
    ports = host.get_ports()
    dependency_categories = 'service,host'
    if request.POST:
        form = forms.EditHostForm(request.POST)
        if form.is_valid():
            # Generic node update
            helpers.form_update_node(request.user, host.handle_id, form)
            # Host specific updates
            if form.cleaned_data['relationship_user']:
                    user_nh = _nh_safe_get(form.cleaned_data['relationship_user'])
                    if user_nh:
                        helpers.set_user(request.user, host, user_nh.handle_id)
            if form.cleaned_data['relationship_owner']:
                owner_nh = _nh_safe_get(form.cleaned_data['relationship_owner'])
                if owner_nh:
                    helpers.set_owner(request.user, host, owner_nh.handle_id)
            # You can not set location and depends on at the same time
            if form.cleaned_data['relationship_depends_on']:
                depends_on_nh = _nh_safe_get(form.cleaned_data['relationship_depends_on'])
                if depends_on_nh:
                    helpers.set_depends_on(request.user, host, depends_on_nh.handle_id)
            elif form.cleaned_data['relationship_location']:
                _handle_location(request.user,
                                 host,
                                 form.cleaned_data['relationship_location'])
            if form.cleaned_data['services_locked'] and form.cleaned_data['services_checked']:
                helpers.remove_rogue_service_marker(request.user, host.handle_id)
            _handle_ports(host,
                          form.cleaned_data['relationship_ports'],
                          request.user)
            if 'saveanddone' in request.POST:
                return redirect(nh.get_absolute_url())
            else:
                return redirect('%sedit' % nh.get_absolute_url())
    else:
        form = forms.EditHostForm(host.data)
    context = {
        'node_handle': nh, 'node': host, 'form': form, 'location': location,
        'relations': relations, 'depends_on': depends_on, 'ports': ports,
        'host_services': host_services, 'dependency_categories': dependency_categories
    }
    return render(request, 'noclook/edit/edit_host.html', context)
示例#6
0
def auto_depend_services(handle_id,
                         description,
                         service_id_regex,
                         _type="Port"):
    """
        Using interface description to depend one or more services.
    """
    if not service_id_regex:
        return
    if not description:
        description = ""

    desc_services = service_id_regex.findall(description)

    for service_id in desc_services:
        service = _find_service(service_id)
        if service:
            if service.data.get('operational_state') == 'Decommissioned':
                logger.warning(
                    '{} {} description mentions decommissioned service {}'.
                    format(_type, handle_id, service_id))
            else:
                # Add it
                # logger.warning('Service {} should depend on port {}'.format(service_id, handle_id))
                helpers.set_depends_on(utils.get_user(), service, handle_id)
        else:
            logger.info('{} {} description mentions unknown service {}'.format(
                _type, handle_id, service_id))
    # check if "other services are dependent"
    q = """
        MATCH (n:Node {handle_id: {handle_id}})<-[:Depends_on]-(s:Service)
        WHERE s.operational_state <> 'Decommissioned' and  NOT(s.name in [{desc_services}])
        RETURN collect(s) as unregistered
        """
    result = nc.query_to_dict(nc.graphdb.manager,
                              q,
                              handle_id=handle_id,
                              desc_services=','.join(desc_services)).get(
                                  'unregistered', [])
    unregistered_services = [
        u"{}({})".format(s['name'], s['handle_id']) for s in result
    ]

    if unregistered_services:
        logger.info(
            u"{} {} has services depending on it that is not in description: {}"
            .format(_type, handle_id, ','.join(unregistered_services)))
示例#7
0
def edit_service(request, handle_id):
    # Get needed data from node
    nh, service = helpers.get_nh_node(handle_id)
    relations = service.get_relations()
    depends_on = service.get_dependencies()
    dependency_categories = ['host',
                             'firewall',
                             'odf',
                             'optical-node',
                             'optical-path',
                             'optical-filter',
                             'router',
                             'service',
                             'switch',
                             'external-equipment']
    user_categories = ['customer', 'end-user']
    if request.POST:
        form = forms.EditServiceForm(request.POST)
        if form.is_valid():
            # Generic node update
            helpers.form_update_node(request.user, service.handle_id, form)
            # Service node updates
            if form.cleaned_data['relationship_provider']:
                owner_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_provider'])
                helpers.set_provider(request.user, service, owner_nh.handle_id)
            if form.cleaned_data['relationship_user']:
                user_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_user'])
                helpers.set_user(request.user, service, user_nh.handle_id)
            if form.cleaned_data['relationship_depends_on']:
                depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_depends_on'])
                helpers.set_depends_on(request.user, service, depends_on_nh.handle_id)
            if 'saveanddone' in request.POST:
                return redirect(nh.get_absolute_url())
            else:
                return redirect('%sedit' % nh.get_absolute_url())
    else:
        form = forms.EditServiceForm(service.data)
    return render(request, 'noclook/edit/edit_service.html',
                  {'node_handle': nh, 'form': form, 'node': service, 'relations': relations,
                   'depends_on': depends_on, 'dependency_categories': dependency_categories,
                   'user_categories': user_categories})
示例#8
0
 def add_dependent(self, user, main_logical_nh, dep_logical_nh):
     main_logical_handle_id = main_logical_nh.handle_id
     dep_logical_nh = dep_logical_nh.get_node()
     helpers.set_depends_on(user, dep_logical_nh, main_logical_handle_id)
示例#9
0
 def add_dependency(cls, user, main_logical_nh, dep_logical_nh):
     main_logical_nh = main_logical_nh.get_node()
     dep_logical_handle_id = dep_logical_nh.handle_id
     helpers.set_depends_on(user, main_logical_nh, dep_logical_handle_id)
示例#10
0
文件: metatypes.py 项目: SUNET/ni
 def link_dependencies(cls, user, logical1_nh, logical2_nh):
     logical1_node = logical1_nh.get_node()
     logical2_handle_id = logical2_nh.handle_id
     helpers.set_depends_on(user, logical1_node, logical2_handle_id)
示例#11
0
文件: metatypes.py 项目: SUNET/ni
 def link_dependents(cls, user, physical_nh, logical_nh):
     logical_node = logical_nh.get_node()
     physical_handle_id = physical_nh.handle_id
     helpers.set_depends_on(user, logical_node, physical_handle_id)
示例#12
0
文件: resources.py 项目: SUNET/ni
 def obj_create(self, bundle, **kwargs):
     bundle.data.update(self._initial_form_data(bundle))
     try:
         if unique_ids.is_free_unique_id(NordunetUniqueId,
                                         bundle.data['node_name']):
             bundle.data['name'] = bundle.data['node_name']
         else:
             raise_conflict_error('Service ID (%s) is already in use.' %
                                  bundle.data['node_name'])
     except KeyError as e:
         raise_not_acceptable_error('%s is missing.' % e)
     form = forms.NewL2vpnServiceForm(bundle.data)
     if form.is_valid():
         bundle.data.update({
             'node_name':
             form.cleaned_data['name'],
             'creator':
             '/api/%s/user/%d/' %
             (self._meta.api_name, bundle.request.user.pk),
             'modifier':
             '/api/%s/user/%d/' %
             (self._meta.api_name, bundle.request.user.pk)
         })
         node_data = bundle.data.get('node', {})
         node_data.update({
             'service_type':
             form.cleaned_data['service_type'],
             'service_class':
             form.cleaned_data['service_class'],
             'ncs_service_name':
             form.cleaned_data['ncs_service_name'],
             'vpn_type':
             form.cleaned_data['vpn_type'],
             'vlan':
             form.cleaned_data['vlan'],
             'vrf_target':
             form.cleaned_data['vrf_target'],
             'route_distinguisher':
             form.cleaned_data['route_distinguisher'],
             'operational_state':
             form.cleaned_data['operational_state'],
             'description':
             form.cleaned_data['description'],
         })
         bundle.data['node'] = node_data
         del bundle.data['name']
         # Ensure that we have all the data needed to create the L2VPN service
         end_point_nodes = self.get_end_point_nodes(bundle)
         # Create the new service
         bundle = super(ServiceL2VPNResource,
                        self).obj_create(bundle, **kwargs)
         unique_ids.register_unique_id(NordunetUniqueId,
                                       bundle.data['node_name'])
         # Depend the created service on provided end points
         node = bundle.obj.get_node()
         for end_point in end_point_nodes:
             helpers.set_depends_on(bundle.request.user, node,
                                    end_point.handle_id)
         return self.hydrate_node(bundle)
     else:
         raise_not_acceptable_error([
             "%s is missing or incorrect." % key
             for key in form.errors.keys()
         ])