Create a network adapter object and bind.
545428
def bind(self, server, net=None, address=None):
        """"""
        if _debug: NetworkServiceAccessPoint._debug("bind %r net=%r address=%r", server, net, address)

        # make sure this hasn't already been called with this network
        if net in self.adapters:
            raise RuntimeError("already bound")

        # create an adapter object, add it to our map
        adapter = NetworkAdapter(self, net)
        self.adapters[net] = adapter
        if _debug: NetworkServiceAccessPoint._debug("    - adapters[%r]: %r", net, adapter)

        # if the address was given, make it the "local" one
        if address and not self.local_address:
            self.local_adapter = adapter
            self.local_address = address

        # bind to the server
        bind(adapter, server)
94712
def register_on_network_adapter_changed(self, callback):
        
        event_type = library.VBoxEventType.on_network_adapter_changed
        return self.event_source.register_callback(callback, event_type)
530267
def get_nexusport_binding(port_id, vlan_id, switch_ip, instance_id):
    """"""
    LOG.debug("get_nexusport_binding() called")
    return _lookup_all_nexus_bindings(port_id=port_id,
                                      vlan_id=vlan_id,
                                      switch_ip=switch_ip,
                                      instance_id=instance_id)
948011
def prepare_socket(bind_addr, family, type, proto, nodelay, ssl_adapter):
        """"""
        sock = socket.socket(family, type, proto)
        prevent_socket_inheritance(sock)

        host, port = bind_addr[:2]
        IS_EPHEMERAL_PORT = port == 0

        if not (IS_WINDOWS or IS_EPHEMERAL_PORT):
            """Enable SO_REUSEADDR for the current socket.

            Skip for Windows (has different semantics)
            or ephemeral ports (can steal ports from others).

            Refs:
            * https://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
            * https://github.com/cherrypy/cheroot/issues/114
            * https://gavv.github.io/blog/ephemeral-port-reuse/
            """
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if nodelay and not isinstance(bind_addr, str):
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

        if ssl_adapter is not None:
            sock = ssl_adapter.bind(sock)

        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See
        # https://github.com/cherrypy/cherrypy/issues/871.
        listening_ipv6 = (
            hasattr(socket, 'AF_INET6')
            and family == socket.AF_INET6
            and host in ('::', '::0', '::0.0.0.0')
        )
        if listening_ipv6:
            try:
                sock.setsockopt(
                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0,
                )
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass

        return sock
76203
public void bindAndStart(int port) throws Exception {
        server = new NioServer(new StreamConnectionFactory() {
            @Override
            public ProtobufConnection<Protos.TwoWayChannelMessage> getNewConnection(InetAddress inetAddress, int port) {
                return new ServerHandler(new InetSocketAddress(inetAddress, port), timeoutSeconds).socketProtobufHandler;
            }
        }, new InetSocketAddress(port));
        server.startAsync();
        server.awaitRunning();
    }
351473
def adapter_update_nio_binding(self, adapter_number, nio):
        

        if self._ubridge_hypervisor:
            try:
                yield from self._update_ubridge_connection(adapter_number, nio)
            except IndexError:
                raise VMwareError('Adapter {adapter_number} does not exist on VMware VM "{name}"'.format(
                    name=self._name,
                    adapter_number=adapter_number
                ))
137793
def create_network(self):
        """"""
        return Network(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
53469
def _bind(self):
        

        credentials = pika.PlainCredentials(self.user, self.password)
        params = pika.ConnectionParameters(credentials=credentials,
                                           host=self.server,
                                           virtual_host=self.vhost,
                                           port=self.port)

        self.connection = pika.BlockingConnection(params)
        self.channel = self.connection.channel()

        # NOTE : PIKA version uses 'exchange_type' instead of 'type'

        self.channel.exchange_declare(exchange=self.topic_exchange,
                                      exchange_type="topic")
520516
def create_api_equipment(self):
        """"""
        return ApiEquipment(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
712502
def connect(self, event, handler):
        """"""
        interface = self._proxy.get_interface_name()
        return self.object.connect(interface, event, handler)
146151
def connect(self, interface, event, handler):
        """"""
        object_path = self.object_path
        return self.bus.connect(interface, event, object_path, handler)
204246
def etcd(url=DEFAULT_URL, mock=False, **kwargs):
    """"""
    if mock:
        from etc.adapters.mock import MockAdapter
        adapter_class = MockAdapter
    else:
        from etc.adapters.etcd import EtcdAdapter
        adapter_class = EtcdAdapter
    return Client(adapter_class(url, **kwargs))
73109
def adapter_add_nio_binding(self, adapter_number, port_number, nio):
        

        try:
            adapter = self._adapters[adapter_number]
        except IndexError:
            raise IOUError('Adapter {adapter_number} does not exist for IOU "{name}"'.format(name=self._name,
                                                                                             adapter_number=adapter_number))

        if not adapter.port_exists(port_number):
            raise IOUError("Port {port_number} does not exist in adapter {adapter}".format(adapter=adapter,
                                                                                           port_number=port_number))

        adapter.add_nio(port_number, nio)
        log.info('IOU "{name}" [{id}]: {nio} added to {adapter_number}/{port_number}'.format(name=self._name,
                                                                                             id=self._id,
                                                                                             nio=nio,
                                                                                             adapter_number=adapter_number,
                                                                                             port_number=port_number))

        if self.ubridge:
            bridge_name = "IOL-BRIDGE-{}".format(self.application_id + 512)
            yield from self._ubridge_send("iol_bridge add_nio_udp {name} {iol_id} {bay} {unit} {lport} {rhost} {rport}".format(name=bridge_name,
                                                                                                                               iol_id=self.application_id,
                                                                                                                               bay=adapter_number,
                                                                                                                               unit=port_number,
                                                                                                                               lport=nio.lport,
                                                                                                                               rhost=nio.rhost,
                                                                                                                               rport=nio.rport))
            yield from self._ubridge_apply_filters(adapter_number, port_number, nio.filters)
81778
def bind_socket(address, port):
    

    assert address
    assert port
    bindsocket = socket.socket()
    try:
        bindsocket.bind((address, port))
    except socket.error:
        logger.error("Couldn't bind socket on %s:%s", address, port)
        return None

    logger.info('Listening on %s:%s', address, port)
    bindsocket.listen(0)
    return bindsocket
1261471
def bind(cls, app, *paths, methods=None, name=None, view=None):
        """"""
        # Register self in admin
        if view is None:
            app.ps.admin.register(cls)
            if not paths:
                paths = ('%s/%s' % (app.ps.admin.cfg.prefix, name or cls.name),)
            cls.url = paths[0]
        return super(AdminHandler, cls).bind(app, *paths, methods=methods, name=name, view=view)
924601
def adapter_add_nio_binding(self, adapter_number, nio):
        

        try:
            adapter = self._ethernet_adapters[adapter_number]
        except KeyError:
            raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name,
                                                                                                            adapter_number=adapter_number))

        # check if trying to connect to a nat, bridged, host-only or any other special adapter
        nic_attachments = yield from self._get_nic_attachements(self._maximum_adapters)
        attachment = nic_attachments[adapter_number]
        if attachment in ("nat", "bridged", "intnet", "hostonly", "natnetwork"):
            if not self._use_any_adapter:
                raise VirtualBoxError("Attachment '{attachment}' is already configured on adapter {adapter_number}. "
                                      "Please remove it or allow VirtualBox VM '{name}' to use any adapter.".format(attachment=attachment,
                                                                                                                    adapter_number=adapter_number,
                                                                                                                    name=self.name))
            elif self.is_running():
                # dynamically configure an UDP tunnel attachment if the VM is already running
                local_nio = self._local_udp_tunnels[adapter_number][0]
                if local_nio and isinstance(local_nio, NIOUDP):
                    yield from self._control_vm("nic{} generic UDPTunnel".format(adapter_number + 1))
                    yield from self._control_vm("nicproperty{} sport={}".format(adapter_number + 1, local_nio.lport))
                    yield from self._control_vm("nicproperty{} dest={}".format(adapter_number + 1, local_nio.rhost))
                    yield from self._control_vm("nicproperty{} dport={}".format(adapter_number + 1, local_nio.rport))
                    yield from self._control_vm("setlinkstate{} on".format(adapter_number + 1))

        if self.is_running():
            try:
                yield from self.add_ubridge_udp_connection("VBOX-{}-{}".format(self._id, adapter_number),
                                                           self._local_udp_tunnels[adapter_number][1],
                                                           nio)
            except KeyError:
                raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name,
                                                                                                                adapter_number=adapter_number))
            yield from self._control_vm("setlinkstate{} on".format(adapter_number + 1))

        adapter.add_nio(0, nio)
        log.info("VirtualBox VM '{name}' [{id}]: {nio} added to adapter {adapter_number}".format(name=self.name,
                                                                                                 id=self.id,
                                                                                                 nio=nio,
                                                                                                 adapter_number=adapter_number))
380548
def _bind(self):
        """"""
        ldap_client = self._connect()
        try:
            ldap_client.simple_bind_s(self.binddn, self.bindpassword)
        except Exception as e:
            ldap_client.unbind_s()
            self._exception_handler(e)
        return ldap_client