File: regions.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (121 lines) | stat: -rw-r--r-- 4,760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package linodego

import (
	"context"
	"time"
)

// This is an enumeration of Capabilities Linode offers that can be referenced
// through the user-facing parts of the application.
// Defined as strings rather than a custom type to avoid breaking change.
// Can be changed in the potential v2 version.
const (
	CapabilityACLB                          string = "Akamai Cloud Load Balancer"
	CapabilityBackups                       string = "Backups"
	CapabilityBareMetal                     string = "Bare Metal"
	CapabilityBlockStorage                  string = "Block Storage"
	CapabilityBlockStorageEncryption        string = "Block Storage Encryption"
	CapabilityBlockStorageMigrations        string = "Block Storage Migrations"
	CapabilityCloudFirewall                 string = "Cloud Firewall"
	CapabilityDBAAS                         string = "Managed Databases"
	CapabilityDiskEncryption                string = "Disk Encryption"
	CapabilityEdgePlans                     string = "Edge Plans"
	CapabilityGPU                           string = "GPU Linodes"
	CapabilityKubernetesEnterprise          string = "Kubernetes Enterprise"
	CapabilityLADiskEncryption              string = "LA Disk Encryption"
	CapabilityLKE                           string = "Kubernetes"
	CapabilityLKEControlPlaneACL            string = "LKE Network Access Control List (IP ACL)"
	CapabilityLinodes                       string = "Linodes"
	CapabilityLkeHaControlPlanes            string = "LKE HA Control Planes"
	CapabilityMachineImages                 string = "Machine Images"
	CapabilityMaintenancePolicy             string = "Maintenance Policy"
	CapabilityMetadata                      string = "Metadata"
	CapabilityNodeBalancers                 string = "NodeBalancers"
	CapabilityObjectStorage                 string = "Object Storage"
	CapabilityObjectStorageAccessKeyRegions string = "Object Storage Access Key Regions"
	CapabilityObjectStorageEndpointTypes    string = "Object Storage Endpoint Types"
	CapabilityPlacementGroup                string = "Placement Group"
	CapabilityPremiumPlans                  string = "Premium Plans"
	CapabilityQuadraT1UVPU                  string = "NETINT Quadra T1U"
	CapabilitySupportTicketSeverity         string = "Support Ticket Severity"
	CapabilityVPCs                          string = "VPCs"
	CapabilityVPCsExtra                     string = "VPCs Extra"
	CapabilityVlans                         string = "Vlans"

	// Deprecated: CapabilityObjectStorageRegions constant has been
	// renamed to `CapabilityObjectStorageAccessKeyRegions`.
	CapabilityObjectStorageRegions string = CapabilityObjectStorageAccessKeyRegions
)

// Region-related endpoints have a custom expiry time as the
// `status` field may update for database outages.
var cacheExpiryTime = time.Minute

// Region represents a linode region object
type Region struct {
	ID      string `json:"id"`
	Country string `json:"country"`

	// A List of enums from the above constants
	Capabilities []string `json:"capabilities"`

	Status   string `json:"status"`
	Label    string `json:"label"`
	SiteType string `json:"site_type"`

	Resolvers            RegionResolvers             `json:"resolvers"`
	PlacementGroupLimits *RegionPlacementGroupLimits `json:"placement_group_limits"`
}

// RegionResolvers contains the DNS resolvers of a region
type RegionResolvers struct {
	IPv4 string `json:"ipv4"`
	IPv6 string `json:"ipv6"`
}

// RegionPlacementGroupLimits contains information about the
// placement group limits for the current user in the current region.
type RegionPlacementGroupLimits struct {
	MaximumPGsPerCustomer int `json:"maximum_pgs_per_customer"`
	MaximumLinodesPerPG   int `json:"maximum_linodes_per_pg"`
}

// ListRegions lists Regions. This endpoint is cached by default.
func (c *Client) ListRegions(ctx context.Context, opts *ListOptions) ([]Region, error) {
	endpoint, err := generateListCacheURL("regions", opts)
	if err != nil {
		return nil, err
	}

	if result := c.getCachedResponse(endpoint); result != nil {
		return result.([]Region), nil
	}

	response, err := getPaginatedResults[Region](ctx, c, "regions", opts)
	if err != nil {
		return nil, err
	}

	c.addCachedResponse(endpoint, response, &cacheExpiryTime)

	return response, nil
}

// GetRegion gets the template with the provided ID. This endpoint is cached by default.
func (c *Client) GetRegion(ctx context.Context, regionID string) (*Region, error) {
	e := formatAPIPath("regions/%s", regionID)

	if result := c.getCachedResponse(e); result != nil {
		result := result.(Region)
		return &result, nil
	}

	response, err := doGETRequest[Region](ctx, c, e)
	if err != nil {
		return nil, err
	}

	c.addCachedResponse(e, response, &cacheExpiryTime)

	return response, nil
}