def __init__(self, username=None, password=None, resource_url=None, config=None, instance_id=None): """ :param username: The username of an authorized Streams user. :type username: str. :param password: The password associated with the username. :type password: str. :param resource_url: The resource endpoint of the instance. Can be found with `st geturl --api`. :type resource_url: str. :param config: Connection information for Bluemix. Should not be used in conjunction with username, password, and resource_url. :type config: dict. """ # manually specify username, password, and resource_url if username and password and resource_url: self._setup_distributed(instance_id, username, password, resource_url) # Connect to Bluemix service using VCAP elif config: vcap_services = _get_vcap_services( vcap_services=config.get(ConfigParams.VCAP_SERVICES)) self.credentials = _get_credentials( config[ConfigParams.SERVICE_NAME], vcap_services) self._analytics_service = True # Obtain the streams SWS REST URL rest_api_url = _get_rest_api_url_from_creds(self.credentials) # Create rest connection to remote Bluemix SWS self.rest_client = StreamsRestClient(self.credentials['userid'], self.credentials['password'], rest_api_url) self.resource_url = rest_api_url # Get the instance id from one of the URL paths self.instance_id = self.credentials['jobs_path'].split( '/service_instances/', 1)[1].split('/', 1)[0] elif username and password and st._has_local_install: self._setup_distributed(instance_id, username, password, st.get_rest_api()) elif st._has_local_install: # Assume quickstart self._setup_distributed(instance_id, 'streamsadmin', 'passw0rd', st.get_rest_api()) else: logger.error( "Invalid arguments for StreamsContext.__init__: must supply either a BlueMix VCAP Services or " "a username, password, and resource url.") raise ValueError( "Must supply either a BlueMix VCAP Services or a username, password, and resource url" " to the StreamsContext constructor.") self.rest_client._sc = self
def __init__(self, username=None, password=None, resource_url=None, config=None, instance_id=None): """ :param username: The username of an authorized Streams user. :type username: str. :param password: The password associated with the username. :type password: str. :param resource_url: The resource endpoint of the instance. Can be found with `st geturl --api`. :type resource_url: str. :param config: Connection information for Bluemix. Should not be used in conjunction with username, password, and resource_url. :type config: dict. """ # manually specify username, password, and resource_url if username and password and resource_url: self._setup_distributed(instance_id, username, password, resource_url) # Connect to Bluemix service using VCAP elif config: vcap_services = _get_vcap_services(vcap_services=config.get(ConfigParams.VCAP_SERVICES)) self.credentials = _get_credentials(config[ConfigParams.SERVICE_NAME], vcap_services) self._analytics_service = True # Obtain the streams SWS REST URL rest_api_url = _get_rest_api_url_from_creds(self.credentials) # Create rest connection to remote Bluemix SWS self.rest_client = StreamsRestClient(self.credentials['userid'], self.credentials['password'], rest_api_url) self.resource_url = rest_api_url # Get the instance id from one of the URL paths self.instance_id = self.credentials['jobs_path'].split('/service_instances/',1)[1].split('/',1)[0] elif username and password and st._has_local_install: self._setup_distributed(instance_id, username, password, st.get_rest_api()) elif st._has_local_install: # Assume quickstart self._setup_distributed(instance_id, 'streamsadmin', 'passw0rd', st.get_rest_api()) else: logger.error("Invalid arguments for StreamsContext.__init__: must supply either a BlueMix VCAP Services or " "a username, password, and resource url.") raise ValueError("Must supply either a BlueMix VCAP Services or a username, password, and resource url" " to the StreamsContext constructor.") self.rest_client._sc = self
def resource_url(self): """str: Root URL for IBM Streams REST API""" self._resource_url = self._resource_url or st.get_rest_api() return self._resource_url
def resource_url(self): """str: Root URL for IBM Streams REST API""" self._resource_url = self._resource_url or st.get_rest_api() return self._resource_url