Simple library for interacting with Octopus
Project description
octopusdpy
WIP Python package for interacting with Octopus Deploy's API. Currently this provides for read only access.
Usage
You'll need two items:
- octopusdpy_url: The URL used to interact with your instance of octopusdpy.
- api_key: An API key used to authenticate with octopusdpy.
import octopusdpy
octopusdpy_api = octopusdpy.API(octopusdpy_url="XXX", api_key="YYY")
When the octopusdpy API returns multiple values an iterator is used:
A new item is returned each iteration. The iterator is exhausted once all items have been returned from the API.
environments = api.get_environments():
for environment in environments:
print(environment.Name)
You can do simple gathering of information like:
Get all the machines assigned to an environment and the roles of those machines.
import octopusdpy
api = octopusdpy.API("XXX", "YYY")
environment_pages = api.get_environments()
for environments in environment_pages:
for environment in environments:
machine_pages = environment.machines
for machines in machine_pages:
for machine in machines:
print(environment.Name, machine.Name, machine.Roles)
Clone a Library Variable Set
source_library_variable_set = api.get_library_variable_set('LibraryVariableSets-123')
destination_library_variable_set = api.get_library_variable_set('LibraryVariableSets-456')
source_variable_set = source_library_variable_set.variable_set
destination_variable_set = destination_library_variable_set.variable_set
destination_variable_set.Variables = source_variable_set.Variables
destination_variable_set.save()
Find all your long running currently executing tasks
from datetime import datetime, timezone
now = datetime.now(timezone.utc)
tasks = api.get_tasks({'states':'executing'})
for task in tasks:
time_delta = now - task.start_time
if time_delta.total_seconds() > 86400:
hours, remainder = divmod(time_delta.total_seconds(), 3600)
minutes, seconds = divmod(remainder, 60)
print(task.Id, task.Description, f"{hours} hours, {minutes} minutes")
Find all the variables in a Library Variable Set that are scoped to a role
import octopusdpy
import re
nightly_re = re.compile(r'.*nightly.*', re.IGNORECASE)
library_variable_set = api.get_library_variable_set('LibraryVariableSets-123')
variable_set = library_variable_set.variable_set
for variable in variable_set.Variables:
roles = variable['Scope'].get('Role', [])
for role in roles:
if nightly_re.match(role):
print(variable)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file octopusdpy-0.0.3.tar.gz.
File metadata
- Download URL: octopusdpy-0.0.3.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1743a9c1e06c0ac3b120b8539746e5caf57b9c2989d13664251ef27f8a04e763
|
|
| MD5 |
55ee683019a6ab83d1288da1888347e0
|
|
| BLAKE2b-256 |
c6f97c4191ab7e80e668df026b1b7582d8e90fcad761fabd0204dcb90379748f
|
File details
Details for the file octopusdpy-0.0.3-py3-none-any.whl.
File metadata
- Download URL: octopusdpy-0.0.3-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b377b6a1354314cea43602d754dee85e8caed6e5c9ec04ad346526c0cf82e1ce
|
|
| MD5 |
e9247dc35e9dfe5b2020161601837fd0
|
|
| BLAKE2b-256 |
76171671251897be5b7d0ca1880877a9e342a3548ab9e40c7a0b254577b2c68c
|