DuploCtl
Duplo Ctl
This is the main IoC container for the Duplo CLI. It manages configuration, resources, clients, formatters, and models. HTTP and auth behavior live in pluggable client classes loaded via the client extension point system.
Using injected client to load a service.
Instantiation
These are a few static methods which instantiate new instances a few different ways. You can also just use the normal init constructor method to build it up manually.
__init__
DuploCtl Constructor
Creates an instance of a duplocloud client configured for a certain portal. All of the arguments are optional and can be set in the environment or in the config file. The types of each of the arguments are annotated types that are used by argparse to create the command line arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
HOST
|
The host of the Duplo instance. |
None
|
token
|
TOKEN
|
The token to use for authentication. |
None
|
tenant
|
TENANT
|
The tenant to use. |
None
|
tenant_id
|
TENANT_ID
|
The tenant id to use. |
None
|
home_dir
|
HOME_DIR
|
The home directory for the client. |
None
|
config_file
|
CONFIG
|
The config file for the client. |
None
|
cache_dir
|
CACHE_DIR
|
The cache directory for the client. |
None
|
version
|
VERSION
|
The version of the client. |
False
|
interactive
|
INTERACTIVE
|
The interactive mode for the client. |
False
|
ctx
|
CONTEXT
|
The context to use. |
None
|
nocache
|
NOCACHE
|
The nocache flag for the client. |
False
|
browser
|
BROWSER
|
The browser to use for interactive login. |
None
|
isadmin
|
ISADMIN
|
The admin flag for the client. |
False
|
query
|
QUERY
|
The query to use. |
None
|
output
|
OUTPUT
|
The output format for the client. |
'json'
|
loglevel
|
LOGLEVEL
|
The log level for the client. |
'WARN'
|
Returns:
| Name | Type | Description |
|---|---|---|
duplo |
DuploCtl
|
An instance of a DuploCtl. |
from_env
staticmethod
From Environment
Create a DuploCtl from environment variables. This is the most common way to create a DuploCtl.
Returns:
| Name | Type | Description |
|---|---|---|
duplo |
DuploCtl
|
An instance of a DuploCtl. |
from_args
staticmethod
DuploCtl from Arguments
Create a DuploCtl from an array of global client arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
str
|
An array of global client arguments aligning with the DuploCtl constructor. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
duplo |
DuploCtl
|
An instance of DuploCtl. |
from_creds
staticmethod
Create a DuploCtl from credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The host of the Duplo instance. |
required |
token
|
str
|
The token to use for authentication. |
required |
tenant
|
str
|
The tenant to use. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
duplo |
DuploCtl
|
The DuploCtl. |
Properties
These are the properties of the DuploCtl class.
token: str
property
writable
Token
Returns the configured token value from args/env/context. May be None.
host: str
property
Get Host
Get the host from the Duplo config. This is accessed as a lazy loaded property. If the host is some kind of falsey value, it will attempt to use the context.
Returns:
| Type | Description |
|---|---|
str
|
The host as a string. |
tenant: str
property
writable
Get Tenant
Get the tenant from the Duplo config. This is accessed as a lazy loaded property. If the tenant is some kind of falsey value, it will attempt to use the context.
Returns:
| Type | Description |
|---|---|
str
|
The tenant as a string. |
settings: dict
property
Get Config
Get the Duplo config as a dict. This is accessed as a lazy loaded property.
Returns:
| Name | Type | Description |
|---|---|---|
settings |
dict
|
The config as a dict. |
context: dict
property
Get Config Context
Get the current context from the Duplo config. This is accessed as a lazy loaded property.
Returns:
| Type | Description |
|---|---|
dict
|
The context as a dict. |
config: dict
property
Injection
Duploctl is a plugin framework which takes advantage of the Python entrypoints system in the pyproject.toml file. This allows you to inject your own custom classes into the DuploCtl class.
load
Load Resource
Load a resource class from the entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
The name of the service. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
kind |
T
|
The instantiated service with a reference to this client. |
load_client
Load Client
Load and cache a client singleton via the client extension point system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the client. |
'duplo'
|
Returns:
| Type | Description |
|---|---|
|
The client instance. |
load_formatter
Load Formatter
Load a Formatter function from the entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the format. |
'string'
|
Returns: The class of the format.
load_model
Load Model
Load a Pydantic model class by name from the duplocloud_sdk. Returns None if the model is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the Pydantic model class (e.g. "AddTenantRequest"). |
required |
Returns:
| Type | Description |
|---|---|
|
The Pydantic model class, or None if not found. |
Methods
format
Format data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
The data to format. |
required | |
output
|
str
|
The output format to use. Defaults to self.output. |
None
|
Returns: The formatted data as a string, or the raw data when output is None.
filter
Query data
Uses the jmespath library to query data. An explicit query override can be passed per invocation, otherwise falls back to the global self.query property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
The data to query. |
required | |
query
|
str
|
Optional JMESPath query override. |
None
|
Returns: The queried data.
jsonpatch
Json Patch
Apply a json patch to a resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
The patches to apply. |
required |
Returns: The patched resource as a JSON object.
validate_model
Validate Model
Validate data against a Pydantic model class. Takes the model class directly (not a name string). Does not check the global validate flag — callers decide when to call this. Raises DuploInvalidError if validation fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The Pydantic model class. |
required | |
data
|
dict
|
The dict to validate. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The validated and serialized dict. |
Raises:
| Type | Description |
|---|---|
DuploInvalidError
|
If the data fails model validation. |
use_context
Use Context
Use the specified context from the Duplo config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the context to use. |
None
|
logger_for
Create a Default Logger
Create a default logger for the given name. This will create a logger with the name 'duplo' and add a console output handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the logger. |
None
|
Returns: The logger.
build_command
Context Args
Build a comamnd using the current context.
Returns:
| Type | Description |
|---|---|
list[str]
|
The context args as a dict. |
__call__
Run a service command.
Choose a resource name and pass it's params in. Each resource has a unique set of arguments and therefore there is no need to try and define anything beyond a resource name and an optional query. Everything else is processed by the resource itself in it's own call method. Not all resources have commands and only execute their call method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
str
|
The name of the resource. |
None
|
args
|
The arguments to the resource. |
()
|
|
query
|
str
|
Optional JMESPath query override for this invocation. |
None
|
kwargs
|
Additional keyword arguments passed to the command. |
{}
|
Returns: The result of the command.