Controller Instance¶
This class object is for Controller type Instances providing the endpoints specific to it’s type. This object is used to control all instances it has access to similar to main panel of your AMP.
- class ampapi.AMPControllerInstance[source]¶
The AMPControllerInstance class is the top most level of Instances inside of AMP. This has access the Target ADS and all Instances it can see.
Note
All API Endpoints an AMP Controller Instance would have access to this class object does too.
- property instances: set[AMPADSInstance | AMPInstance | AMPMinecraftInstance]¶
Represents all Instances the
AMPControllerInstancecan see, these are transferred fromavailable_instance.Note
Similar to
available_instancebut converted into a type ofAMPInstanceclasses that have API functions.The set of
AMPInstancetypes will be ordered byinstance_id.- Returns:
A set of converted
Instanceclasses sorted byinstance_id.- Return type:
set[Union[
AMPADSInstance,AMPInstance,AMPMinecraftInstance]]
- instance_conversion(instances: Iterable[Instance]) set[AMPInstance | AMPMinecraftInstance | AMPADSInstance][source]¶
Takes a set of
Instancedataclasses and turns them intoAMPInstance,AMPMinecraftInstanceand orAMPADSInstancerespectively to facilitate API function accessibility.Note
By default the list of instances will be sorted.
- Parameters:
instances (Iterable[
Instance]) – An Iterable ofInstancedataclasses.- Returns:
The set of converted
Instanceobjects.- Return type:
set[Union[
AMPInstance,AMPMinecraftInstance,AMPADSInstance]]
- async get_instances(include_self: bool = True, format_data: bool | None = None) set[AMPInstance | AMPMinecraftInstance | AMPADSInstance] | Iterable[Controller | Instance][source]¶
This function is a coroutine.
Returns a set of converted
InstancestoAMPInstance,AMPMinecraftInstanceandAMPADSInstance.Note
If
format_data==Falsethis will return the list ofControllerand orInstancedataclasses instead.Warning
This will be only Instances the AMP Controller and AMP User has permission to access.
- Parameters:
format_data (Union[
bool, None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant if None), by default None.- Returns:
On success returns a set of
AMPInstance,AMPMinecraftInstanceand orAMPADSInstancedataclasses.- Return type:
Union[set[Union[
AMPInstance,AMPMinecraftInstance,AMPADSInstance]], list[Union[Controller,Instance]]]
Generic Instance¶
This class object is for Generic type Instances providing the endpoints specific to it’s type.
- class ampapi.AMPInstance(data: Instance | None, controller: AMPControllerInstance | None = None)[source]¶
AMPInstancerepresents an entire Instance from AMP that is not AMP Controller, AMP Target/ADS or Minecraft.This is similar to what you get when selecting ‘Manage’ an instance from the Web GUI.
Note
Do NOT change the
moduleattribute.Attributes are cached! Please call the respective Endpoints to get current information.
To Update the attributes call
get_instance_status()orget_updates().To check if the Instance is running, check the
runningproperty.To check if the Application is running, check the
app_stateproperty.
- Parameters:
data (Union[
Instance, None]) – The Instance data to be unpacked and set as attributes of this class to execute API calls.controller (Union[
AMPControllerInstance, None]) – TheAMPControllerInstanceto be used to execute specific API calls.
- get_application_status(format_data: bool | None = None) InstanceStatus[source]¶
This function is a coroutine.
Gets the AMP Instance Application Status information and updates the class properties(State, Uptime and Metrics)
Note
The Instance MUST be running (
running = True) or you will get aConnectionError- Parameters:
format_data (Union[
bool, None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant if None), by default None.- Raises:
ConnectionError – The requested instance is not available at this time if the Instance is not running.
- Returns:
On success returns a
AppStatusdataclass.- Return type:
AppStatus
- get_instance_status() AMPInstance | AMPMinecraftInstance[source]¶
This function is a coroutine.
Requests the recent changes to the Instance, updates our
selfobject and returns the updated object.Note
Typical usage is to get current information pertaining to an Instance and keeping it updated.
Warning
This only applies if you are manually creating these classes.
You must have a
AMPControllerInstancegenerated and set to_controllerfirst. See__init__()
- Raises:
RuntimeError – If the
_controllerattribute has not been set.- Returns:
Returns an updated
selfobject.- Return type:
Union[
AMPInstance,AMPMinecraftInstance]
- get_updates(format_data: bool | None = None) Updates[source]¶
This function is a coroutine.
Requests the recent Console entries of the Instance, will acquire all updates from previous API call of
get_updates()and updates parses the information setting it toself. SeeUpdatesfor attribute access.Note
The Instance MUST be running (
running = True) or you will get aConnectionError- Parameters:
format_data (Union[
bool,None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant ifNone), by defaultNone- Raises:
ConnectionError – If the
runningis False.RuntimeError – If the
_controllerattribute has not been set.
- Returns:
On success returns a
Updatesdataclass.- Return type:
Updates
- start_instance(format_data: bool | None = None) ActionResult[source]¶
This function is a coroutine.
Start the Instance.
Warning
This only applies if you are manually creating these classes.
You must have a
AMPControllerInstancegenerated and set to_controllerfirst. See__init__()
- Parameters:
format_data (Union[
bool, None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant if None), by default None.- Raises:
RuntimeError – If the
_controllerattribute has not been set.- Returns:
On success returns an
ActionResultdataclass.- Return type:
ActionResult
- stop_instance(format_data: bool | None = None) ActionResult[source]¶
This function is a coroutine.
Stops the Instance.
Note
The Instance MUST be running (
running = True) or you will get aConnectionErrorWarning
This only applies if you are manually creating these classes.
You must have a
AMPControllerInstancegenerated and set to_controllerfirst. See__init__()
- Parameters:
format_data (Union[
bool, None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant if None), by default None.- Raises:
ConnectionError – If the
runningis False.RuntimeError – If the
_controllerattribute has not been set.
- Returns:
On success returns an
ActionResultdataclass.- Return type:
ActionResult
- restart_instance(format_data: bool | None = None) ActionResult[source]¶
This function is a coroutine.
Restart the Instance.
Note
The Instance MUST be running (
running = True) or you will get aConnectionErrorWarning
This only applies if you are manually creating these classes.
You must have a
AMPControllerInstancegenerated and set to_controllerfirst. See__init__()
- Parameters:
format_data (Union[bool, None], optional) – Format the JSON response data. (Uses
FORMAT_DATAglobal constant if None), by default None.- Raises:
ConnectionError – The requested instance is not available at this time if the Instance is offline.
RuntimeError – If the
_controllerattribute has not been set.
- Returns:
On success returns an
ActionResultdataclass.- Return type:
ActionResult
- update_instance(format_data: bool | None = None) ActionResult[source]¶
This function is a coroutine. Update the AMP Instance.
Warning
This only applies if you are manually creating these classes.
You must have a
AMPControllerInstancegenerated and set to_controllerfirst. See__init__()
- Parameters:
format_data (Union[
bool, None], optional) – Format the JSON response data. (UsesFORMAT_DATAglobal constant if None), by default None.- Returns:
On success returns an
ActionResultdataclass.- Return type:
ActionResult
Target/ADS Instance¶
This class object is for Target/ADS type Instances providing the endpoints specific to it’s type.
- class ampapi.AMPADSInstance(data: Instance | None, controller: AMPControllerInstance | None = None)[source]¶
Typically referred to the “Target ADS” which is apart of the available Instances of the
AMPControllerInstanceviainstances.Note
No fundamental difference between this class and a
AMPInstance.
Minecraft Instance¶
This class object is for Minecraft type Instances providing the endpoints specific to it’s type.
API Utility¶
This file is specifically designed to provide useful functions for data handling of API endpoints and development of the API.
- async ampapi.util.amp_api_update(instance: AMPControllerInstance, sanitize_json: bool) None[source]¶
This function is a coroutine.
Gets the AMP Instance API Endpoints and writes them out to a file. Used for version changes.
Note
Having a
Minecrafttype Instance is beneficial for this call. Otherwise you will only get the ADS/Controller API spec sheet.- Parameters:
instance (AMPControllerInstance) – Must be the Controller instance; as we are looking for the ADS and a Minecraft Instance.
sanitize_json (bool) – Sanitize the JSON responses to meet PEP8 compliance.
- ampapi.util.dict_merge(dict1: ScheduleDataData, dict2: ScheduleDataData) ScheduleDataData[source]¶
Merges dict2 into dict1 with key overlapp but combining data instead of replacing key data.
Note
This was made for
ScheduleDataDataspecifically to merge the list ofMethodsDataandTriggersDataunder the same key.- Parameters:
dict1 (
ScheduleDataData) – The origin dict.dict2 (
ScheduleDataData) – The dict to merge keys from.
- Returns:
Merged dictionary.
- Return type:
ScheduleDataData
- ampapi.util.dump_to_file(data: Iterable, file_name: str = '', path: Path | None = None, no_format: bool = True) None[source]¶
Dump’s a list or dict to a file.
- async ampapi.util.generate_docs_rst(instance: AMPControllerInstance) None[source]¶
This function is a coroutine.
This will generate the Sphinx
.rstfiles we use for documentation. The files will be written to../docs/nodes/Warning
There may be a few errors due to the formatting of AMPs return information; so it is wrapped in
try/excepts- Parameters:
instance (AMPControllerInstance | AMPADSInstance) – Must be of these types as the API endpoint
get_settingspec()is not available to all.
- ampapi.util.repeat_to_length(string: str, repeat_char: str, length: int = 0) str[source]¶
Will repeat the passed in
repeat_charby thelen(string)provided or by thelengthparameter.Note
By default the
repeat_charwill be one longer than the provided string unless you specify thelengthparameter.- Parameters:
- Returns:
The modified
repeat_charstr by thelengthprovided.- Return type: