diff --git a/instances.go b/instances.go index 7a1352790..04c5239ad 100644 --- a/instances.go +++ b/instances.go @@ -98,11 +98,13 @@ type InstanceSpec struct { // InstanceAlert represents a metric alert type InstanceAlert struct { - CPU int `json:"cpu"` - IO int `json:"io"` - NetworkIn int `json:"network_in"` - NetworkOut int `json:"network_out"` - TransferQuota int `json:"transfer_quota"` + CPU int `json:"cpu"` + IO int `json:"io"` + NetworkIn int `json:"network_in"` + NetworkOut int `json:"network_out"` + TransferQuota int `json:"transfer_quota"` + SystemAlerts *[]int `json:"system_alerts,omitempty"` + UserAlerts *[]int `json:"user_alerts,omitempty"` } // InstanceBackup represents backup settings for an instance @@ -228,6 +230,15 @@ type InstanceCreateOptions struct { // NOTE: MaintenancePolicy can only be used with v4beta. MaintenancePolicy *string `json:"maintenance_policy,omitempty"` + + // Note: Alerts can only be used with v4beta. + Alerts *InstanceACLPAlertsOptions `json:"alerts,omitempty"` +} + +// InstanceACLPAlertsOptions represents ACLP alerts options for instance creation and cloning. +type InstanceACLPAlertsOptions struct { + SystemAlerts *[]int `json:"system_alerts,omitempty"` + UserAlerts *[]int `json:"user_alerts,omitempty"` } // InstanceCreatePlacementGroupOptions represents the placement group @@ -403,6 +414,9 @@ type InstanceCloneOptions struct { // Deprecated: group is a deprecated property denoting a group label for the Linode. Group string `json:"group,omitempty"` + + // Note: Alerts can only be used with v4beta. + Alerts *InstanceACLPAlertsOptions `json:"alerts,omitempty"` } // InstanceResizeOptions is an options struct used when resizing an instance diff --git a/test/unit/fixtures/instance_clone.json b/test/unit/fixtures/instance_clone.json index 3fc031976..c09a233f7 100644 --- a/test/unit/fixtures/instance_clone.json +++ b/test/unit/fixtures/instance_clone.json @@ -4,5 +4,14 @@ "region": "us-east", "type": "g6-standard-1", "status": "provisioning", - "maintenance_policy": "linode/migrate" + "maintenance_policy": "linode/migrate", + "alerts": { + "cpu": 0, + "io": 0, + "network_in": 0, + "network_out": 0, + "transfer_quota": 0, + "system_alerts": [123,456], + "user_alerts": [555] + } } diff --git a/test/unit/fixtures/instance_create.json b/test/unit/fixtures/instance_create.json index a145a9b01..7a9248b8a 100644 --- a/test/unit/fixtures/instance_create.json +++ b/test/unit/fixtures/instance_create.json @@ -4,5 +4,14 @@ "region": "us-east", "type": "g6-standard-1", "status": "provisioning", - "maintenance_policy": "linode/migrate" + "maintenance_policy": "linode/migrate", + "alerts": { + "cpu": 0, + "io": 0, + "network_in": 0, + "network_out": 0, + "transfer_quota": 0, + "system_alerts": [123,456], + "user_alerts": [555] + } } diff --git a/test/unit/fixtures/instance_get.json b/test/unit/fixtures/instance_get.json index 419ee7633..0c6c8d89c 100644 --- a/test/unit/fixtures/instance_get.json +++ b/test/unit/fixtures/instance_get.json @@ -17,5 +17,14 @@ "placement_group": { "migrating_to": 2468 }, - "maintenance_policy": "linode/migrate" + "maintenance_policy": "linode/migrate", + "alerts": { + "cpu": 0, + "io": 0, + "network_in": 0, + "network_out": 0, + "transfer_quota": 0, + "system_alerts": [123,456], + "user_alerts": [555] + } } diff --git a/test/unit/fixtures/instance_update.json b/test/unit/fixtures/instance_update.json index dca96c6ce..6da11c4ad 100644 --- a/test/unit/fixtures/instance_update.json +++ b/test/unit/fixtures/instance_update.json @@ -1,5 +1,14 @@ { "id": 123, "label": "updated-instance", - "maintenance_policy": "linode/power_off_on" + "maintenance_policy": "linode/power_off_on", + "alerts": { + "cpu": 0, + "io": 0, + "network_in": 0, + "network_out": 0, + "transfer_quota": 0, + "system_alerts": [123,456], + "user_alerts": [555] + } } diff --git a/test/unit/fixtures/interface_list.json b/test/unit/fixtures/interface_list.json index 1f86dad65..597487c6f 100644 --- a/test/unit/fixtures/interface_list.json +++ b/test/unit/fixtures/interface_list.json @@ -15,6 +15,15 @@ "vlan": { "vlan_label": "my_vlan", "ipam_address": "10.0.0.1/24" + }, + "alerts": { + "cpu": 0, + "io": 0, + "network_in": 0, + "network_out": 0, + "transfer_quota": 0, + "system_alerts": [123,456], + "user_alerts": [555] } }, { diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index f10e08d6f..d21449b96 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -44,6 +44,19 @@ func TestInstances_List(t *testing.T) { require.NotNil(t, linode.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *linode.PlacementGroup.MigratingTo) assert.Equal(t, "linode/migrate", linode.MaintenancePolicy) + if linode.Alerts.SystemAlerts != nil { + systemAlerts := *linode.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } + } + if linode.Alerts.UserAlerts != nil { + userAlerts := *linode.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } + } } func TestInstance_Get(t *testing.T) { @@ -77,6 +90,19 @@ func TestInstance_Get(t *testing.T) { assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) require.NotNil(t, instance.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *instance.PlacementGroup.MigratingTo) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } + } + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } + } } func TestInstance_Migrate(t *testing.T) { @@ -180,6 +206,10 @@ func TestInstance_Create(t *testing.T) { Image: "linode/ubuntu22.04", RootPass: "securepassword", MaintenancePolicy: linodego.Pointer("linode/migrate"), + Alerts: &linodego.InstanceACLPAlertsOptions{ + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, + }, } base.MockPost("linode/instances", fixtureData) @@ -188,6 +218,19 @@ func TestInstance_Create(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "new-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } + } + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } + } } func TestInstance_Update(t *testing.T) { @@ -201,6 +244,10 @@ func TestInstance_Update(t *testing.T) { updateOptions := linodego.InstanceUpdateOptions{ Label: "updated-instance", MaintenancePolicy: linodego.Pointer("linode/power_off_on"), + Alerts: &linodego.InstanceAlert{ + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, + }, } base.MockPut("linode/instances/123", fixtureData) @@ -209,6 +256,19 @@ func TestInstance_Update(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "updated-instance", instance.Label) assert.Equal(t, "linode/power_off_on", instance.MaintenancePolicy) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } + } + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } + } } func TestInstance_Delete(t *testing.T) { @@ -256,6 +316,10 @@ func TestInstance_Clone(t *testing.T) { Region: "us-east", Type: "g6-standard-1", Label: "cloned-instance", + Alerts: &linodego.InstanceACLPAlertsOptions{ + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, + }, } base.MockPost("linode/instances/123/clone", fixtureData) @@ -264,6 +328,19 @@ func TestInstance_Clone(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "cloned-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } + } + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } + } } func TestInstance_Resize(t *testing.T) {