+117
@@ -0,0 +1,117 @@
|
||||
package awsserversdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SecurityGroupsService struct{ client *Client }
|
||||
type EIPService struct{ client *Client }
|
||||
type VolumeService struct{ client *Client }
|
||||
type TrafficService struct{ client *Client }
|
||||
|
||||
type SecurityGroupRule struct {
|
||||
Direction string `json:"direction,omitempty"`
|
||||
Protocol string `json:"protocol"`
|
||||
FromPort int32 `json:"from_port"`
|
||||
ToPort int32 `json:"to_port"`
|
||||
CIDR string `json:"cidr"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
type SecurityGroupView map[string]any
|
||||
|
||||
func (s *SecurityGroupsService) Get(ctx context.Context, region, instanceID string) (SecurityGroupView, error) {
|
||||
result := SecurityGroupView{}
|
||||
err := s.client.do(ctx, http.MethodGet, instancesPath(region, instanceID)+"/security-group", nil, &result, "")
|
||||
return result, err
|
||||
}
|
||||
func (s *SecurityGroupsService) AddRule(ctx context.Context, region, instanceID string, input SecurityGroupRule, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/security-group/rules", input, options...)
|
||||
}
|
||||
func (s *SecurityGroupsService) DeleteRule(ctx context.Context, region, instanceID string, input SecurityGroupRule, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodDelete, instancesPath(region, instanceID)+"/security-group/rules", input, options...)
|
||||
}
|
||||
|
||||
type EIPInfo struct {
|
||||
Current map[string]any `json:"current"`
|
||||
Available []map[string]any `json:"available"`
|
||||
}
|
||||
type EnsureEIPRequest struct {
|
||||
AllocationID string `json:"allocation_id,omitempty"`
|
||||
}
|
||||
type ReverseDNSRequest struct {
|
||||
DomainName string `json:"domain_name,omitempty"`
|
||||
}
|
||||
|
||||
func (s *EIPService) Get(ctx context.Context, region, instanceID string) (*EIPInfo, error) {
|
||||
var result EIPInfo
|
||||
err := s.client.do(ctx, http.MethodGet, instancesPath(region, instanceID)+"/eip", nil, &result, "")
|
||||
return &result, err
|
||||
}
|
||||
func (s *EIPService) Ensure(ctx context.Context, region, instanceID string, input EnsureEIPRequest, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/eip", input, options...)
|
||||
}
|
||||
func (s *EIPService) SetReverseDNS(ctx context.Context, region, instanceID string, input ReverseDNSRequest, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPatch, instancesPath(region, instanceID)+"/eip/reverse-dns", input, options...)
|
||||
}
|
||||
|
||||
type Volume map[string]any
|
||||
type CreateVolumeRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
DeviceName string `json:"device_name"`
|
||||
SizeGiB int32 `json:"size_gib"`
|
||||
Type string `json:"type,omitempty"`
|
||||
IOPS int32 `json:"iops,omitempty"`
|
||||
Throughput int32 `json:"throughput,omitempty"`
|
||||
Encrypted bool `json:"encrypted"`
|
||||
KMSKeyID string `json:"kms_key_id,omitempty"`
|
||||
DeleteOnTermination bool `json:"delete_on_termination"`
|
||||
}
|
||||
type AttachVolumeRequest struct {
|
||||
DeviceName string `json:"device_name"`
|
||||
DeleteOnTermination bool `json:"delete_on_termination"`
|
||||
}
|
||||
type ModifyVolumeRequest struct {
|
||||
SizeGiB int32 `json:"size_gib,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
IOPS int32 `json:"iops,omitempty"`
|
||||
Throughput int32 `json:"throughput,omitempty"`
|
||||
}
|
||||
|
||||
func (s *VolumeService) List(ctx context.Context, region, instanceID string) ([]Volume, error) {
|
||||
var result []Volume
|
||||
err := s.client.do(ctx, http.MethodGet, instancesPath(region, instanceID)+"/volumes", nil, &result, "")
|
||||
return result, err
|
||||
}
|
||||
func (s *VolumeService) Create(ctx context.Context, region, instanceID string, input CreateVolumeRequest, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/volumes", input, options...)
|
||||
}
|
||||
func (s *VolumeService) Attach(ctx context.Context, region, instanceID, volumeID string, input AttachVolumeRequest, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/volumes/"+escaped(volumeID)+"/attach", input, options...)
|
||||
}
|
||||
func (s *VolumeService) Detach(ctx context.Context, region, instanceID, volumeID string, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/volumes/"+escaped(volumeID)+"/detach", map[string]any{}, options...)
|
||||
}
|
||||
func (s *VolumeService) Modify(ctx context.Context, region, instanceID, volumeID string, input ModifyVolumeRequest, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodPatch, instancesPath(region, instanceID)+"/volumes/"+escaped(volumeID), input, options...)
|
||||
}
|
||||
func (s *VolumeService) Delete(ctx context.Context, region, instanceID, volumeID string, force bool, options ...RequestOption) (*Operation, error) {
|
||||
return (&InstancesService{client: s.client}).operation(ctx, http.MethodDelete, instancesPath(region, instanceID)+"/volumes/"+escaped(volumeID), map[string]bool{"force": force}, options...)
|
||||
}
|
||||
|
||||
type TrafficLimit map[string]any
|
||||
type TrafficLimitRequest struct {
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
LimitGiB *float64 `json:"limit_gib,omitempty"`
|
||||
}
|
||||
|
||||
func (s *TrafficService) Get(ctx context.Context, region, instanceID string) (TrafficLimit, error) {
|
||||
result := TrafficLimit{}
|
||||
err := s.client.do(ctx, http.MethodGet, instancesPath(region, instanceID)+"/traffic-limit", nil, &result, "")
|
||||
return result, err
|
||||
}
|
||||
func (s *TrafficService) Update(ctx context.Context, region, instanceID string, input TrafficLimitRequest) (TrafficLimit, error) {
|
||||
result := TrafficLimit{}
|
||||
err := s.client.do(ctx, http.MethodPatch, instancesPath(region, instanceID)+"/traffic-limit", input, &result, newID())
|
||||
return result, err
|
||||
}
|
||||
Reference in New Issue
Block a user