Juju Utilities

Module for interacting with juju.

zaza.utilities.juju.get_application_ip(application, model_name=None)

Get the application’s IP address.

Parameters
  • application (str) – Application name

  • model_name (str) – Name of model to query.

Returns

Application’s IP address

Return type

str

zaza.utilities.juju.get_application_status(application=None, unit=None, model_name=None)

Return the juju status for an application.

Parameters
  • application (string) – Application name

  • unit (string) – Specific unit

  • model_name (str) – Name of model to query.

Returns

Juju status output for an application

Return type

dict

zaza.utilities.juju.get_cloud_configs(cloud=None)

Get cloud configuration from local clouds.yaml.

libjuju does not yet have cloud information implemented. Use libjuju as soon as possible.

Parameters

cloud – Name of specific cloud

Returns

Dictionary of cloud configuration

Return type

dict

zaza.utilities.juju.get_full_juju_status(model_name=None)

Return the full juju status output.

Parameters

model_name (str) – Name of model to query.

Returns

Full juju status output

Return type

dict

zaza.utilities.juju.get_machine_series(machine, model_name=None)

Return the juju series for a machine.

Parameters
  • machine (string) – Machine number

  • model_name (str) – Name of model to query.

Returns

Juju series

Return type

string

zaza.utilities.juju.get_machine_status(machine, key=None, model_name=None)

Return the juju status for a machine.

Parameters
  • machine (string) – Machine number

  • key (string) – Key option requested

  • model_name (str) – Name of model to query.

Returns

Juju status output for a machine

Return type

dict

zaza.utilities.juju.get_machine_uuids_for_application(application, model_name=None)

Return machine uuids for a given application.

Parameters
  • application (string) – Application name

  • model_name (str) – Name of model to query.

Returns

List of machine uuuids for an application

Return type

list

zaza.utilities.juju.get_machines_for_application(application, model_name=None)

Return machines for a given application.

Parameters
  • application (string) – Application name

  • model_name (str) – Name of model to query.

Returns

List of machines for an application

Return type

list

zaza.utilities.juju.get_principle_applications(application_name, application_status=None, model_name=None)

Get the principle applications that application_name is related to.

Parameters
  • application_name (string) – Application name

  • application_status (dict) – Juju status dict for application

  • model_name (str) – Name of model to query.

Returns

List of principle applications

Return type

list

zaza.utilities.juju.get_provider_type()

Get the type of the undercloud.

If it can’t work it out (i.e. it might be a localhost lxd install where there is no clouds.yaml) then return None.

If libjuju doesn’t know (i.e. cloud is not truthy) then default to openstack.

Returns

Name of the undercloud type

Return type

Optional[string]

zaza.utilities.juju.get_relation_from_unit(entity, remote_entity, remote_interface_name, model_name=None)

Get relation data passed between two units.

Get relation data for relation with remote_interface_name between entity and remote_entity from the perspective of entity.

entity and remote_entity may refer to either a application or a specific unit. If application name is given first unit is found in model.

Parameters
  • entity (str) – Application or unit to get relation data from

  • remote_entity (str) – Application or Unit in the other end of the relation we want to query

  • remote_interface_name (str) – Name of interface to query on remote end of relation

  • model_name (str) – Name of model to query.

Returns

dict with relation data

Return type

dict

Raises

model.CommandRunFailed

zaza.utilities.juju.get_subordinate_units(unit_list, charm_name=None, status=None, model_name=None)

Get a list of all subordinate units associated with units in unit_list.

Get a list of all subordinate units associated with units in unit_list. Subordinate can be filtered by using ‘charm_name’ which will only return subordinate units which have ‘charm_name’ in the name of the charm e.g.

get_subordinate_units(
[‘cinder/1’]) would return [‘cinder-hacluster/1’,

‘cinder-ceph/2’])

where as

get_subordinate_units(

[‘cinder/1’], charm_name=’hac’) would return [‘cinder-hacluster/1’]

NOTE: The charm_name match is against the name of the charm not the

application name.

Parameters
  • charm_name (str) – List of unit names

  • charm_name – charm_name to match against, can be a sub-string.

  • status (juju.client._definitions.FullStatus) – Juju status to query against,

  • model_name (str) – Name of model to query.

Returns

List of matching unit names.

Return type

[]

zaza.utilities.juju.get_unit_name_from_host_name(host_name, application_name, model_name=None)

Return the juju unit name corresponding to a hostname.

Parameters
  • host_name (string) – Host name to map to unit name.

  • application_name (string) – Application name

  • model_name (str) – Name of model to query.

Returns

The unit name of the application running on host_name.

Return type

str or None

zaza.utilities.juju.get_unit_name_from_ip_address(ip, application_name, model_name=None)

Return the juju unit name corresponding to an IP address.

Parameters
  • ip (string) – IP address to map to unit name.

  • application_name (string) – Application name

  • model_name (str) – Name of model to query.

zaza.utilities.juju.is_subordinate_application(application_name, application_status=None, model_name=None)

Is the given application a subordinate application.

Parameters
  • application_name (string) – Application name

  • application_status (dict) – Juju status dict for application

  • model_name (str) – Name of model to query.

Returns

Whether application_name is a subordinate

Return type

bool

zaza.utilities.juju.leader_get(application, key='', model_name=None)

Get leader settings from leader unit of named application.

Parameters
  • application (str) – Application to get leader settings from.

  • model_name (str) – Name of model to query.

Returns

dict with leader settings

Return type

dict

Raises

model.CommandRunFailed

zaza.utilities.juju.remote_run(unit, remote_cmd, timeout=None, fatal=None, model_name=None)

Run command on unit and return the output.

NOTE: This function is pre-deprecated. As soon as libjuju unit.run is able to return output this functionality should move to model.run_on_unit.

Parameters
  • remote_cmd (string) – Command to execute on unit

  • timeout – Timeout value for the command

  • fatal (bool) – Command failure condidered fatal or not

  • model_name (str) – Name of model to query.

Returns

Juju run output

Return type

string

Raises

model.CommandRunFailed