Python wrapper to support asynchronous acli commands.
Install the Acquia CLI.
pip install git+https://github.com/NCIOCPL/pyacli.git
At this point you can from pyacli import site_factory or the other modules in it.
For local development you can do an editable install:
pip install -e .
To authenticate you create a new instance of the SiteFactory class and pass in:
- Site Factory URI
- Username
- Key
You can have multiple Site Factory instances active at once and pyacli will ensure each one has the correct authentication before making calls.
from site_factory import SiteFactory
dev_auth = {
"ACSF_FACTORY_URI": os.environ["ACSF_DEV_FACTORY"],
"ACSF_USERNAME": os.environ["ACSF_DEV_USERNAME"],
"ACSF_KEY": os.environ["ACSF_DEV_KEY"],
}
dev_acli = site_factory.SiteFactory(**dev_auth)
test_auth = {
"ACSF_FACTORY_URI": os.environ["ACSF_TEST_FACTORY"],
"ACSF_USERNAME": os.environ["ACSF_TEST_USERNAME"],
"ACSF_KEY": os.environ["ACSF_TEST_KEY"],
}
test_acli = site_factory.SiteFactory(**test_auth)run is the workhorse method of SiteFactory and is designed to execute an acli acsf:* command for you.
Parameters:
**args: One or more ACSF commands with arguments as a tuple (e.g.["acsf:sites:clear-cache", "1"])**kwargsof options:verbose: Whether or not to print out information as it executeswait: IfTrueretrieves the task ID of the generated ACSF task and polls its status until completedinterval: If waiting, the interval to poll onmax_checks: If waiting, the max number of attempts at polling the status
# Run commands against multiple factories
dev_acli.run(
["acsf:sites:find"],
wait=False,
verbose=False
)
test_acli.run(
["acsf:sites:find"],
wait=False,
verbose=False
)
# Run one or more commands and wait for the tasks they create to complete
dev_acli.run(
["acsf:sites:clear-cache", "123"],
["acsf:sites:clear-cache", "456"],
interval=5, max_checks=10
)get_sites() is a shortcut method that will execute acli acsf:sites:find and return just the site names and IDs. If you pass it any site names as strings then it will filter the list for you.
# Get a list of all sites with IDs
print(dev_acli.get_sites())
# Filter to specific sites
print(dev_acli.get_sites("mysite1", "mysite2"))