Attach network to VPN gateway
        :Param  req
        :Type   object Request
160959
def attach_vpngw(self, req, id, driver):
        
        vpngw = driver.get_vnpgw(req.params, id)
        if vpngw is None:
            vpngw = driver.create_vpngw(req.params, id)
        response = driver.attach_vpngw(req.params, vpngw)
        data = {
            'action': 'attach_igw',
            'controller': 'network',
            'id': id,
            'cloud': req.environ['calplus.cloud'],
            'response': response
        }
        return data
635923
def _establish_tunnel(self, connection, address):
        '''
        '''
        host = '[{}]'.format(address[0]) if ':' in address[0] else address[0]
        port = address[1]
        request = RawRequest('CONNECT', '{0}:{1}'.format(host, port))

        self.add_auth_header(request)

        stream = Stream(connection, keep_alive=True)

        _logger.debug('Sending Connect.')
        yield from stream.write_request(request)

        _logger.debug('Read proxy response.')
        response = yield from stream.read_response()

        if response.status_code != 200:
            debug_file = io.BytesIO()
            _logger.debug('Read proxy response body.')
            yield from stream.read_body(request, response, file=debug_file)

            debug_file.seek(0)
            _logger.debug(ascii(debug_file.read()))

        if response.status_code == 200:
            connection.tunneled = True
        else:
            raise NetworkError(
                'Proxy does not support CONNECT: {} {}'
                .format(response.status_code,
                        wpull.string.printable_str(response.reason))
            )
860675
def register_onRsp(self, req):
        
        def wrapper(_callback):
            callbackList = self._req_callbacks.setdefault(req, [])
            callbackList.append(_callback)
            return _callback
        return wrapper
661562
def add(env, securitygroup_id, network_component, server, interface):
    """"""
    _validate_args(network_component, server, interface)

    mgr = SoftLayer.NetworkManager(env.client)
    component_id = _get_component_id(env, network_component, server, interface)

    ret = mgr.attach_securitygroup_component(securitygroup_id,
                                             component_id)
    if not ret:
        raise exceptions.CLIAbort("Could not attach network component")

    table = formatting.Table(REQUEST_COLUMNS)
    table.add_row([ret['requestId']])

    env.fout(table)
756673
function(req, res, router, cb) {
  var url = (req.url === '/') ? '/' + router.defaultPage : req.url;
  var source = router.static.path + url; //path.resolve(router.static.path, '.'+url);
  if (url.indexOf('.') != -1) {
    router.stat(source, function(err, stat) {
      if (err || stat === undefined || stat.size === undefined) {
        cb();
      } else {
        res.writeHead(200, {
          'Content-Type': router.getMime(url),
          'Content-Length': stat.size
        });
        router.openStream(source).pipe(res);
      }
    });
  } else {
    cb();
  }
}
346526
def add_network_to_bgp_speaker(self, speaker_id, body=None):
        """"""
        return self.put((self.bgp_speaker_path % speaker_id) +
                        "/add_gateway_network", body=body)
1017928
def deploy(self, id_networkv4):
        

        data = dict()
        uri = 'api/networkv4/%s/equipments/' % id_networkv4

        return super(ApiNetworkIPv4, self).post(uri, data=data)
24245
def _setup_transport(self):
        
        if HAVE_PY26_SSL:
            if hasattr(self, 'sslopts'):
                self.sslobj = ssl.wrap_socket(self.sock, **self.sslopts)
            else:
                self.sslobj = ssl.wrap_socket(self.sock)
            self.sslobj.do_handshake()
        else:
            self.sslobj = socket.ssl(self.sock)
1061047
def attach_igw(self, req, driver):
        
        igw = driver.get_igw(req.params)
        if igw is None:
            igw = driver.create_igw(req.params)
        response = driver.attach_igw(req.params, igw)
        data = {
            'action': 'attach_igw',
            'controller': 'network',
            'id': id,
            'cloud': req.environ['calplus.cloud'],
            'response': response
        }
        return data
622830
def _connect_to_gateway(self):
        
        for key in self.ssh_pkeys:
            self.logger.debug('Trying to log in with key: {0}'
                              .format(hexlify(key.get_fingerprint())))
            try:
                self._transport = self._get_transport()
                self._transport.connect(hostkey=self.ssh_host_key,
                                        username=self.ssh_username,
                                        pkey=key)
                if self._transport.is_alive:
                    return
            except paramiko.AuthenticationException:
                self.logger.debug('Authentication error')
                self._stop_transport()

        if self.ssh_password:  # avoid conflict using both pass and pkey
            self.logger.debug('Trying to log in with password: {0}'
                              .format('*' * len(self.ssh_password)))
            try:
                self._transport = self._get_transport()
                self._transport.connect(hostkey=self.ssh_host_key,
                                        username=self.ssh_username,
                                        password=self.ssh_password)
                if self._transport.is_alive:
                    return
            except paramiko.AuthenticationException:
                self.logger.debug('Authentication error')
                self._stop_transport()

        self.logger.error('Could not open connection to gateway')
500476
def _on_gateway(self, header, payload, rest, addr):
        
        if payload.get('service') == SERVICE_UDP:
            self.gateway = Gateway(addr[0], payload['port'], header.gateway)
            self.gateway_found_event.set()
968211
function middlewareFunction (req,res,next){

  return ipToLocation(req.ip)
    .then(function (location) {
      req.location = location;
      next();
    })
    .catch(function (error) {
      req.locationError = error;
      next();
    })

}
964552
private void addPendingRequest(ResourceRequestInfo req) {
    idToPendingRequests.put(req.getId(), req);
    if (req.getHosts() != null && req.getHosts().size() > 0) {
      Context c = getContext(req.getType());
      for (RequestedNode node: req.getRequestedNodes()) {
        String host = node.getHost();
        List<ResourceRequestInfo> hostReqs = c.hostToPendingRequests.get(host);
        if (hostReqs == null) {
          hostReqs = new LinkedList<ResourceRequestInfo>();
          c.hostToPendingRequests.put(host, hostReqs);
        }
        hostReqs.add(req);
        Node rack = node.getRack();
        List<ResourceRequestInfo> rackReqs = c.rackToPendingRequests.get(rack);
        if (rackReqs == null) {
          rackReqs = new LinkedList<ResourceRequestInfo>();
          c.rackToPendingRequests.put(rack, rackReqs);
        }
        rackReqs.add(req);
      }
    }
    // Always add to the "any" list.
    Context c = getContext(req.getType());
    c.anyHostRequests.add(req);
    addPendingRequestForType(req);
  }
182124
def post(self, path, query=None, data=None, redirects=True):
        
        return self.request('POST', path, query, data, redirects)
749979
async def create_tunnel_connection(self, req):
        
        tunnel_address = req.tunnel_address
        connection = await self.create_connection(tunnel_address)
        response = connection.current_consumer()
        for event in response.events().values():
            event.clear()
        response.start(HttpTunnel(self, req))
        await response.event('post_request').waiter()
        if response.status_code != 200:
            raise ConnectionRefusedError(
                'Cannot connect to tunnel: status code %s'
                % response.status_code
            )
        raw_sock = connection.transport.get_extra_info('socket')
        if raw_sock is None:
            raise RuntimeError('Transport without socket')
        # duplicate socket so we can close transport
        raw_sock = raw_sock.dup()
        connection.transport.close()
        await connection.event('connection_lost').waiter()
        self.sessions -= 1
        self.requests_processed -= 1
        #
        connection = await self.create_connection(
            sock=raw_sock, ssl=req.ssl(self), server_hostname=req.netloc
        )
        return connection
1236831
def setCurrentNetwork(self, body, verbose=None):
        

        response=api(url=self.___url+'networks/currentNetwork', method="PUT", body=body, verbose=verbose)
        return response
140921
def deploy(self, id_networkv6):
        

        data = dict()
        uri = 'api/networkv6/%s/equipments/' % id_networkv6

        return super(ApiNetworkIPv6, self).post(uri, data=data)