Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        super(AddInterface, self).__init__(*args, **kwargs)
        # Populate Available Port Choices
        # Only include ports that are not already part of other interfaces
        this_interface_id = 0

        current_interface = None
        if (type(self) is UpdateInterface):
            this_interface_id = kwargs['initial']['id']
            current_interface = sysinv.host_interface_get(
                self.request, this_interface_id)
        else:
            self.fields['datanetworks_pci'].widget = \
                forms.widgets.HiddenInput()

        host_uuid = kwargs['initial']['ihost_uuid']

        # Populate Address Pool selections
        pools = sysinv.address_pool_list(self.request)
        self.fields['ipv4_pool'].choices = _get_ipv4_pool_choices(pools)
        self.fields['ipv6_pool'].choices = _get_ipv6_pool_choices(pools)

        # Populate Network Choices
        networks = sysinv.network_list(self.request)
        network_choices = _get_network_choices(networks)
        self.fields['networks'].choices = network_choices

        # Populate Data Network Choices by querying SysInv
        self.extras = {}

        used_datanets = []
        ifdns = sysinv.interface_datanetwork_list_by_host(
            self.request, host_uuid)
        for i in ifdns:
            if not current_interface or \
                    i.interface_uuid != current_interface.uuid:
                iface = sysinv.host_interface_get(self.request,
                                                  i.interface_uuid)
                if iface.ifclass == 'data':
                    used_datanets.append(i.datanetwork_name)

        datanet_choices = []
        datanet_filtered = []
        initial_datanet_name = []
        if getattr(self.request.user, 'services_region', None) == 'RegionOne' \
                and getattr(settings, 'DC_MODE', False):
            nt_choices = self.fields['ifclass'].choices
            self.fields['ifclass'].choices = [
                i for i in nt_choices if i[0] != 'data'
            ]

        datanets = sysinv.data_network_list(self.request)
        for dn in datanets:
            label = "{} (mtu={})".format(dn.name, dn.mtu)
            datanet = (str(dn.name), label)
            datanet_choices.append(datanet)
            if dn.name not in used_datanets:
                datanet_filtered.append(datanet)
                initial_datanet_name.append(str(dn.name))

        self.fields['datanetworks_data'].choices = datanet_filtered
        self.fields['datanetworks_sriov'].choices = datanet_filtered
        if (type(self) is UpdateInterface):
            self.fields['datanetworks_pci'].choices = datanet_choices
            # set initial selection for UpdateInterface
            self.fields['datanetworks_data'].initial = initial_datanet_name
            self.fields['datanetworks_pci'].initial = initial_datanet_name
            self.fields['datanetworks_sriov'].initial = initial_datanet_name

        if current_interface:
            # update operation
            if not current_interface.uses:
                # update default interfaces
                self.fields['uses'].widget = forms.widgets.HiddenInput()
                avail_port_list = sysinv.host_port_list(
                    self.request, host_uuid)
                for p in avail_port_list:
                    if p.interface_uuid == this_interface_id:
                        self.fields['ports'].initial = p.uuid
            else:
                # update non default interfaces
                avail_interface_list = sysinv.host_interface_list(
                    self.request, host_uuid)
                interface_tuple_list = []
                for i in avail_interface_list:
                    if i.uuid != current_interface.uuid:
                        interface_tuple_list.append(
                            (i.uuid,
                             "%s (%s, %s)" % (i.ifname, i.imac, i.ifclass)))

                uses_initial = [
                    i.uuid for i in avail_interface_list
                    if i.ifname in current_interface.uses
                ]

                self.fields['uses'].initial = uses_initial
                self.fields['uses'].choices = interface_tuple_list

            if current_interface.vlan_id:
                self.fields['vlan_id'].initial = current_interface.vlan_id

        else:
            # add operation
            avail_interface_list = sysinv.host_interface_list(
                self.request, host_uuid)
            interface_tuple_list = []
            for i in avail_interface_list:
                interface_tuple_list.append(
                    (i.uuid, "%s (%s, %s)" % (i.ifname, i.imac, i.ifclass)))
            self.fields['uses'].choices = interface_tuple_list
            self.fields['ifclass'].initial = ('none', 'none')
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        super(UpdateInterface, self).__init__(*args, **kwargs)
        ifclass_val = kwargs['initial']['ifclass']
        host_uuid = kwargs['initial']['ihost_uuid']

        this_interface_id = kwargs['initial']['id']

        iftype_val = kwargs['initial']['iftype']

        interface_networks = sysinv.interface_network_list_by_interface(
            self.request, this_interface_id)
        if ifclass_val == 'platform':
            # Load the networks associated with this interface
            network_choices = self.fields['networks'].choices
            network_choice_dict = dict(network_choices)
            initial_networks = []
            for i in interface_networks:
                for uuid in network_choice_dict.keys():
                    if i.network_uuid == uuid:
                        initial_networks.append(uuid)

            self.fields['networks'].initial = initial_networks
        for i in interface_networks:
            if i.network_type == 'mgmt':
                self.fields['aemode'].choices = self.MGMT_AE_MODE_CHOICES
                break
        else:
            self.fields['aemode'].choices = self.AE_MODE_CHOICES

        if ifclass_val in ['data', 'pci-passthrough', 'pci-sriov']:
            interface_datanetworks =\
                sysinv.interface_datanetwork_list_by_interface(
                    self.request, this_interface_id)
            # Load the networks associated with this interface
            if ifclass_val == 'data':
                datanetwork_choices = self.fields['datanetworks_data'].choices
            elif ifclass_val == 'pci-passthrough':
                datanetwork_choices = self.fields['datanetworks_pci'].choices
            elif ifclass_val == 'pci-sriov':
                datanetwork_choices = self.fields['datanetworks_sriov'].choices
            datanetwork_choice_dict = dict(datanetwork_choices)
            initial_datanetworks = []
            for i in interface_datanetworks:
                for name in datanetwork_choice_dict.keys():
                    if i.datanetwork_name == name:
                        initial_datanetworks.append(name)
            self.fields['datanetworks_data'].initial = initial_datanetworks
            self.fields['datanetworks_pci'].initial = initial_datanetworks
            self.fields['datanetworks_sriov'].initial = initial_datanetworks

        # Populate Address Pool selections
        pools = sysinv.address_pool_list(self.request)
        self.fields['ipv4_pool'].choices = _get_ipv4_pool_choices(pools)
        self.fields['ipv6_pool'].choices = _get_ipv6_pool_choices(pools)
        self.fields['ipv4_pool'].initial = kwargs['initial'].get('ipv4_pool')
        self.fields['ipv6_pool'].initial = kwargs['initial'].get('ipv6_pool')

        # Setting field to read-only doesn't actually work so we're making
        # it disabled.  This has the effect of not allowing the data through
        # to the form submission, so we require a hidden field to carry the
        # actual value through (iftype data)
        self.fields['iftype'].widget.attrs['disabled'] = 'disabled'
        self.fields['iftype'].required = False
        self.fields['iftype'].choices = self.INTERFACE_TYPE_CHOICES
        self.fields['iftypedata'].initial = kwargs['initial'].get('iftype')
        self.fields['iftype'].initial = kwargs['initial'].get('iftype')

        # Load the ifclass choices
        ifclass_choices = []
        used_choices = []
        if ifclass_val:
            label = "{}".format(ifclass_val)
            choice = (str(ifclass_val), label)
            used_choices.append(str(ifclass_val))
            ifclass_choices.append(choice)
        else:
            label = "{}".format("none")
            val = ("none", label)
            used_choices.append("none")
            ifclass_choices.append(val)

        if iftype_val == 'ethernet':
            choices_list = [
                'none', 'platform', 'data', 'pci-sriov', 'pci-passthrough'
            ]
        elif iftype_val == 'ae':
            choices_list = ['none', 'platform', 'data']
        elif iftype_val == 'vf':
            choices_list = ['none', 'data']
        else:
            choices_list = ['platform', 'data']

        choices_list = flatten(choices_list)

        if getattr(self.request.user, 'services_region', None) == 'RegionOne' \
                and getattr(settings, 'DC_MODE', False):
            # Data is not available when in RegionOne of SystemController
            choices_list.remove('data')

        for choice in choices_list:
            if choice not in used_choices:
                label = "{}".format(choice)
                val = (str(choice), label)
                ifclass_choices.append(val)

        self.fields['ifclass'].choices = ifclass_choices
        if not ifclass_val:
            del kwargs['initial']['ifclass']
            self.fields['ifclass'].initial = ('none', 'none')

        # Get the total possible number of VFs for SRIOV interface class
        port_list = sysinv.host_port_list(self.request, host_uuid)
        for p in port_list:
            if p.interface_uuid == this_interface_id:
                if p.sriov_totalvfs:
                    self.fields['sriov_totalvfs'].initial = p.sriov_totalvfs
                else:
                    self.fields['sriov_totalvfs'].initial = 0
                break

        initial_numvfs = kwargs['initial']['sriov_numvfs']
        if initial_numvfs:
            self.fields['sriov_numvfs'].initial = initial_numvfs
        else:
            self.fields['sriov_numvfs'].initial = 0
Esempio n. 3
0
    def __init__(self, *args, **kwargs):
        super(AddInterface, self).__init__(*args, **kwargs)
        # Populate Available Port Choices
        # Only include ports that are not already part of other interfaces
        this_interface_id = 0

        current_interface = None
        if (type(self) is UpdateInterface):
            this_interface_id = kwargs['initial']['id']
            current_interface = sysinv.host_interface_get(
                self.request, this_interface_id)
        else:
            self.fields['providernetworks_sriov'].widget = \
                forms.widgets.HiddenInput()
            self.fields['providernetworks_pci'].widget = \
                forms.widgets.HiddenInput()

        host_uuid = kwargs['initial']['ihost_uuid']

        # Retrieve SDN configuration
        sdn_enabled = kwargs['initial']['sdn_enabled']
        sdn_l3_mode = kwargs['initial']['sdn_l3_mode_enabled']

        # Populate Address Pool selections
        pools = sysinv.address_pool_list(self.request)
        self.fields['ipv4_pool'].choices = _get_ipv4_pool_choices(pools)
        self.fields['ipv6_pool'].choices = _get_ipv6_pool_choices(pools)

        # Populate Network Choices
        networks = sysinv.network_list(self.request)
        network_choices = _get_network_choices(networks)
        self.fields['networks'].choices = network_choices

        # Populate Provider Network Choices by querying Neutron
        self.extras = {}
        interfaces = sysinv.host_interface_list(self.request, host_uuid)

        used_providernets = []
        for i in interfaces:
            if i.ifclass == 'data' and \
                    i.providernetworks and \
                            i.uuid != this_interface_id:
                used_providernets = used_providernets + \
                    i.providernetworks.split(",")

        providernet_choices = []
        providernet_filtered = []
        if getattr(self.request.user, 'services_region', None) == 'RegionOne' \
                and getattr(settings, 'DC_MODE', False):
            nt_choices = self.fields['ifclass'].choices
            self.fields['ifclass'].choices = [
                i for i in nt_choices if i[0] != 'data'
            ]
        else:
            providernets = neutron.provider_network_list(self.request)
            for provider in providernets:
                label = "{} (mtu={})".format(provider.name, provider.mtu)
                providernet = (str(provider.name), label)
                providernet_choices.append(providernet)
                if provider.name not in used_providernets:
                    providernet_filtered.append(providernet)

        self.fields['providernetworks_data'].choices = providernet_filtered
        if (type(self) is UpdateInterface):
            self.fields['providernetworks_pci'].choices = providernet_choices
            self.fields['providernetworks_sriov'].choices = providernet_choices

        if current_interface:
            # update operation
            if not current_interface.uses:
                # update default interfaces
                self.fields['uses'].widget = forms.widgets.HiddenInput()
                avail_port_list = sysinv.host_port_list(
                    self.request, host_uuid)
                for p in avail_port_list:
                    if p.interface_uuid == this_interface_id:
                        self.fields['ports'].initial = p.uuid
            else:
                # update non default interfaces
                avail_interface_list = sysinv.host_interface_list(
                    self.request, host_uuid)
                interface_tuple_list = []
                for i in avail_interface_list:
                    if i.uuid != current_interface.uuid:
                        interface_tuple_list.append(
                            (i.uuid,
                             "%s (%s, %s)" % (i.ifname, i.imac, i.ifclass)))

                uses_initial = [
                    i.uuid for i in avail_interface_list
                    if i.ifname in current_interface.uses
                ]

                self.fields['uses'].initial = uses_initial
                self.fields['uses'].choices = interface_tuple_list

            if current_interface.vlan_id:
                self.fields['vlan_id'].initial = current_interface.vlan_id

        else:
            # add operation
            avail_interface_list = sysinv.host_interface_list(
                self.request, host_uuid)
            interface_tuple_list = []
            for i in avail_interface_list:
                interface_tuple_list.append(
                    (i.uuid, "%s (%s, %s)" % (i.ifname, i.imac, i.ifclass)))
            self.fields['uses'].choices = interface_tuple_list
            self.fields['ifclass'].initial = ('none', 'none')