def __init__(self, server=None, port=None, api_version=1,
                 debug_print=False, timeout=None):
        """Initialize the REST API wrapper object.

        If the port to connect to is not specified by the port argument, or by
        the STC_SERVER_PORT environment variable, then try connecting on the
        DEFAULT_PORT.

        Arguments:
        server      -- STC REST API server to connect to. None to use environ.
        port        -- HTTP port to connect to server on.  Use environment
                       variable STC_SERVER_PORT or DEFAULT_PORT if None.
        api_version -- What API version to use.
        debug_print -- Enable debug print statements.
        timeout     -- Number of seconds to wait for a response.

        """
        if not server:
            server = os.environ.get('STC_SERVER_ADDRESS')
            if not server:
                raise RuntimeError('STC_SERVER_ADDRESS not set')
        if not port:
            port = os.environ.get('STC_SERVER_PORT', DEFAULT_PORT)

        self._dbg_print = bool(debug_print)
        rest = None

        url = resthttp.RestHttp.url('http', server, port, 'stcapi')
        rest = resthttp.RestHttp(url, debug_print=debug_print, timeout=timeout)
        try:
            rest.get_request('sessions')
        except (socket.error, resthttp.ConnectionError,
                resthttp.RestHttpError):
            raise RuntimeError('Cannot connect to STC server: %s:%s' %
                               (server, port))

        rest.add_header('X-Spirent-API-Version', str(api_version))
        self._rest = rest
        self._sid = None
        self._api_ver = None
def __init__ ( self , server = None , port = None , api_version = 1 , debug_print = False , timeout = None ) : if not server : server = os . environ . get ( 'STC_SERVER_ADDRESS' ) if not server : raise RuntimeError ( 'STC_SERVER_ADDRESS not set' ) if not port : port = os . environ . get ( 'STC_SERVER_PORT' , DEFAULT_PORT ) self . _dbg_print = bool ( debug_print ) rest = None url = resthttp . RestHttp . url ( 'http' , server , port , 'stcapi' ) rest = resthttp . RestHttp ( url , debug_print = debug_print , timeout = timeout ) try : rest . get_request ( 'sessions' ) except ( socket . error , resthttp . ConnectionError , resthttp . RestHttpError ) : raise RuntimeError ( 'Cannot connect to STC server: %s:%s' % ( server , port ) ) rest . add_header ( 'X-Spirent-API-Version' , str ( api_version ) ) self . _rest = rest self . _sid = None self . _api_ver = None
Initialize the REST API wrapper object.

        If the port to connect to is not specified by the port argument, or by
        the STC_SERVER_PORT environment variable, then try connecting on the
        DEFAULT_PORT.

        Arguments:
        server      -- STC REST API server to connect to. None to use environ.
        port        -- HTTP port to connect to server on.  Use environment
                       variable STC_SERVER_PORT or DEFAULT_PORT if None.
        api_version -- What API version to use.
        debug_print -- Enable debug print statements.
        timeout     -- Number of seconds to wait for a response.