- """
- ##############################################################
- # check arguments
- ##############################################################
- """
-
- # juju URL
- if url is None:
- raise N2VCBadArgumentsException("Argument url is mandatory", ["url"])
- url_parts = url.split(":")
- if len(url_parts) != 2:
- raise N2VCBadArgumentsException(
- "Argument url: bad format (localhost:port) -> {}".format(url), ["url"]
- )
- self.hostname = url_parts[0]
- try:
- self.port = int(url_parts[1])
- except ValueError:
- raise N2VCBadArgumentsException(
- "url port must be a number -> {}".format(url), ["url"]
- )
-
- # juju USERNAME
- if username is None:
- raise N2VCBadArgumentsException(
- "Argument username is mandatory", ["username"]
- )
-
- # juju CONFIGURATION
- if vca_config is None:
- raise N2VCBadArgumentsException(
- "Argument vca_config is mandatory", ["vca_config"]
- )
-
- if "secret" in vca_config:
- self.secret = vca_config["secret"]
- else:
- raise N2VCBadArgumentsException(
- "Argument vca_config.secret is mandatory", ["vca_config.secret"]
- )
-
- # pubkey of juju client in osm machine: ~/.local/share/juju/ssh/juju_id_rsa.pub
- # if exists, it will be written in lcm container: _create_juju_public_key()
- if "public_key" in vca_config:
- self.public_key = vca_config["public_key"]
- else:
- self.public_key = None
-
- # TODO: Verify ca_cert is valid before using. VCA will crash
- # if the ca_cert isn't formatted correctly.
-
- self.ca_cert = vca_config.get("ca_cert")
- if self.ca_cert:
- self.ca_cert = base64_to_cacert(vca_config["ca_cert"])
-
- if "api_proxy" in vca_config and vca_config["api_proxy"] != "":
- self.api_proxy = vca_config["api_proxy"]
- self.log.debug(
- "api_proxy for native charms configured: {}".format(self.api_proxy)
- )
- else:
- self.warning(
- "api_proxy is not configured"
- )
- self.api_proxy = None
-
- model_config = ModelConfig(vca_config)
-
- self.cloud = vca_config.get('cloud')
- self.k8s_cloud = None
- if "k8s_cloud" in vca_config:
- self.k8s_cloud = vca_config.get("k8s_cloud")
- self.log.debug('Arguments have been checked')
-
- # juju data
- self.controller = None # it will be filled when connect to juju
- self.juju_models = {} # model objects for every model_name
- self.juju_observers = {} # model observers for every model_name
- self._connecting = (
- False # while connecting to juju (to avoid duplicate connections)
- )
- self._authenticated = (
- False # it will be True when juju connection be stablished
- )
- self._creating_model = False # True during model creation
- self.libjuju = Libjuju(
- endpoint=self.url,
- api_proxy=self.api_proxy,
- username=self.username,
- password=self.secret,
- cacert=self.ca_cert,
- loop=self.loop,
- log=self.log,
- db=self.db,
- n2vc=self,
- model_config=model_config,
- )
-
- # create juju pub key file in lcm container at
- # ./local/share/juju/ssh/juju_id_rsa.pub
- self._create_juju_public_key()