Inventory Source

Description

This resource is used for managing and executing inventory sources via Tower. Note inventory updates are triggered via update method.

Fields Table

name type help_text read_only unique filterable required
name String The name field. False True True True
description String The description field. False False True False
inventory Resource inventory The inventory field. False False True True
source Choices: ,file,scm,ec2,vmware,gce,azure,azure_rm,openstack,satellite6,cloudforms,custom The type of inventory source in use. False False True True
credential Resource credential The credential field. False False True False
source_vars String The source_vars field. False False True False
timeout int The timeout field (in seconds). False False True False
source_project Resource project Use project files as source for inventory. False False True False
source_path String File in SCM Project to use as source. False False True False
update_on_project_update bool The update_on_project_update field. False False True False
source_regions String The source_regions field. False False True False
instance_filters String The instance_filters field. False False True False
group_by String The group_by field. False False True False
source_script Resource inventory_script The source_script field. False False True False
overwrite bool The overwrite field. False False True False
overwrite_vars bool The overwrite_vars field. False False True False
update_on_launch bool The update_on_launch field. False False True False
update_cache_timeout int The update_cache_timeout field. False False True False

API Specification

class tower_cli.resources.inventory_source.Resource(*args, **kwargs)[source]

A resource for inventory sources.

copy(pk=None, new_name=None, **kwargs)[source]

Copy an object.

Parameters:
  • pk (int) – Primary key of the resource object to be copied
  • new_name – The new name to give the resource if deep copying via the API
  • **kwargs – Keyword arguments of fields whose given value will override the original value.
Returns:

loaded JSON of the copied new resource object.

Return type:

dict

create(**kwargs)[source]

Create an object.

Parameters:
  • fail_on_found (bool) – Flag that if set, the operation fails if an object matching the unique criteria already exists.
  • force_on_exists (bool) – Flag that if set, then if a match is found on unique fields, other fields will be updated to the provided values.; If unset, a match causes the request to be a no-op.
  • **kwargs – Keyword arguments which, all together, will be used as POST body to create the resource object.
Returns:

A dictionary combining the JSON output of the created resource, as well as two extra fields: “changed”, a flag indicating if the resource is created successfully; “id”, an integer which is the primary key of the created object.

Return type:

dict

delete(pk=None, fail_on_missing=False, **kwargs)

Remove the given object.

Parameters:
  • pk (int) – Primary key of the resource to be deleted.
  • fail_on_missing (bool) – Flag that if set, the object’s not being found is considered a failure; otherwise, a success with no change is reported.
  • **kwargs – Keyword arguments used to look up resource object to delete if pk is not provided.
Returns:

dictionary of only one field “changed”, which is a flag indicating whether the specified resource is successfully deleted.

Return type:

dict

get(pk=None, **kwargs)

Retrieve one and exactly one object.

Parameters:
  • pk (int) – Primary key of the resource to be read. Tower CLI will only attempt to read that object if pk is provided (not None).
  • **kwargs – Keyword arguments used to look up resource object to retrieve if pk is not provided.
Returns:

loaded JSON of the retrieved resource object.

Return type:

dict

list(all_pages=False, **kwargs)

Retrieve a list of objects.

Parameters:
  • all_pages (bool) – Flag that if set, collect all pages of content from the API when returning results.
  • page (int) – The page to show. Ignored if all_pages is set.
  • query (list) – Contains 2-tuples used as query parameters to filter resulting resource objects.
  • **kwargs – Keyword arguments list of available fields used for searching resource objects.
Returns:

A JSON object containing details of all resource objects returned by Tower backend.

Return type:

dict

modify(pk=None, create_on_missing=False, **kwargs)[source]

Modify an already existing object.

Parameters:
  • pk (int) – Primary key of the resource to be modified.
  • create_on_missing (bool) – Flag that if set, a new object is created if pk is not set and objects matching the appropriate unique criteria is not found.
  • **kwargs – Keyword arguments which, all together, will be used as PATCH body to modify the resource object. if pk is not set, key-value pairs of **kwargs which are also in resource’s identity will be used to lookup existing reosource.
Returns:

A dictionary combining the JSON output of the modified resource, as well as two extra fields: “changed”, a flag indicating if the resource is successfully updated; “id”, an integer which is the primary key of the updated object.

Return type:

dict

monitor(pk, parent_pk=None, timeout=None, interval=0.5, outfile=<open file '<stdout>', mode 'w'>, **kwargs)

Stream the standard output from a job run to stdout.

Parameters:
  • pk (int) – Primary key of the job resource object to be monitored.
  • parent_pk (int) – Primary key of the unified job template resource object whose latest job run will be monitored if pk is not set.
  • timeout (float) – Number in seconds after which this method will time out.
  • interval (float) – Polling interval to refresh content from Tower.
  • outfile (file) – Alternative file than stdout to write job stdout to.
  • **kwargs – Keyword arguments used to look up job resource object to monitor if pk is not provided.
Returns:

A dictionary combining the JSON output of the finished job resource object, as well as two extra fields: “changed”, a flag indicating if the job resource object is finished as expected; “id”, an integer which is the primary key of the job resource object being monitored.

Return type:

dict

Raises:
status(pk, detail=False, **kwargs)[source]

Retrieve the current inventory update status.

Parameters:
  • pk (int) – Primary key of the resource to retrieve status from.
  • detail (bool) – Flag that if set, return the full JSON of the job resource rather than a status summary.
  • **kwargs – Keyword arguments used to look up resource object to retrieve status from if pk is not provided.
Returns:

full loaded JSON of the specified unified job if detail flag is on; trimed JSON containing only “elapsed”, “failed” and “status” fields of the unified job if detail flag is off.

Return type:

dict

update(inventory_source, monitor=False, wait=False, timeout=None, **kwargs)[source]

Update the given inventory source.

Parameters:
  • inventory_source (str) – Primary key or name of the inventory source to be updated.
  • monitor (bool) – Flag that if set, immediately calls monitor on the newly launched inventory update rather than exiting with a success.
  • wait (bool) – Flag that if set, monitor the status of the inventory update, but do not print while it is in progress.
  • timeout (int) – If provided with monitor flag set, this attempt will time out after the given number of seconds.
  • **kwargs – Fields used to override underlyingl inventory source fields when creating and launching an inventory update.
Returns:

Result of subsequent monitor call if monitor flag is on; Result of subsequent wait call if wait flag is on; dictionary of “status” if none of the two flags are on.

Return type:

dict

Raises:

tower_cli.exceptions.BadRequest – When the inventory source cannot be updated.

wait(pk, parent_pk=None, min_interval=1, max_interval=30, timeout=None, outfile=<open file '<stdout>', mode 'w'>, exit_on=['successful'], **kwargs)

Wait for a job resource object to enter certain status.

Parameters:
  • pk (int) – Primary key of the job resource object to wait.
  • parent_pk (int) – Primary key of the unified job template resource object whose latest job run will be waited if pk is not set.
  • timeout (float) – Number in seconds after which this method will time out.
  • min_interval (float) – Minimum polling interval to request an update from Tower.
  • max_interval (float) – Maximum polling interval to request an update from Tower.
  • outfile (file) – Alternative file than stdout to write job status updates on.
  • exit_on (array) – Job resource object statuses to wait on.
  • **kwargs – Keyword arguments used to look up job resource object to wait if pk is not provided.
Returns:

A dictionary combining the JSON output of the status-changed job resource object, as well as two extra fields: “changed”, a flag indicating if the job resource object is status-changed as expected; “id”, an integer which is the primary key of the job resource object being status-changed.

Return type:

dict

Raises: