- vdu_count = '-cnt-' + vdu_count
-
- application_name = 'app-{}{}{}'.format(vnf_id, vdu_id, vdu_count)
-
- return N2VCJujuConnector._format_app_name(application_name)
-
- async def _juju_create_machine(
- self,
- model_name: str,
- application_name: str,
- machine_id: str = None,
- db_dict: dict = None,
- progress_timeout: float = None,
- total_timeout: float = None
- ) -> Machine:
-
- self.debug('creating machine in model: {}, existing machine id: {}'.format(model_name, machine_id))
-
- # get juju model and observer (create model if needed)
- model = await self._juju_get_model(model_name=model_name)
- observer = self.juju_observers[model_name]
-
- # find machine id in model
- machine = None
- if machine_id is not None:
- self.debug('Finding existing machine id {} in model'.format(machine_id))
- # get juju existing machines in the model
- existing_machines = await model.get_machines()
- if machine_id in existing_machines:
- self.debug('Machine id {} found in model (reusing it)'.format(machine_id))
- machine = model.machines[machine_id]
-
- if machine is None:
- self.debug('Creating a new machine in juju...')
- # machine does not exist, create it and wait for it
- machine = await model.add_machine(
- spec=None,
- constraints=None,
- disks=None,
- series='xenial'
- )
-
- # register machine with observer
- observer.register_machine(machine=machine, db_dict=db_dict)
-
- # id for the execution environment
- ee_id = N2VCJujuConnector._build_ee_id(
- model_name=model_name,
- application_name=application_name,
- machine_id=str(machine.entity_id)
- )
-
- # write ee_id in database
- self._write_ee_id_db(
- db_dict=db_dict,
- ee_id=ee_id
- )
-
- # wait for machine creation
- await observer.wait_for_machine(
- machine_id=str(machine.entity_id),
- progress_timeout=progress_timeout,
- total_timeout=total_timeout
- )
-
- else:
-
- self.debug('Reusing old machine pending')
-
- # register machine with observer
- observer.register_machine(machine=machine, db_dict=db_dict)
-
- # machine does exist, but it is in creation process (pending), wait for create finalisation
- await observer.wait_for_machine(
- machine_id=machine.entity_id,
- progress_timeout=progress_timeout,
- total_timeout=total_timeout)
-
- self.debug("Machine ready at " + str(machine.dns_name))
- return machine
-
- async def _juju_provision_machine(
- self,
- model_name: str,
- hostname: str,
- username: str,
- private_key_path: str,
- db_dict: dict = None,
- progress_timeout: float = None,
- total_timeout: float = None
- ) -> str: