Skip to content

Commit

Permalink
Merge branch 'main' into TPT2871_migrate_account_notifications_to_acc…
Browse files Browse the repository at this point in the history
…ount_user_grants
  • Loading branch information
ErikZilber committed Jun 20, 2024
2 parents 04caf51 + 5ef1b79 commit 149fe2d
Show file tree
Hide file tree
Showing 12 changed files with 1,815 additions and 83 deletions.
8 changes: 8 additions & 0 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ const (
ActionPaymentMethodAdd EventAction = "payment_method_add"
ActionPaymentSubmitted EventAction = "payment_submitted"
ActionPasswordReset EventAction = "password_reset"
ActionPlacementGroupCreate EventAction = "placement_group_create"
ActionPlacementGroupUpdate EventAction = "placement_group_update"
ActionPlacementGroupDelete EventAction = "placement_group_delete"
ActionPlacementGroupAssign EventAction = "placement_group_assign"
ActionPlacementGroupUnassign EventAction = "placement_group_unassign"
ActionPlacementGroupBecameNonCompliant EventAction = "placement_group_became_non_compliant"
ActionPlacementGroupBecameCompliant EventAction = "placement_group_became_compliant"
ActionProfileUpdate EventAction = "profile_update"
ActionStackScriptCreate EventAction = "stackscript_create"
ActionStackScriptDelete EventAction = "stackscript_delete"
Expand Down Expand Up @@ -226,6 +233,7 @@ const (
EntityManagedService EntityType = "managed_service"
EntityNodebalancer EntityType = "nodebalancer"
EntityOAuthClient EntityType = "oauth_client"
EntityPlacementGroup EntityType = "placement_group"
EntityProfile EntityType = "profile"
EntityStackscript EntityType = "stackscript"
EntityTag EntityType = "tag"
Expand Down
46 changes: 0 additions & 46 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,46 +0,0 @@
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46 h1:lsxEuwrXEAokXB9qhlbKWPpo3KMLZQ5WB5WLQRW1uq0=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/kisielk/errcheck v1.5.0 h1:e8esj/e4R+SAOwFwN+n3zr0nYeCyeweozKfO23MvHzY=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
41 changes: 33 additions & 8 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type Instance struct {
Specs *InstanceSpec `json:"specs"`
WatchdogEnabled bool `json:"watchdog_enabled"`
Tags []string `json:"tags"`

// NOTE: Placement Groups may not currently be available to all users.
PlacementGroup *InstancePlacementGroup `json:"placement_group"`
}

// InstanceSpec represents a linode spec
Expand Down Expand Up @@ -104,6 +107,15 @@ type InstanceTransfer struct {
Quota int `json:"quota"`
}

// InstancePlacementGroup represents information about the placement group
// this Linode is a part of.
type InstancePlacementGroup struct {
ID int `json:"id"`
Label string `json:"label"`
AffinityType PlacementGroupAffinityType `json:"affinity_type"`
IsStrict bool `json:"is_strict"`
}

// InstanceMetadataOptions specifies various Instance creation fields
// that relate to the Linode Metadata service.
type InstanceMetadataOptions struct {
Expand All @@ -130,6 +142,9 @@ type InstanceCreateOptions struct {
Metadata *InstanceMetadataOptions `json:"metadata,omitempty"`
FirewallID int `json:"firewall_id,omitempty"`

// NOTE: Placement Groups may not currently be available to all users.
PlacementGroup *InstanceCreatePlacementGroupOptions `json:"placement_group,omitempty"`

// Creation fields that need to be set explicitly false, "", or 0 use pointers
SwapSize *int `json:"swap_size,omitempty"`
Booted *bool `json:"booted,omitempty"`
Expand All @@ -138,6 +153,13 @@ type InstanceCreateOptions struct {
Group string `json:"group,omitempty"`
}

// InstanceCreatePlacementGroupOptions represents the placement group
// to create this Linode under.
type InstanceCreatePlacementGroupOptions struct {
ID int `json:"id"`
CompliantOnly *bool `json:"compliant_only,omitempty"`
}

// InstanceUpdateOptions is an options struct used when Updating an Instance
type InstanceUpdateOptions struct {
Label string `json:"label,omitempty"`
Expand Down Expand Up @@ -190,13 +212,14 @@ type InstanceCloneOptions struct {
Type string `json:"type,omitempty"`

// LinodeID is an optional existing instance to use as the target of the clone
LinodeID int `json:"linode_id,omitempty"`
Label string `json:"label,omitempty"`
BackupsEnabled bool `json:"backups_enabled"`
Disks []int `json:"disks,omitempty"`
Configs []int `json:"configs,omitempty"`
PrivateIP bool `json:"private_ip,omitempty"`
Metadata *InstanceMetadataOptions `json:"metadata,omitempty"`
LinodeID int `json:"linode_id,omitempty"`
Label string `json:"label,omitempty"`
BackupsEnabled bool `json:"backups_enabled"`
Disks []int `json:"disks,omitempty"`
Configs []int `json:"configs,omitempty"`
PrivateIP bool `json:"private_ip,omitempty"`
Metadata *InstanceMetadataOptions `json:"metadata,omitempty"`
PlacementGroup *InstanceCreatePlacementGroupOptions `json:"placement_group,omitempty"`

// Deprecated: group is a deprecated property denoting a group label for the Linode.
Group string `json:"group,omitempty"`
Expand All @@ -211,10 +234,12 @@ type InstanceResizeOptions struct {
AllowAutoDiskResize *bool `json:"allow_auto_disk_resize,omitempty"`
}

// InstanceResizeOptions is an options struct used when resizing an instance
// InstanceMigrateOptions is an options struct used when migrating an instance
type InstanceMigrateOptions struct {
Type InstanceMigrationType `json:"type,omitempty"`
Region string `json:"region,omitempty"`

PlacementGroup *InstanceCreatePlacementGroupOptions `json:"placement_group,omitempty"`
}

// InstancesPagedResponse represents a linode API response for listing
Expand Down
160 changes: 160 additions & 0 deletions placement_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package linodego

import "context"

// PlacementGroupAffinityType is an enum that determines the affinity policy
// for Linodes in a placement group.
type PlacementGroupAffinityType string

const (
AffinityTypeAntiAffinityLocal PlacementGroupAffinityType = "anti_affinity:local"
)

// PlacementGroupMember represents a single Linode assigned to a
// placement group.
type PlacementGroupMember struct {
LinodeID int `json:"linode_id"`
IsCompliant bool `json:"is_compliant"`
}

// PlacementGroup represents a Linode placement group.
// NOTE: Placement Groups may not currently be available to all users.
type PlacementGroup struct {
ID int `json:"id"`
Label string `json:"label"`
Region string `json:"region"`
AffinityType PlacementGroupAffinityType `json:"affinity_type"`
IsCompliant bool `json:"is_compliant"`
IsStrict bool `json:"is_strict"`
Members []PlacementGroupMember `json:"members"`
}

// PlacementGroupCreateOptions represents the options to use
// when creating a placement group.
type PlacementGroupCreateOptions struct {
Label string `json:"label"`
Region string `json:"region"`
AffinityType PlacementGroupAffinityType `json:"affinity_type"`
IsStrict bool `json:"is_strict"`
}

// PlacementGroupUpdateOptions represents the options to use
// when updating a placement group.
type PlacementGroupUpdateOptions struct {
Label string `json:"label,omitempty"`
}

// PlacementGroupAssignOptions represents options used when
// assigning Linodes to a placement group.
type PlacementGroupAssignOptions struct {
Linodes []int `json:"linodes"`
CompliantOnly *bool `json:"compliant_only,omitempty"`
}

// PlacementGroupUnAssignOptions represents options used when
// unassigning Linodes from a placement group.
type PlacementGroupUnAssignOptions struct {
Linodes []int `json:"linodes"`
}

// ListPlacementGroups lists placement groups under the current account
// matching the given list options.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) ListPlacementGroups(
ctx context.Context,
options *ListOptions,
) ([]PlacementGroup, error) {
return getPaginatedResults[PlacementGroup](
ctx,
c,
"placement/groups",
options,
)
}

// GetPlacementGroup gets a placement group with the specified ID.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) GetPlacementGroup(
ctx context.Context,
id int,
) (*PlacementGroup, error) {
return doGETRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d", id),
)
}

// CreatePlacementGroup creates a placement group with the specified options.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) CreatePlacementGroup(
ctx context.Context,
options PlacementGroupCreateOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
"placement/groups",
options,
)
}

// UpdatePlacementGroup updates a placement group with the specified ID using the provided options.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) UpdatePlacementGroup(
ctx context.Context,
id int,
options PlacementGroupUpdateOptions,
) (*PlacementGroup, error) {
return doPUTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d", id),
options,
)
}

// AssignPlacementGroupLinodes assigns the specified Linodes to the given
// placement group.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) AssignPlacementGroupLinodes(
ctx context.Context,
id int,
options PlacementGroupAssignOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d/assign", id),
options,
)
}

// UnassignPlacementGroupLinodes un-assigns the specified Linodes from the given
// placement group.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) UnassignPlacementGroupLinodes(
ctx context.Context,
id int,
options PlacementGroupUnAssignOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d/unassign", id),
options,
)
}

// DeletePlacementGroup deletes a placement group with the specified ID.
// NOTE: Placement Groups may not currently be available to all users.
func (c *Client) DeletePlacementGroup(
ctx context.Context,
id int,
) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("placement/groups/%d", id),
)
}
Loading

0 comments on commit 149fe2d

Please sign in to comment.