marathon package

marathon.models

class marathon.models.app.MarathonApp(accepted_resource_roles=None, args=None, backoff_factor=None, backoff_seconds=None, cmd=None, constraints=None, container=None, cpus=None, dependencies=None, deployments=None, disk=None, env=None, executor=None, health_checks=None, id=None, instances=None, kill_selection=None, labels=None, last_task_failure=None, max_launch_delay_seconds=None, mem=None, ports=None, require_ports=None, store_urls=None, task_rate_limit=None, tasks=None, tasks_running=None, tasks_staged=None, tasks_healthy=None, task_kill_grace_period_seconds=None, tasks_unhealthy=None, upgrade_strategy=None, unreachable_strategy=None, uris=None, user=None, version=None, version_info=None, ip_address=None, fetch=None, task_stats=None, readiness_checks=None, readiness_check_results=None, secrets=None, port_definitions=None, residency=None, gpus=None, networks=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon Application resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps

Parameters:
  • accepted_resource_roles (list[str]) – a list of resource roles (the resource offer must contain at least one of these for the app to be launched on that host)
  • args (list[str]) – args form of the command to run
  • backoff_factor (int) – multiplier for subsequent backoff
  • backoff_seconds (int) – base time, in seconds, for exponential backoff
  • cmd (str) – cmd form of the command to run
  • constraints (list[marathon.models.constraint.MarathonConstraint] or list[tuple]) – placement constraints
  • container (marathon.models.container.MarathonContainer or dict) – container info
  • cpus (float) – cpus required per instance
  • dependencies (list[str]) – services (app IDs) on which this app depends
  • disk (int) – disk required per instance
  • deployments (list[marathon.models.deployment.MarathonDeployment]) – (read-only) currently running deployments that affect this app
  • env (dict) – env vars
  • executor (str) – executor
  • gpus (int) – gpus required per instance
  • health_checks (list[marathon.models.MarathonHealthCheck] or list[dict]) – health checks
  • id (str) – app id
  • instances (int) – instances
  • last_task_failure (marathon.models.app.MarathonTaskFailure or dict) – last task failure
  • mem (float) – memory (in MB) required per instance
  • secrets (dict) – A map with named secret declarations.
  • ports (list[int]) – ports
  • require_ports (bool) – require the specified ports to be available in the resource offer
  • store_urls (list[str]) – store URLs
  • task_rate_limit (float) – (Removed in Marathon 0.7.0) maximum number of tasks launched per second
  • tasks (list[marathon.models.task.MarathonTask]) – (read-only) tasks
  • tasks_running (int) – (read-only) the number of running tasks
  • tasks_staged (int) – (read-only) the number of staged tasks
  • tasks_healthy (int) – (read-only) the number of healthy tasks
  • tasks_unhealthy (int) – (read-only) the number of unhealthy tasks
  • upgrade_strategy (marathon.models.app.MarathonUpgradeStrategy or dict) – strategy by which app instances are replaced during a deployment
  • uris (list[str]) – uris
  • user (str) – user
  • version (str) – version id
  • version_info (marathon.models.app.MarathonAppVersionInfo or dict) – time of last scaling, last config change
  • task_stats (marathon.models.app.MarathonTaskStats or dict) – task statistics

:param dict labels :type readiness_checks: list[marathon.models.app.ReadinessCheck] or list[dict] :type residency: marathon.models.app.Residency or dict :param int task_kill_grace_period_seconds: Configures the termination signal escalation behavior of executors when stopping tasks. :param list[dict] unreachable_strategy: Handling for unreachable instances. :param str kill_selection: Defines which instance should be killed first in case of e.g. rescaling.

CREATE_ONLY_ATTRIBUTES = ['id', 'accepted_resource_roles']

List of attributes that should only be passed on creation

KILL_SELECTIONS = ['YOUNGEST_FIRST', 'OLDEST_FIRST']
READ_ONLY_ATTRIBUTES = ['deployments', 'tasks', 'tasks_running', 'tasks_staged', 'tasks_healthy', 'tasks_unhealthy']

List of read-only attributes

UPDATE_OK_ATTRIBUTES = ['args', 'backoff_factor', 'backoff_seconds', 'cmd', 'constraints', 'container', 'cpus', 'dependencies', 'disk', 'env', 'executor', 'gpus', 'health_checks', 'instances', 'kill_selection', 'labels', 'max_launch_delay_seconds', 'mem', 'ports', 'require_ports', 'store_urls', 'task_rate_limit', 'upgrade_strategy', 'unreachable_strategy', 'uris', 'user', 'version']

List of attributes which may be updated/changed after app creation

add_env(key, value)[source]
class marathon.models.app.MarathonAppVersionInfo(last_scaling_at=None, last_config_change_at=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon App version info.

See release notes for Marathon v0.11.0 https://github.com/mesosphere/marathon/releases/tag/v0.11.0

Parameters:
  • app_id (str) – application id
  • host (str) – mesos slave running the task
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
class marathon.models.app.MarathonHealthCheck(command=None, grace_period_seconds=None, interval_seconds=None, max_consecutive_failures=None, path=None, port_index=None, protocol=None, timeout_seconds=None, ignore_http1xx=None, **kwargs)[source]

Bases: marathon.models.base.MarathonObject

Marathon health check.

See https://mesosphere.github.io/marathon/docs/health-checks.html

Parameters:
  • command (str) – health check command (if protocol == ‘COMMAND’)
  • grace_period_seconds (int) – how long to ignore health check failures on initial task launch (before first healthy status)
  • interval_seconds (int) – how long to wait between health checks
  • max_consecutive_failures (int) – max number of consecutive failures before the task should be killed
  • path (str) – health check target path (if protocol == ‘HTTP’)
  • port_index (int) – target port as indexed in app’s ports array
  • protocol (str) – health check protocol (‘HTTP’, ‘TCP’, or ‘COMMAND’)
  • timeout_seconds (int) – how long before a waiting health check is considered failed
  • ignore_http1xx (bool) – Ignore HTTP informational status codes 100 to 199.
  • kwargs (dict) – additional arguments for forward compatibility
class marathon.models.app.MarathonTaskFailure(app_id=None, host=None, message=None, task_id=None, instance_id=None, slave_id=None, state=None, timestamp=None, version=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon Task Failure.

Parameters:
  • app_id (str) – application id
  • host (str) – mesos slave running the task
  • message (str) – error message
  • task_id (str) – task id
  • instance_id (str) – instance id
  • state (str) – task state
  • timestamp (datetime or str) – when this task failed
  • version (str) – app version with which this task was started
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
class marathon.models.app.MarathonTaskStats(started_after_last_scaling=None, with_latest_config=None, with_outdated_config=None, total_summary=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon task statistics

See https://mesosphere.github.io/marathon/docs/rest-api.html#taskstats-object-v0-11

Parameters:
class marathon.models.app.MarathonTaskStatsCounts(staged=None, running=None, healthy=None, unhealthy=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon app task counts

Equivalent to tasksStaged, tasksRunning, tasksHealthy, tasksUnhealthy.

Parameters:
  • staged (int) – Staged task count
  • running (int) – Running task count
  • healthy (int) – Healthy task count
  • unhealthy (int) – unhealthy task count
class marathon.models.app.MarathonTaskStatsLifeTime(average_seconds=None, median_seconds=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon app life time statistics

Measured from “startedAt” (timestamp of the Mesos TASK_RUNNING status update) of each running task until now

Parameters:
  • average_seconds (float) – Average seconds
  • median_seconds (float) – Median seconds
class marathon.models.app.MarathonTaskStatsStats(counts=None, life_time=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon app task stats

Parameters:
class marathon.models.app.MarathonTaskStatsType(stats=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon app task stats

Parameters:stats (marathon.models.app.MarathonTaskStatsStats or dict) – stast about app tasks
class marathon.models.app.MarathonUnreachableStrategy(unreachable_inactive_after_seconds=None, unreachable_expunge_after_seconds=None, inactive_after_seconds=None, expunge_after_seconds=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon unreachable Strategy.

Define handling for unreachable instances. Given unreachable_inactive_after_seconds = 60 and unreachable_expunge_after = 120, an instance will be expunged if it has been unreachable for more than 120 seconds or a second instance is started if it has been unreachable for more than 60 seconds.”,

See https://mesosphere.github.io/marathon/docs/?

Parameters:
  • unreachable_inactive_after_seconds (int) – time an instance is unreachable for in seconds before marked as inactive.
  • unreachable_expunge_after_seconds (int) – time an instance is unreachable for in seconds before expunged.

:param int inactive_after_seconds :param int expunge_after_seconds

DISABLED = 'disabled'
classmethod from_json(attributes)[source]
class marathon.models.app.MarathonUpgradeStrategy(maximum_over_capacity=None, minimum_health_capacity=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon health check.

See https://mesosphere.github.io/marathon/docs/health-checks.html

Parameters:minimum_health_capacity (float) – minimum % of instances kept healthy on deploy
class marathon.models.app.PortDefinition(port=None, protocol=None, name=None, labels=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon port definitions: https://mesosphere.github.io/marathon/docs/ports.html

Parameters:
  • port (int) – The port
  • protocol (string) – tcp or udp
  • name (string) – (optional) the name of the port
  • labels (dict) – undocumented
class marathon.models.app.ReadinessCheck(name=None, protocol=None, path=None, port_name=None, interval_seconds=None, http_status_codes_for_ready=None, preserve_last_response=None, timeout_seconds=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon readiness check: https://mesosphere.github.io/marathon/docs/readiness-checks.html

Parameters:
  • name (Optional. Default (string) – “readinessCheck”): The name used to identify this readiness check.
  • protocol (Optional. Default (string) – “HTTP”): Protocol of the requests to be performed. Either HTTP or HTTPS.
  • path (Optional. Default (string) – “/”): Path to the endpoint the task exposes to provide readiness status. Example: /path/to/readiness.
  • port_name (Optional. Default (string) – “http-api”): Name of the port to query as described in the portDefinitions. Example: http-api.
  • interval_seconds (Optional. Default (int) – 30 seconds): Number of seconds to wait between readiness checks.
  • timeout_seconds (Optional. Default (int) – 10 seconds): Number of seconds after which a readiness check times out, regardless of the response. This value must be smaller than interval_seconds.
  • http_status_codes_for_ready (Optional. Default (list) – [200]): The HTTP/HTTPS status code to treat as ready.
  • preserve_last_response (Optional. Default (bool) – false): If true, the last readiness check response will be preserved and exposed in the API as part of a deployment.
class marathon.models.app.Residency(relaunch_escalation_timeout_seconds=None, task_lost_behavior=None)[source]

Bases: marathon.models.base.MarathonObject

Declares how “resident” an app is: https://mesosphere.github.io/marathon/docs/persistent-volumes.html

Parameters:
  • relaunch_escalation_timeout_seconds (int) – How long marathon will try to relaunch where the volumes is, defaults to 3600
  • task_lost_behavior (string) – What to do after a TASK_LOST. See the official Marathon docs for options
class marathon.models.app.Secret(source=None)[source]

Bases: marathon.models.base.MarathonObject

Declares marathon secret object. :param str source: The source of the secret’s value. The format depends on the secret store used by Mesos.

class marathon.models.base.MarathonObject[source]

Bases: object

Base Marathon object.

classmethod from_json(attributes)[source]

Construct an object from a parsed response.

Parameters:attributes (dict) – object attributes from parsed response
json_repr(minimal=False)[source]

Construct a JSON-friendly representation of the object.

Parameters:minimal (bool) – Construct a minimal representation of the object (ignore nulls and empty collections)
Return type:dict
to_json(minimal=True)[source]

Encode an object as a JSON string.

Parameters:minimal (bool) – Construct a minimal representation of the object (ignore nulls and empty collections)
Return type:str
class marathon.models.base.MarathonResource[source]

Bases: marathon.models.base.MarathonObject

Base Marathon resource.

marathon.models.base.assert_valid_id(id)[source]

Checks if an id is the correct format that Marathon expects. Raises ValueError if not valid.

Parameters:id (str) – App or group id.
Return type:str
marathon.models.base.assert_valid_path(path)[source]

Checks if a path is a correct format that Marathon expects. Raises ValueError if not valid.

Parameters:path (str) – The app id.
Return type:str
class marathon.models.constraint.MarathonConstraint(field, operator, value=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon placement constraint.

See https://mesosphere.github.io/marathon/docs/constraints.html

Parameters:
  • field (str) – constraint operator target
  • operator (str) – must be one of [UNIQUE, CLUSTER, GROUP_BY, LIKE, UNLIKE]
  • value – [optional] if operator is CLUSTER, constrain tasks to servers where field == value.

If operator is GROUP_BY, place at most value tasks per group. If operator is LIKE or UNLIKE, filter servers using regexp. :type value: str, int, or None

classmethod from_json(obj)[source]

Construct a MarathonConstraint from a parsed response.

Parameters:attributes (dict) – object attributes from parsed response
Return type:MarathonConstraint
json_repr(minimal=False)[source]

Construct a JSON-friendly representation of the object.

Parameters:minimal (bool) – [ignored]
Return type:list
class marathon.models.container.MarathonContainer(docker=None, type='DOCKER', volumes=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon health check.

See https://mesosphere.github.io/marathon/docs/native-docker.html

Parameters:
TYPES = ['DOCKER', 'MESOS']

Valid container types

class marathon.models.container.MarathonContainerPortMapping(name=None, container_port=None, host_port=0, service_port=None, protocol='tcp', labels=None)[source]

Bases: marathon.models.base.MarathonObject

Container port mapping.

See https://mesosphere.github.io/marathon/docs/native-docker.html

Parameters:
  • name (str) –
  • container_port (int) –
  • host_port (int) –
  • protocol (str) –
  • labels (object) –
PROTOCOLS = ['tcp', 'udp']

Valid protocols

class marathon.models.container.MarathonContainerVolume(container_path=None, host_path=None, mode='RW', persistent=None, external=None)[source]

Bases: marathon.models.base.MarathonObject

Volume options.

See https://mesosphere.github.io/marathon/docs/native-docker.html

Parameters:
  • container_path (str) – container path
  • host_path (str) – host path
  • mode (str) – one of [‘RO’, ‘RW’]
  • persistent (object) – persistent volume options, should be of the form {‘size’: 1000}
  • external (object) – external volume options
MODES = ['RO', 'RW']
class marathon.models.container.MarathonDockerContainer(image=None, network='HOST', port_mappings=None, parameters=None, privileged=None, force_pull_image=None, **kwargs)[source]

Bases: marathon.models.base.MarathonObject

Docker options.

See https://mesosphere.github.io/marathon/docs/native-docker.html

Parameters:
  • image (str) – docker image
  • network (str) –
  • port_mappings (list[marathon.models.container.MarathonContainerPortMapping] or list[dict]) –
  • parameters (list[dict]) –
  • privileged (bool) – run container in privileged mode
  • force_pull_image (bool) – Force a docker pull before launching
NETWORK_MODES = ['BRIDGE', 'HOST', 'NONE']

Valid network modes

class marathon.models.deployment.MarathonDeployment(affected_apps=None, current_actions=None, current_step=None, id=None, steps=None, total_steps=None, version=None, affected_pods=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon Application resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#deployments
https://mesosphere.github.io/marathon/docs/generated/api.html#v2_deployments_get
Parameters:
parse_deployment_step(step)[source]
class marathon.models.deployment.MarathonDeploymentAction(action=None, app=None, apps=None, type=None, readiness_check_results=None, pod=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon Application resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#deployments

Parameters:
class marathon.models.deployment.MarathonDeploymentOriginalState(dependencies=None, apps=None, id=None, version=None, groups=None, pods=None)[source]

Bases: marathon.models.base.MarathonObject

class marathon.models.deployment.MarathonDeploymentPlan(original=None, target=None, steps=None, id=None, version=None)[source]

Bases: marathon.models.base.MarathonObject

class marathon.models.deployment.MarathonDeploymentStep(actions=None)[source]

Bases: marathon.models.base.MarathonObject

class marathon.models.deployment.MarathonDeploymentTargetState(groups=None, apps=None, dependencies=None, id=None, version=None, pods=None)[source]

Bases: marathon.models.base.MarathonObject

class marathon.models.endpoint.MarathonEndpoint(app_id=None, service_port=None, host=None, task_id=None, task_port=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon Endpoint helper object for service discovery. It describes a single port mapping for a running task.

Parameters:
  • app_id (str) – application id
  • host (str) – mesos slave running the task
  • task_id (str) – task id
  • service_port (int) – application service port
  • task_port (int) – port allocated on the slave
classmethod from_tasks(tasks)[source]

Construct a list of MarathonEndpoints from a list of tasks.

:param list[marathon.models.MarathonTask] tasks: list of tasks to parse

Return type:list[MarathonEndpoint]
class marathon.models.group.MarathonGroup(apps=None, dependencies=None, groups=None, id=None, pods=None, version=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon group resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#groups

Parameters:
class marathon.models.info.MarathonConfig(checkpoint=None, executor=None, failover_timeout=None, framework_name=None, ha=None, hostname=None, leader_proxy_connection_timeout_ms=None, leader_proxy_read_timeout_ms=None, local_port_min=None, local_port_max=None, master=None, mesos_leader_ui_url=None, mesos_role=None, mesos_user=None, webui_url=None, reconciliation_initial_delay=None, reconciliation_interval=None, task_launch_timeout=None, marathon_store_timeout=None, task_reservation_timeout=None, features=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon config resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/info

Parameters:
  • checkpoint (bool) –
  • executor (str) –
  • failover_timeout (int) –
  • features (type) – Undocumented object
  • framework_name (str) –
  • ha (bool) –
  • hostname (str) –
  • leader_proxy_connection_timeout_ms (int) –
  • leader_proxy_read_timeout_ms (int) –
  • local_port_min (int) –
  • local_port_max (int) –
  • master (str) –
  • mesos_leader_ui_url (str) –
  • mesos_role (str) –
  • mesos_user (str) –
  • webui_url (str) –
  • reconciliation_initial_delay (int) –
  • reconciliation_interval (int) –
  • task_launch_timeout (int) –
  • task_reservation_timeout (int) –
  • marathon_store_timeout (int) –
class marathon.models.info.MarathonEventSubscriber(type=None, http_endpoints=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon event subscriber resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/info

Parameters:
  • type (str) –
  • http_endpoints (list[str]) –
class marathon.models.info.MarathonHttpConfig(assets_path=None, http_port=None, https_port=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon http config resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/info

Parameters:
  • assets_path (str) –
  • http_port (int) –
  • https_port (int) –
class marathon.models.info.MarathonInfo(event_subscriber=None, framework_id=None, http_config=None, leader=None, marathon_config=None, name=None, version=None, elected=None, zookeeper_config=None, buildref=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon Info.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#get-v2-info Also: https://mesosphere.github.io/marathon/docs/generated/api.html#v2_info_get

Parameters:
class marathon.models.info.MarathonZooKeeperConfig(zk=None, zk_future_timeout=None, zk_hosts=None, zk_max_versions=None, zk_path=None, zk_session_timeout=None, zk_state=None, zk_timeout=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon zookeeper config resource.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/info

Parameters:
  • zk (str) –
  • zk_future_timeout (dict) –
  • zk_hosts (str) –
  • zk_max_versions (str) –
  • zk_path (str) –
  • zk_session_timeout (str) –
  • zk_state (str) –
  • zk_timeout (int) –
class marathon.models.queue.MarathonQueueItem(app=None, overdue=None, count=None, delay=None, since=None, processed_offers_summary=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon queue item.

See: https://mesosphere.github.io/marathon/docs/rest-api.html#queue

List all the tasks queued up or waiting to be scheduled. This is mainly used for troubleshooting and occurs when scaling changes are requested and the volume of scaling changes out paces the ability to schedule those tasks. In addition to the application in the queue, you see also the task count that needs to be started.

If the task has a rate limit, then a delay to the start gets applied. You can see this delay for every application with the seconds to wait before the next launch will be tried.

Parameters:
class marathon.models.queue.MarathonQueueItemDelay(time_left_seconds=None, overdue=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon queue item delay.

Parameters:
  • time_left_seconds (int) – Seconds to wait before the next launch will be tried.
  • overdue (bool) – Is the queue item overdue.
class marathon.models.task.MarathonHealthCheckResult(alive=None, consecutive_failures=None, first_success=None, last_failure=None, last_success=None, task_id=None, last_failure_cause=None, instance_id=None)[source]

Bases: marathon.models.base.MarathonObject

Marathon health check result.

See https://mesosphere.github.io/marathon/docs/health-checks.html

Parameters:
  • alive (bool) – boolean to determine task health
  • consecutive_failures (int) – number of failed healthchecks in a row
  • first_success (str) – first time when which healthcheck succeeded
  • last_failure (str) – last time when which healthcheck failed
  • last_failure_cause (str) – cause for last failure
  • last_success (str) – last time when which healthcheck succeeded
  • task_id (str) – task id
  • instance_id (str) – instance id
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
class marathon.models.task.MarathonIpAddress(ip_address=None, protocol=None)[source]

Bases: marathon.models.base.MarathonObject

class marathon.models.task.MarathonTask(app_id=None, health_check_results=None, host=None, id=None, ports=None, service_ports=None, slave_id=None, staged_at=None, started_at=None, version=None, ip_addresses=[], state=None, local_volumes=None)[source]

Bases: marathon.models.base.MarathonResource

Marathon Task resource.

Parameters:
  • app_id (str) – application id
  • health_check_results (list[marathon.models.MarathonHealthCheckResult] or list[dict]) – health check results
  • host (str) – mesos slave running the task
  • id (str) – task id
  • ports (list[int]) – allocated ports
  • service_ports (list[int]) – ports exposed for load balancing
  • state (str) – State of the task e.g. TASK_RUNNING
  • slave_id (str) – Mesos slave id
  • staged_at (datetime or str) – when this task was staged
  • started_at (datetime or str) – when this task was started
  • version (str) – app version with which this task was started
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'

marathon.client

class marathon.client.MarathonClient(servers, username=None, password=None, timeout=10, session=None, auth_token=None, verify=True)[source]

Bases: object

Client interface for the Marathon REST API.

create_app(app_id, app)[source]

Create and start an app.

Parameters:app_id (str) – application ID

:param marathon.models.app.MarathonApp app: the application to create

Returns:the created app (on success)
Return type:marathon.models.app.MarathonApp or False
create_event_subscription(url)[source]

Register a callback URL as an event subscriber.

Parameters:url (str) – callback URL
Returns:the created event subscription
Return type:dict
create_group(group)[source]

Create and start a group.

:param marathon.models.group.MarathonGroup group: the group to create

Returns:success
Return type:dict containing the version ID
delete_app(app_id, force=False)[source]

Stop and destroy an app.

Parameters:
  • app_id (str) – application ID
  • force (bool) – apply even if a deployment is in progress
Returns:

a dict containing the deployment id and version

Return type:

dict

delete_deployment(deployment_id, force=False)[source]

Cancel a deployment.

Parameters:
  • deployment_id (str) – deployment id
  • force (bool) – if true, don’t create a rollback deployment to restore the previous configuration
Returns:

a dict containing the deployment id and version (empty dict if force=True)

Return type:

dict

delete_event_subscription(url)[source]

Deregister a callback URL as an event subscriber.

Parameters:url (str) – callback URL
Returns:the deleted event subscription
Return type:dict
delete_group(group_id, force=False)[source]

Stop and destroy a group.

Parameters:
  • group_id (str) – group ID
  • force (bool) – apply even if a deployment is in progress
Returns:

a dict containing the deleted version

Return type:

dict

delete_leader()[source]

Causes the current leader to abdicate, triggers a new election.

Returns:message saying leader abdicated
Return type:dict
event_stream(raw=False)[source]

Polls event bus using /v2/events

Parameters:raw (bool) – if true, yield raw event text, else yield MarathonEvent object
Returns:iterator with events
Return type:iterator
get_app(app_id, embed_tasks=False, embed_counts=False, embed_deployments=False, embed_readiness=False, embed_last_task_failure=False, embed_failures=False, embed_task_stats=False)[source]

Get a single app.

Parameters:
  • app_id (str) – application ID
  • embed_tasks (bool) – embed tasks in result
  • embed_counts (bool) – embed all task counts
  • embed_deployments (bool) – embed all deployment identifier
  • embed_readiness (bool) – embed all readiness check results
  • embed_last_task_failure (bool) – embeds the last task failure
  • embed_failures (bool) – shorthand for embed_last_task_failure
  • embed_task_stats (bool) – embed task stats in result
Returns:

application

Return type:

marathon.models.app.MarathonApp

get_group(group_id)[source]

Get a single group.

Parameters:group_id (str) – group ID
Returns:group
Return type:marathon.models.group.MarathonGroup
get_info()[source]

Get server configuration information.

Returns:server config info
Return type:marathon.models.info.MarathonInfo
get_leader()[source]

Get the current marathon leader.

Returns:leader endpoint
Return type:dict
get_metrics()[source]

Get server metrics

Returns:metrics dict
Return type:dict
get_version(app_id, version)[source]

Get the configuration of an app at a specific version.

Parameters:
  • app_id (str) – application ID
  • version (str) – application version
Returns:

application configuration

Return type:

marathon.models.app.MarathonApp

kill_given_tasks(task_ids, scale=False, force=None)[source]

Kill a list of given tasks.

Parameters:
  • task_ids (list[str]) – tasks to kill
  • scale (bool) – if true, scale down the app by the number of tasks killed
  • force (bool) – if true, ignore any current running deployments
Returns:

True on success

Return type:

bool

kill_task(app_id, task_id, scale=False, wipe=False)[source]

Kill a task.

Parameters:
  • app_id (str) – application ID
  • task_id (str) – the task to kill
  • scale (bool) – if true, scale down the app by one if the task exists
Returns:

the killed task

Return type:

marathon.models.task.MarathonTask

kill_tasks(app_id, scale=False, wipe=False, host=None, batch_size=0, batch_delay=0)[source]

Kill all tasks belonging to app.

Parameters:
  • app_id (str) – application ID
  • scale (bool) – if true, scale down the app by the number of tasks killed
  • host (str) – if provided, only terminate tasks on this Mesos slave
  • batch_size (int) – if non-zero, terminate tasks in groups of this size
  • batch_delay (int) – time (in seconds) to wait in between batched kills. If zero, automatically determine
Returns:

list of killed tasks

Return type:

list[marathon.models.task.MarathonTask]

list_apps(cmd=None, embed_tasks=False, embed_counts=False, embed_deployments=False, embed_readiness=False, embed_last_task_failure=False, embed_failures=False, embed_task_stats=False, app_id=None, **kwargs)[source]

List all apps.

Parameters:
  • cmd (str) – if passed, only show apps with a matching cmd
  • embed_tasks (bool) – embed tasks in result
  • embed_counts (bool) – embed all task counts
  • embed_deployments (bool) – embed all deployment identifier
  • embed_readiness (bool) – embed all readiness check results
  • embed_last_task_failure (bool) – embeds the last task failure
  • embed_failures (bool) – shorthand for embed_last_task_failure
  • embed_task_stats (bool) – embed task stats in result
  • app_id (str) – if passed, only show apps with an ‘id’ that matches or contains this value
  • kwargs – arbitrary search filters
Returns:

list of applications

Return type:

list[marathon.models.app.MarathonApp]

list_deployments()[source]

List all running deployments.

Returns:list of deployments
Return type:list[marathon.models.deployment.MarathonDeployment]
list_endpoints()[source]

List the current endpoints for all applications

Returns:list of endpoints
Return type:list[MarathonEndpoint]
list_event_subscriptions()[source]

List the event subscriber callback URLs.

Returns:list of callback URLs
Return type:list[str]
list_groups(**kwargs)[source]

List all groups.

Parameters:kwargs – arbitrary search filters
Returns:list of groups
Return type:list[marathon.models.group.MarathonGroup]
list_queue()[source]

List all the tasks queued up or waiting to be scheduled.

Returns:list of queue items
Return type:list[marathon.models.queue.MarathonQueueItem]
list_tasks(app_id=None, **kwargs)[source]

List running tasks, optionally filtered by app_id.

Parameters:
  • app_id (str) – if passed, only show tasks for this application
  • kwargs – arbitrary search filters
Returns:

list of tasks

Return type:

list[marathon.models.task.MarathonTask]

list_versions(app_id)[source]

List the versions of an app.

Parameters:app_id (str) – application ID
Returns:list of versions
Return type:list[str]
ping()[source]

Ping the Marathon server.

Returns:the text response
Return type:str
restart_app(app_id, force=False)[source]

Restarts given application by app_id :param str app_id: application ID :param bool force: apply even if a deployment is in progress :returns: a dict containing the deployment id and version :rtype: dict

rollback_app(app_id, version, force=False)[source]

Roll an app back to a previous version.

Parameters:
  • app_id (str) – application ID
  • version (str) – application version
  • force (bool) – apply even if a deployment is in progress
Returns:

a dict containing the deployment id and version

Return type:

dict

rollback_group(group_id, version, force=False)[source]

Roll a group back to a previous version.

Parameters:
  • group_id (str) – group ID
  • version (str) – group version
  • force (bool) – apply even if a deployment is in progress
Returns:

a dict containing the deployment id and version

Return type:

dict

scale_app(app_id, instances=None, delta=None, force=False)[source]

Scale an app.

Scale an app to a target number of instances (with instances), or scale the number of instances up or down by some delta (delta). If the resulting number of instances would be negative, desired instances will be set to zero.

If both instances and delta are passed, use instances.

Parameters:
  • app_id (str) – application ID
  • instances (int) – [optional] the number of instances to scale to
  • delta (int) – [optional] the number of instances to scale up or down by
  • force (bool) – apply even if a deployment is in progress
Returns:

a dict containing the deployment id and version

Return type:

dict

scale_group(group_id, scale_by)[source]

Scale a group by a factor.

Parameters:
  • group_id (str) – group ID
  • scale_by (int) – factor to scale by
Returns:

a dict containing the deployment id and version

Return type:

dict

update_app(app_id, app, force=False, minimal=True)[source]

Update an app.

Applies writable settings in app to app_id Note: this method can not be used to rename apps.

Parameters:
  • app_id (str) – target application ID
  • app (marathon.models.app.MarathonApp) – application settings
  • force (bool) – apply even if a deployment is in progress
  • minimal (bool) – ignore nulls and empty collections
Returns:

a dict containing the deployment id and version

Return type:

dict

update_apps(apps, force=False, minimal=True)[source]

Update multiple apps.

Applies writable settings in elements of apps either by upgrading existing ones or creating new ones

Parameters:
  • apps – sequence of application settings
  • force (bool) – apply even if a deployment is in progress
  • minimal (bool) – ignore nulls and empty collections
Returns:

a dict containing the deployment id and version

Return type:

dict

update_group(group_id, group, force=False, minimal=True)[source]

Update a group.

Applies writable settings in group to group_id Note: this method can not be used to rename groups.

Parameters:
  • group_id (str) – target group ID
  • group (marathon.models.group.MarathonGroup) – group settings
  • force (bool) – apply even if a deployment is in progress
  • minimal (bool) – ignore nulls and empty collections
Returns:

a dict containing the deployment id and version

Return type:

dict

marathon.exceptions

exception marathon.exceptions.InternalServerError(response)[source]

Bases: marathon.exceptions.MarathonHttpError

exception marathon.exceptions.InvalidChoiceError(param, value, options)[source]

Bases: marathon.exceptions.MarathonError

exception marathon.exceptions.MarathonError[source]

Bases: exceptions.Exception

exception marathon.exceptions.MarathonHttpError(response)[source]

Bases: marathon.exceptions.MarathonError

exception marathon.exceptions.NotFoundError(response)[source]

Bases: marathon.exceptions.MarathonHttpError

Module contents