Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions linode_api4/groups/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from linode_api4.objects.filtering import Filter
from linode_api4.objects.linode import (
Backup,
InstanceACLPAlertsOptions,
InstancePlacementGroupAssignment,
InterfaceGeneration,
NetworkInterface,
Expand Down Expand Up @@ -167,6 +168,9 @@ def instance_create(
boot_size: Optional[int] = None,
authorized_users: Optional[List[str]] = None,
ipv4: Optional[List[str]] = None,
alerts: Optional[
Union[Dict[str, Any], InstanceACLPAlertsOptions]
] = None,
**kwargs,
):
"""
Expand Down Expand Up @@ -359,6 +363,9 @@ def instance_create(
:param ipv4: A list of reserved IPv4 addresses to assign to this Instance.
NOTE: Reserved IP feature may not currently be available to all users.
:type ipv4: list[str]
:param alerts: ACLP alerts available to define during instance creation.
This is v4beta only and may not be available to all users.
:type alerts: dict[str, Any] or InstanceACLPAlertsOptions

:returns: A new Instance object
:rtype: Instance
Expand All @@ -385,6 +392,7 @@ def instance_create(
"image": image,
"root_pass": root_pass,
"authorized_keys": load_and_validate_keys(authorized_keys),
"alerts": alerts,
"authorized_users": authorized_users,
# These will automatically be flattened below
"firewall_id": firewall,
Expand Down
16 changes: 16 additions & 0 deletions linode_api4/groups/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
AkamaiObjectStorageLogsDestinationDetails,
CustomHTTPSLogsDestinationDetails,
LogsStreamDetails,
LogsStreamQuota,
)

__all__ = [
Expand Down Expand Up @@ -625,3 +626,18 @@ def stream_create(
)

return LogsStream(self.client, result["id"], result)

def stream_quotas(self) -> PaginatedList:
"""
Retrieve quota definitions available for the authenticated account's streams.

This reads from ``/monitor/streams/quotas`` on the API v4 endpoint.

API Documentation: TODO

:returns: A paginated list of stream quota definitions.
:rtype: PaginatedList[LogsStreamQuota]
"""
return self.client._get_objects(
"/monitor/streams/quotas", LogsStreamQuota
)
35 changes: 34 additions & 1 deletion linode_api4/objects/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,31 @@ class UpgradeInterfacesResult(JSONObject):
)


@dataclass
class InstanceAlerts(JSONObject):
"""
Represents both legacy and ACLP alerts for a Linode Instance.
"""

cpu: int = 0
io: int = 0
network_in: int = 0
network_out: int = 0
transfer_quota: int = 0
system_alerts: Optional[List[int]] = None
user_alerts: Optional[List[int]] = None


@dataclass
class InstanceACLPAlertsOptions(JSONObject):
"""
Represents the ACLP alerts available to define during instance creation and cloning.
"""

system_alerts: Optional[List[int]] = None
user_alerts: Optional[List[int]] = None


@dataclass
class InstanceBackupSchedule(JSONObject):
"""
Expand Down Expand Up @@ -842,7 +867,7 @@ class Instance(Base):
"created": Property(is_datetime=True),
"updated": Property(volatile=True, is_datetime=True),
"region": Property(slug_relationship=Region),
"alerts": Property(mutable=True),
"alerts": Property(mutable=True, json_object=InstanceAlerts),
"image": Property(slug_relationship=Image),
"disks": Property(derived_class=Disk),
"configs": Property(derived_class=Config),
Expand Down Expand Up @@ -1949,6 +1974,9 @@ def clone(
Dict[str, Any],
int,
] = None,
alerts: Optional[
Union[Dict[str, Any], InstanceACLPAlertsOptions]
] = None,
):
"""
Clones this linode into a new linode or into a new linode in the given region
Expand Down Expand Up @@ -1987,6 +2015,10 @@ def clone(
:param placement_group: Information about the placement group to create this instance under.
:type placement_group: Union[InstancePlacementGroupAssignment, PlacementGroup, Dict[str, Any], int]

:param alerts: ACLP monitor alert definitions associated with the cloned Instance.
This is under v4beta and may not be available to all users.
:type alerts: dict[str, Any] or InstanceACLPAlertsOptions

:returns: The cloned Instance.
:rtype: Instance
"""
Expand Down Expand Up @@ -2017,6 +2049,7 @@ def clone(
"label": label,
"group": group,
"with_backups": with_backups,
"alerts": alerts,
"placement_group": _expand_placement_group_assignment(
placement_group
),
Expand Down
22 changes: 18 additions & 4 deletions linode_api4/objects/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"LogsStreamStatus",
"LogsStreamDetails",
"LogsStreamDestination",
"LogsStreamQuota",
]


Expand Down Expand Up @@ -276,8 +277,8 @@ class MonitorDashboard(Base):
"id": Property(identifier=True),
"created": Property(is_datetime=True),
"label": Property(),
"service_type": Property(ServiceType),
"type": Property(DashboardType),
"service_type": Property(),
"type": Property(),
"group_by": Property(),
"widgets": Property(json_object=DashboardWidget),
"updated": Property(is_datetime=True),
Expand All @@ -294,7 +295,7 @@ class MonitorService(Base):
api_endpoint = "/monitor/services/{service_type}"
id_attribute = "service_type"
properties = {
"service_type": Property(ServiceType),
"service_type": Property(),
"label": Property(),
"alert": Property(json_object=ServiceAlert),
}
Expand Down Expand Up @@ -495,7 +496,7 @@ class AlertDefinition(DerivedBase):
"entity_ids": Property(mutable=True),
"description": Property(mutable=True),
"service_class": Property(alias_of="class"),
"scope": Property(AlertScope),
"scope": Property(),
"regions": Property(mutable=True),
"entities": Property(json_object=AlertEntities),
"channel_ids": Property(mutable=True),
Expand Down Expand Up @@ -904,3 +905,16 @@ def history(self):
"{}/history".format(LogsStream.api_endpoint.format(id=self.id)),
LogsStreamHistory,
)


@dataclass
class LogsStreamQuota(JSONObject):
"""
Represents a quota definition for logs streams.
"""

quota_id: str = ""
quota_name: str = ""
quota_limit: int = 0
quota_type: str = ""
description: str = ""
1 change: 1 addition & 0 deletions linode_api4/objects/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Capability(StrEnum):
prefixlists = "Cloud Firewall Prefix Lists"
current_prefixlists = "Cloud Firewall Prefix List Current References"
gpudirect_rdma = "GPUDirect RDMA"
premium_nodebalancers = "Premium NodeBalancers"


@dataclass
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ unit-test = [
]
int-test = [
"linode_api4[test-shared]",
"cryptography",
]
lint = [
"black>=23.1.0",
Expand Down
12 changes: 9 additions & 3 deletions test/fixtures/linode_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"network_out": 5,
"cpu": 90,
"transfer_quota": 80,
"io": 5000
"io": 5000,
"system_alerts": [123,456],
"user_alerts": [555]
},
"label": "linode123",
"backups": {
Expand Down Expand Up @@ -66,7 +68,9 @@
"network_out": 5,
"cpu": 90,
"transfer_quota": 80,
"io": 5000
"io": 5000,
"system_alerts": [123,456],
"user_alerts": [555]
},
"label": "linode456",
"backups": {
Expand Down Expand Up @@ -106,7 +110,9 @@
"network_out": 5,
"cpu": 90,
"transfer_quota": 80,
"io": 5000
"io": 5000,
"system_alerts": [123,456],
"user_alerts": [555]
},
"group": "test",
"hypervisor": "kvm",
Expand Down
45 changes: 45 additions & 0 deletions test/fixtures/linode_instances_123_clone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": 124,
"status": "running",
"type": "g6-standard-1",
"alerts": {
"network_in": 5,
"network_out": 5,
"cpu": 90,
"transfer_quota": 80,
"io": 5000,
"system_alerts": [123,456],
"user_alerts": [555]
},
"group": "test",
"hypervisor": "kvm",
"label": "linode124",
"backups": {
"enabled": true,
"schedule": {
"window": "W02",
"day": "Scheduling"
}
},
"specs": {
"memory": 2048,
"disk": 30720,
"vcpus": 1,
"transfer": 2000
},
"ipv6": "1235:abcd::1234:abcd:89ef:67cd/64",
"created": "2017-01-01T00:00:00",
"region": "us-east-1",
"ipv4": [
"124.45.67.89"
],
"updated": "2017-01-01T00:00:00",
"image": "linode/ubuntu24.04",
"tags": ["something"],
"host_uuid": "3b3ddd59d9a78bb8de041391075df44de62bfec8",
"watchdog_enabled": true,
"disk_encryption": "disabled",
"lke_cluster_id": null,
"placement_group": null,
"interface_generation": "linode"
}
21 changes: 21 additions & 0 deletions test/fixtures/monitor_streams_quotas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"data": [
{
"quota_id": "aclp_audit_logs_streams",
"quota_name": "Number of Audit Logs Streams",
"description": "Current number of audit logs streams per account",
"quota_limit": 5,
"quota_type": "logs_streams_aclp_audit_logs_streams"
},
{
"quota_id": "aclp_lke_audit_logs_streams",
"quota_name": "Number of LKE Audit Logs Streams",
"description": "Current number of LKE audit logs streams per account",
"quota_limit": 10,
"quota_type": "logs_streams_aclp_lke_audit_logs_streams"
}
],
"results": 2,
"page": 1,
"pages": 1
}
Loading
Loading