Allow several interfaces to be added and accessed from the other machines.

    This is particularly useful when working with virtual ips.
965584
def allow_address_pairs(session, network, subnet):
    
    nclient = neutron.Client('2', session=session,
                             region_name=os.environ['OS_REGION_NAME'])
    ports = nclient.list_ports()
    ports_to_update = filter(
        lambda p: p['network_id'] == network['id'],
        ports['ports'])
    logger.info('[nova]: Allowing address pairs for ports %s' %
                list(map(lambda p: p['fixed_ips'], ports_to_update)))
    for port in ports_to_update:
        try:
            nclient.update_port(port['id'], {
                'port': {
                    'allowed_address_pairs': [{
                        'ip_address': subnet
                        }]
                    }
                })
        except Exception:
            # NOTE(msimonin): dhcp and router interface port
            # seems to have enabled_sec_groups = False which
            # prevent them to be updated, just throw a warning
            # a skip them
            logger.warn("Can't update port %s" % port)
704425
def virtual_interface_create(name, net_name, **kwargs):
    '''
    
    '''
    conn = get_conn()
    return conn.virtual_interface_create(name, net_name)
1089657
def add_nexusport_binding(port_id, vlan_id, vni, switch_ip, instance_id,
                          is_native=False, ch_grp=0):
    """"""
    LOG.debug("add_nexusport_binding() called")
    session = bc.get_writer_session()
    binding = nexus_models_v2.NexusPortBinding(port_id=port_id,
                  vlan_id=vlan_id,
                  vni=vni,
                  switch_ip=switch_ip,
                  instance_id=instance_id,
                  is_native=is_native,
                  channel_group=ch_grp)
    session.add(binding)
    session.flush()
    return binding
774627
def add_hosts(self, hostIds):
    
    hostRefList = [ApiHostRef(self._get_resource_root(), x) for x in hostIds]
    return self._post("hosts", ApiHostRef, True, data=hostRefList,
        api_version=3)
1192040
def _add_redundancy_router_interfaces(self, context, router, itfc_info,
                                          new_port, redundancy_router_ids=None,
                                          ha_settings_db=None,
                                          create_ha_group=True):
        
        # There are essentially three cases where we add interface to a
        # redundancy router:
        # 1. HA is enabled on a user visible router that has one or more
        #    interfaces.
        # 2. Redundancy level is increased so one or more redundancy routers
        #    are added.
        # 3. An interface is added to a user visible router.
        #
        # For 1: An HA GROUP MUST BE CREATED and EXTRA PORTS MUST BE CREATED
        #        for each redundancy router. The id of extra port should be
        #        specified in the interface_info argument of the
        #        add_router_interface call so that we ADD BY PORT.
        # For 2: HA group need NOT be created as it will already exist (since
        #        there is already at least on redundancy router). EXTRA PORTS
        #        MUST BE CREATED for each added redundancy router. The id
        #        of extra port should be specified in the interface_info
        #        argument of the add_router_interface call so that we ADD BY
        #        PORT.
        # For 3: if the interface for the user_visible_router was added by ...
        #   a) PORT:   An HA GROUP MUST BE CREATED and and EXTRA PORTS MUST BE
        #              CREATED for each redundancy router. The id of extra port
        #              should be specified in the interface_info argument of
        #              the add_router_interface call so that we ADD BY PORT.
        #   b) SUBNET: There are two cases to consider. If the added interface
        #              of the user_visible_router has ...
        #        b1) 1 SUBNET:   An HA GROUP MUST BE CREATED and and EXTRA
        #                        PORTS MUST BE CREATED for each redundancy
        #                        router. The id of extra port should be
        #                        specified in the interface_info argument of
        #                        the add_router_interface call so we ADD BY
        #                        PORT.
        #        b2) >1 SUBNETS: HA group need NOT be created as it will
        #                        already exist (since the redundancy routers
        #                        should already have extra ports to which the
        #                        (IPv6) subnet is added. Extra ports need
        #                        thus NOT be created. The subnet id should be
        #                        added to the existing extra ports.
        router_id = router['id']
        if ha_settings_db is None:
            ha_settings_db = self._get_ha_settings_by_router_id(context,
                                                                router_id)
        if ha_settings_db is None:
            return
        e_context = context.elevated()
        add_by_subnet = (itfc_info is not None and 'subnet_id' in itfc_info and
                         len(new_port['fixed_ips']) > 1)
        if (add_by_subnet is False or (itfc_info is None and
                                       create_ha_group is True)):
            # generate ha settings and extra port for router (VIP) port
            self._create_ha_group(e_context, router, new_port, ha_settings_db)
        fixed_ips = self._get_fixed_ips_subnets(new_port['fixed_ips'])
        for r_id in (redundancy_router_ids or
                     self._get_redundancy_router_ids(e_context, router_id)):
            if add_by_subnet is True:
                # need to add subnet to redundancy router port
                ports = self._core_plugin.get_ports(
                    e_context,
                    filters={'device_id': [r_id],
                             'network_id': [new_port['network_id']]},
                    fields=['fixed_ips', 'id'])
                redundancy_port = ports[0]
                fixed_ips = redundancy_port['fixed_ips']
                fixed_ip = {'subnet_id': itfc_info['subnet_id']}
                fixed_ips.append(fixed_ip)
                self._core_plugin.update_port(
                    e_context, redundancy_port['id'],
                    {'port': {'fixed_ips': fixed_ips}})
            else:
                redundancy_port = self._create_hidden_port(
                    e_context, new_port['network_id'], '', fixed_ips)
                interface_info = {'port_id': redundancy_port['id']}
                self.add_router_interface(e_context, r_id, interface_info)
1115007
def _allocate_ips_to_nics(self, conf):
        
        for dom_name, dom_spec in conf.get('domains', {}).items():
            for idx, nic in enumerate(dom_spec.get('nics', [])):
                if 'ip' in nic:
                    continue
                net = self._get_net(conf, dom_name, nic)
                if net['type'] != 'nat':
                    continue

                allocated = net['mapping'].values()
                vacant = _create_ip(
                    net['gw'],
                    set(range(2, 255)).difference(
                        set([int(ip.split('.')[-1]) for ip in allocated])
                    ).pop()
                )
                nic['ip'] = vacant
                self._add_nic_to_mapping(net, dom_spec, nic)
1244555
public static base_response add(nitro_service client, nsip resource) throws Exception {
		nsip addresource = new nsip();
		addresource.ipaddress = resource.ipaddress;
		addresource.netmask = resource.netmask;
		addresource.type = resource.type;
		addresource.arp = resource.arp;
		addresource.icmp = resource.icmp;
		addresource.vserver = resource.vserver;
		addresource.telnet = resource.telnet;
		addresource.ftp = resource.ftp;
		addresource.gui = resource.gui;
		addresource.ssh = resource.ssh;
		addresource.snmp = resource.snmp;
		addresource.mgmtaccess = resource.mgmtaccess;
		addresource.restrictaccess = resource.restrictaccess;
		addresource.dynamicrouting = resource.dynamicrouting;
		addresource.ospf = resource.ospf;
		addresource.bgp = resource.bgp;
		addresource.rip = resource.rip;
		addresource.hostroute = resource.hostroute;
		addresource.hostrtgw = resource.hostrtgw;
		addresource.metric = resource.metric;
		addresource.vserverrhilevel = resource.vserverrhilevel;
		addresource.ospflsatype = resource.ospflsatype;
		addresource.ospfarea = resource.ospfarea;
		addresource.state = resource.state;
		addresource.vrid = resource.vrid;
		addresource.icmpresponse = resource.icmpresponse;
		addresource.ownernode = resource.ownernode;
		addresource.arpresponse = resource.arpresponse;
		addresource.td = resource.td;
		return addresource.add_resource(client);
	}
353578
def add_rule(self, ip_protocol, from_port, to_port,
                 src_group_name, src_group_owner_id, cidr_ip):
        
        rule = IPPermissions(self)
        rule.ip_protocol = ip_protocol
        rule.from_port = from_port
        rule.to_port = to_port
        self.rules.append(rule)
        rule.add_grant(src_group_name, src_group_owner_id, cidr_ip)
688855
def _find_interfaces_mac(ip):  # pylint: disable=invalid-name
    '''
    
    '''
    all_interfaces = _get_mine('net.interfaces')
    all_ipaddrs = _get_mine('net.ipaddrs')

    for device, device_ipaddrs in six.iteritems(all_ipaddrs):
        if not device_ipaddrs.get('result', False):
            continue
        for interface, interface_ipaddrs in six.iteritems(device_ipaddrs.get('out', {})):
            ip_addresses = interface_ipaddrs.get('ipv4', {}).keys()
            ip_addresses.extend(interface_ipaddrs.get('ipv6', {}).keys())
            for ipaddr in ip_addresses:
                if ip != ipaddr:
                    continue
                interface_mac = all_interfaces.get(device, {}).get('out', {}).get(interface, {}).get('mac_address', '')
                return device, interface, interface_mac

    return ('', '', '')
112005
def add_ipv4addr(self, ipv4addr):
        
        for addr in self.ipv4addrs:
            if ((isinstance(addr, dict) and addr['ipv4addr'] == ipv4addr) or
                (isinstance(addr, HostIPv4) and addr.ipv4addr == ipv4addr)):
                raise ValueError('Already exists')
        self.ipv4addrs.append({'ipv4addr': ipv4addr})
578493
def AddForwardedIp(self, address, interface):
    
    for ip in list(netaddr.IPNetwork(address)):
      self._RunIfconfig(args=[interface, 'alias', '%s/32' % str(ip)])
674036
public void addInterface(Class<?> newInterface) {
        if (!newInterface.isInterface()) {
            throw new IllegalArgumentException(newInterface + " is not an interface");
        }
        additionalInterfaces.add(newInterface);
    }
267537
def add_ip(self,oid,value,label=None):
		""""""
		self.add_oid_entry(oid,'IPADDRESS',value,label=label)
1369378
def access_add(name, event, cid, uid, **kwargs):
    
    ctx = Context(**kwargs)
    ctx.execute_action('access:add', **{
        'unicorn': ctx.repo.create_secure_service('unicorn'),
        'service': name,
        'event': event,
        'cids': cid,
        'uids': uid,
    })
968392
public static base_responses add(nitro_service client, nsip resources[]) throws Exception {
		base_responses result = null;
		if (resources != null && resources.length > 0) {
			nsip addresources[] = new nsip[resources.length];
			for (int i=0;i<resources.length;i++){
				addresources[i] = new nsip();
				addresources[i].ipaddress = resources[i].ipaddress;
				addresources[i].netmask = resources[i].netmask;
				addresources[i].type = resources[i].type;
				addresources[i].arp = resources[i].arp;
				addresources[i].icmp = resources[i].icmp;
				addresources[i].vserver = resources[i].vserver;
				addresources[i].telnet = resources[i].telnet;
				addresources[i].ftp = resources[i].ftp;
				addresources[i].gui = resources[i].gui;
				addresources[i].ssh = resources[i].ssh;
				addresources[i].snmp = resources[i].snmp;
				addresources[i].mgmtaccess = resources[i].mgmtaccess;
				addresources[i].restrictaccess = resources[i].restrictaccess;
				addresources[i].dynamicrouting = resources[i].dynamicrouting;
				addresources[i].ospf = resources[i].ospf;
				addresources[i].bgp = resources[i].bgp;
				addresources[i].rip = resources[i].rip;
				addresources[i].hostroute = resources[i].hostroute;
				addresources[i].hostrtgw = resources[i].hostrtgw;
				addresources[i].metric = resources[i].metric;
				addresources[i].vserverrhilevel = resources[i].vserverrhilevel;
				addresources[i].ospflsatype = resources[i].ospflsatype;
				addresources[i].ospfarea = resources[i].ospfarea;
				addresources[i].state = resources[i].state;
				addresources[i].vrid = resources[i].vrid;
				addresources[i].icmpresponse = resources[i].icmpresponse;
				addresources[i].ownernode = resources[i].ownernode;
				addresources[i].arpresponse = resources[i].arpresponse;
				addresources[i].td = resources[i].td;
			}
			result = add_bulk_request(client, addresources);
		}
		return result;
	}
412658
public <X> X newProxy(Class<X> interfaces) {
		return (X) newProxy(new Class[] {interfaces});
	}
1343550
private static void addAllInterfaces(List<NetworkInterface> target, List<NetworkInterface> level) {
        if (!level.isEmpty()) {
            target.addAll(level);
            for (NetworkInterface intf : level) {
                addAllInterfaces(target, Collections.list(intf.getSubInterfaces()));
            }
        }
    }