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
Hashes for octopusdpy-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b377b6a1354314cea43602d754dee85e8caed6e5c9ec04ad346526c0cf82e1ce |
|
MD5 | e9247dc35e9dfe5b2020161601837fd0 |
|
BLAKE2b-256 | 76171671251897be5b7d0ca1880877a9e342a3548ab9e40c7a0b254577b2c68c |