-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #521 from linode/proj/vm-placement
project: VM Placement
- Loading branch information
Showing
12 changed files
with
1,790 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.