diff --git a/xelon/client.go b/xelon/client.go index 0670ae2..2991578 100644 --- a/xelon/client.go +++ b/xelon/client.go @@ -36,16 +36,16 @@ type Client struct { common service // Reuse a single struct instead of allocating one for each service on the heap. - Clouds *CloudsService - Devices *DevicesService + Clouds *CloudsServiceV1 + Devices *DevicesServiceV1 Kubernetes *KubernetesService LoadBalancerClusters *LoadBalancerClustersService LoadBalancers *LoadBalancersService - Networks *NetworksService - PersistentStorages *PersistentStoragesService - SSHKeys *SSHKeysService - Templates *TemplatesService - Tenants *TenantsService + Networks *NetworksServiceV1 + PersistentStorages *PersistentStoragesServiceV1 + SSHKeys *SSHKeysServiceV1 + Templates *TemplatesServiceV1 + Tenants *TenantsServiceV1 } type service struct { @@ -134,16 +134,16 @@ func NewClient(token string, opts ...ClientOption) *Client { c.common.client = c - c.Clouds = (*CloudsService)(&c.common) - c.Devices = (*DevicesService)(&c.common) + c.Clouds = (*CloudsServiceV1)(&c.common) + c.Devices = (*DevicesServiceV1)(&c.common) c.Kubernetes = (*KubernetesService)(&c.common) c.LoadBalancerClusters = (*LoadBalancerClustersService)(&c.common) c.LoadBalancers = (*LoadBalancersService)(&c.common) - c.Networks = (*NetworksService)(&c.common) - c.PersistentStorages = (*PersistentStoragesService)(&c.common) - c.SSHKeys = (*SSHKeysService)(&c.common) - c.Templates = (*TemplatesService)(&c.common) - c.Tenants = (*TenantsService)(&c.common) + c.Networks = (*NetworksServiceV1)(&c.common) + c.PersistentStorages = (*PersistentStoragesServiceV1)(&c.common) + c.SSHKeys = (*SSHKeysServiceV1)(&c.common) + c.Templates = (*TemplatesServiceV1)(&c.common) + c.Tenants = (*TenantsServiceV1)(&c.common) // Notify user if no ClientID is set if c.clientID == "" { @@ -153,17 +153,6 @@ func NewClient(token string, opts ...ClientOption) *Client { return c } -// Deprecated: SetBaseURL overrides the default BaseURL. Use WithBaseURL instead. -func (c *Client) SetBaseURL(baseURL string) { - parsedURL, _ := url.Parse(baseURL) - c.baseURL = parsedURL -} - -// Deprecated: SetUserAgent overrides the default UserAgent. Use WithUserAgent instead. -func (c *Client) SetUserAgent(ua string) { - c.userAgent = ua -} - // NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved // relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. // If specified, the value pointed to by body is JSON encoded and included as the request body. diff --git a/xelon/client_test.go b/xelon/client_test.go index 0d7e933..86b3f64 100644 --- a/xelon/client_test.go +++ b/xelon/client_test.go @@ -40,14 +40,6 @@ func TestClient_NewClient(t *testing.T) { assert.Equal(t, "auth-token", client.token) } -func TestClient_SetUserAgent(t *testing.T) { - client := &Client{} - - client.SetUserAgent("custom-user-agent") - - assert.Equal(t, "custom-user-agent", client.userAgent) -} - func TestClient_Defaults(t *testing.T) { client := NewClient("auth-token") diff --git a/xelon/clouds.go b/xelon/clouds_v1.go similarity index 72% rename from xelon/clouds.go rename to xelon/clouds_v1.go index 32a7a79..26bb5be 100644 --- a/xelon/clouds.go +++ b/xelon/clouds_v1.go @@ -8,8 +8,9 @@ import ( const cloudsBasePath = "hv" -// CloudsService handles communication with the organization's cloud related methods of the Xelon API. -type CloudsService service +// CloudsServiceV1 handles communication with the organization's cloud related methods of the Xelon API. +// Deprecated. +type CloudsServiceV1 service type Cloud struct { ID int `json:"id,omitempty"` @@ -18,7 +19,7 @@ type Cloud struct { Type int `json:"type,omitempty"` } -func (s *CloudsService) List(ctx context.Context, tenantID string) ([]Cloud, *Response, error) { +func (s *CloudsServiceV1) List(ctx context.Context, tenantID string) ([]Cloud, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } diff --git a/xelon/clouds_test.go b/xelon/clouds_v1_test.go similarity index 100% rename from xelon/clouds_test.go rename to xelon/clouds_v1_test.go diff --git a/xelon/devices.go b/xelon/devices_v1.go similarity index 86% rename from xelon/devices.go rename to xelon/devices_v1.go index 2f0ed52..7f33539 100644 --- a/xelon/devices.go +++ b/xelon/devices_v1.go @@ -8,8 +8,9 @@ import ( const devicesBasePath = "vmlist" -// DevicesService handles communication with the devices related methods of the Xelon API. -type DevicesService service +// DevicesServiceV1 handles communication with the devices related methods of the Xelon API. +// Deprecated. +type DevicesServiceV1 service // Device represents a Xelon device. type Device struct { @@ -95,7 +96,7 @@ type DeviceRoot struct { } // List provides a list of all devices. -func (s *DevicesService) List(ctx context.Context, tenantID string, opts *DeviceListOptions) ([]DeviceLocalVMDetails, *Response, error) { +func (s *DevicesServiceV1) List(ctx context.Context, tenantID string, opts *DeviceListOptions) ([]DeviceLocalVMDetails, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -126,7 +127,7 @@ func (s *DevicesService) List(ctx context.Context, tenantID string, opts *Device } // Get provides detailed information for a device identified by tenant and localvmid. -func (s *DevicesService) Get(ctx context.Context, tenantID, localVMID string) (*DeviceRoot, *Response, error) { +func (s *DevicesServiceV1) Get(ctx context.Context, tenantID, localVMID string) (*DeviceRoot, *Response, error) { if tenantID == "" || localVMID == "" { return nil, nil, ErrEmptyArgument } @@ -148,7 +149,7 @@ func (s *DevicesService) Get(ctx context.Context, tenantID, localVMID string) (* } // Create makes a new device with given payload. -func (s *DevicesService) Create(ctx context.Context, createRequest *DeviceCreateRequest) (*DeviceCreateResponse, *Response, error) { +func (s *DevicesServiceV1) Create(ctx context.Context, createRequest *DeviceCreateRequest) (*DeviceCreateResponse, *Response, error) { if createRequest == nil { return nil, nil, ErrEmptyPayloadNotAllowed } @@ -170,7 +171,7 @@ func (s *DevicesService) Create(ctx context.Context, createRequest *DeviceCreate } // Delete removes a device identified by localvmid. -func (s *DevicesService) Delete(ctx context.Context, localVMID string) (*Response, error) { +func (s *DevicesServiceV1) Delete(ctx context.Context, localVMID string) (*Response, error) { if localVMID == "" { return nil, ErrEmptyArgument } @@ -186,7 +187,7 @@ func (s *DevicesService) Delete(ctx context.Context, localVMID string) (*Respons } // Start starts a specific device identified by localvmid. -func (s *DevicesService) Start(ctx context.Context, localVMID string) (*Response, error) { +func (s *DevicesServiceV1) Start(ctx context.Context, localVMID string) (*Response, error) { if localVMID == "" { return nil, ErrEmptyArgument } @@ -202,7 +203,7 @@ func (s *DevicesService) Start(ctx context.Context, localVMID string) (*Response } // Stop stops a specific device identified by localvmid. -func (s *DevicesService) Stop(ctx context.Context, localVMID string) (*Response, error) { +func (s *DevicesServiceV1) Stop(ctx context.Context, localVMID string) (*Response, error) { if localVMID == "" { return nil, ErrEmptyArgument } @@ -219,7 +220,7 @@ func (s *DevicesService) Stop(ctx context.Context, localVMID string) (*Response, // GetDeviceCreationInfo retrieves a list of available templates, NICs, // and scripts when creating a new device. -func (s *DevicesService) GetDeviceCreationInfo(ctx context.Context, tenantID, deviceCategory, deviceType string, templateID int) (*DeviceCreationInfo, *Response, error) { +func (s *DevicesServiceV1) GetDeviceCreationInfo(ctx context.Context, tenantID, deviceCategory, deviceType string, templateID int) (*DeviceCreationInfo, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } diff --git a/xelon/networks.go b/xelon/networks_v1.go similarity index 85% rename from xelon/networks.go rename to xelon/networks_v1.go index bf47550..a9699b6 100644 --- a/xelon/networks.go +++ b/xelon/networks_v1.go @@ -8,8 +8,9 @@ import ( const networkBasePath = "networks" -// NetworksService handles communication with the network related methods of the Xelon API. -type NetworksService service +// NetworksServiceV1 handles communication with the network related methods of the Xelon API. +// Deprecated. +type NetworksServiceV1 service type Network struct { ID int `json:"id,omitempty"` @@ -104,7 +105,7 @@ type networkRoot struct { } // List provides a list of all networks. -func (s *NetworksService) List(ctx context.Context, tenantID string) ([]Network, *Response, error) { +func (s *NetworksServiceV1) List(ctx context.Context, tenantID string) ([]Network, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -126,7 +127,7 @@ func (s *NetworksService) List(ctx context.Context, tenantID string) ([]Network, } // Get provides information about a network identified by local id. -func (s *NetworksService) Get(ctx context.Context, tenantID string, networkID int) (*NetworkInfo, *Response, error) { +func (s *NetworksServiceV1) Get(ctx context.Context, tenantID string, networkID int) (*NetworkInfo, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -148,7 +149,7 @@ func (s *NetworksService) Get(ctx context.Context, tenantID string, networkID in } // CreateLAN makes a new LAN network with given payload. -func (s *NetworksService) CreateLAN(ctx context.Context, tenantID string, createRequest *NetworkLANCreateRequest) (*APIResponse, *Response, error) { +func (s *NetworksServiceV1) CreateLAN(ctx context.Context, tenantID string, createRequest *NetworkLANCreateRequest) (*APIResponse, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -173,7 +174,7 @@ func (s *NetworksService) CreateLAN(ctx context.Context, tenantID string, create } // Update changes the configuration of a network. -func (s *NetworksService) Update(ctx context.Context, networkID int, updateRequest *NetworkUpdateRequest) (*APIResponse, *Response, error) { +func (s *NetworksServiceV1) Update(ctx context.Context, networkID int, updateRequest *NetworkUpdateRequest) (*APIResponse, *Response, error) { if updateRequest == nil { return nil, nil, ErrEmptyPayloadNotAllowed } @@ -195,7 +196,7 @@ func (s *NetworksService) Update(ctx context.Context, networkID int, updateReque } // Delete removes a network identified by id. -func (s *NetworksService) Delete(ctx context.Context, networkID int) (*Response, error) { +func (s *NetworksServiceV1) Delete(ctx context.Context, networkID int) (*Response, error) { path := fmt.Sprintf("%v/%v/destroy", networkBasePath, networkID) req, err := s.client.NewRequest(http.MethodDelete, path, nil) @@ -207,7 +208,7 @@ func (s *NetworksService) Delete(ctx context.Context, networkID int) (*Response, } // AddIPAddress adds a new IP address to the specific network. -func (s *NetworksService) AddIPAddress(ctx context.Context, networkID int, addIPRequest *NetworkAddIPRequest) (*APIResponse, *Response, error) { +func (s *NetworksServiceV1) AddIPAddress(ctx context.Context, networkID int, addIPRequest *NetworkAddIPRequest) (*APIResponse, *Response, error) { if addIPRequest == nil { return nil, nil, ErrEmptyPayloadNotAllowed } @@ -229,7 +230,7 @@ func (s *NetworksService) AddIPAddress(ctx context.Context, networkID int, addIP } // DeleteIPAddress removes an IP from the specific network. -func (s *NetworksService) DeleteIPAddress(ctx context.Context, networkID, ipAddressID int) (*Response, error) { +func (s *NetworksServiceV1) DeleteIPAddress(ctx context.Context, networkID, ipAddressID int) (*Response, error) { path := fmt.Sprintf("%v/%v/deleteIp?ipid=%v", networkBasePath, networkID, ipAddressID) req, err := s.client.NewRequest(http.MethodDelete, path, nil) diff --git a/xelon/persistent_storages.go b/xelon/persistent_storages_v1.go similarity index 78% rename from xelon/persistent_storages.go rename to xelon/persistent_storages_v1.go index 089fde2..64396f3 100644 --- a/xelon/persistent_storages.go +++ b/xelon/persistent_storages_v1.go @@ -8,8 +8,9 @@ import ( const persistentStorageBasePath = "persistentStorage" -// PersistentStoragesService handles communication with the persistent storage related methods of the Xelon API. -type PersistentStoragesService service +// PersistentStoragesServiceV1 handles communication with the persistent storage related methods of the Xelon API. +// Deprecated. +type PersistentStoragesServiceV1 service type PersistentStorage struct { AssignedServers []DeviceLocalVMDetails `json:"assigned_servers,omitempty"` @@ -36,7 +37,7 @@ type PersistentStorageAttachDetachRequest struct { ServerID []string `json:"server_id"` } -func (s *PersistentStoragesService) List(ctx context.Context, tenantID string) ([]PersistentStorage, *Response, error) { +func (s *PersistentStoragesServiceV1) List(ctx context.Context, tenantID string) ([]PersistentStorage, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -56,7 +57,7 @@ func (s *PersistentStoragesService) List(ctx context.Context, tenantID string) ( return persistentStorages, resp, nil } -func (s *PersistentStoragesService) Get(ctx context.Context, tenantID, localID string) (*PersistentStorage, *Response, error) { +func (s *PersistentStoragesServiceV1) Get(ctx context.Context, tenantID, localID string) (*PersistentStorage, *Response, error) { if tenantID == "" || localID == "" { return nil, nil, ErrEmptyArgument } @@ -76,7 +77,7 @@ func (s *PersistentStoragesService) Get(ctx context.Context, tenantID, localID s return persistentStorage, resp, nil } -func (s *PersistentStoragesService) GetByName(ctx context.Context, tenantID, name string) (*PersistentStorage, *Response, error) { +func (s *PersistentStoragesServiceV1) GetByName(ctx context.Context, tenantID, name string) (*PersistentStorage, *Response, error) { if tenantID == "" || name == "" { return nil, nil, ErrEmptyArgument } @@ -96,7 +97,7 @@ func (s *PersistentStoragesService) GetByName(ctx context.Context, tenantID, nam return persistentStorage, resp, nil } -func (s *PersistentStoragesService) Create(ctx context.Context, tenantID string, createRequest *PersistentStorageCreateRequest) (*APIResponse, *Response, error) { +func (s *PersistentStoragesServiceV1) Create(ctx context.Context, tenantID string, createRequest *PersistentStorageCreateRequest) (*APIResponse, *Response, error) { if tenantID == "" { return nil, nil, ErrEmptyArgument } @@ -119,7 +120,7 @@ func (s *PersistentStoragesService) Create(ctx context.Context, tenantID string, return apiResponse, resp, nil } -func (s *PersistentStoragesService) Extend(ctx context.Context, localID string, extendRequest *PersistentStorageExtendRequest) (*APIResponse, *Response, error) { +func (s *PersistentStoragesServiceV1) Extend(ctx context.Context, localID string, extendRequest *PersistentStorageExtendRequest) (*APIResponse, *Response, error) { if localID == "" { return nil, nil, ErrEmptyArgument } @@ -142,7 +143,7 @@ func (s *PersistentStoragesService) Extend(ctx context.Context, localID string, return apiResponse, resp, nil } -func (s *PersistentStoragesService) Delete(ctx context.Context, tenantID, localID string) (*Response, error) { +func (s *PersistentStoragesServiceV1) Delete(ctx context.Context, tenantID, localID string) (*Response, error) { if tenantID == "" || localID == "" { return nil, ErrEmptyArgument } @@ -156,7 +157,7 @@ func (s *PersistentStoragesService) Delete(ctx context.Context, tenantID, localI return s.client.Do(ctx, req, nil) } -func (s *PersistentStoragesService) AttachToDevice(ctx context.Context, tenantID, localID string, attachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) { +func (s *PersistentStoragesServiceV1) AttachToDevice(ctx context.Context, tenantID, localID string, attachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) { if tenantID == "" || localID == "" { return nil, nil, ErrEmptyArgument } @@ -178,7 +179,7 @@ func (s *PersistentStoragesService) AttachToDevice(ctx context.Context, tenantID return apiResponse, resp, nil } -func (s *PersistentStoragesService) DetachFromDevice(ctx context.Context, tenantID, localID string, detachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) { +func (s *PersistentStoragesServiceV1) DetachFromDevice(ctx context.Context, tenantID, localID string, detachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) { if tenantID == "" || localID == "" { return nil, nil, ErrEmptyArgument } diff --git a/xelon/ssh_keys.go b/xelon/ssh_keys_v1.go similarity index 78% rename from xelon/ssh_keys.go rename to xelon/ssh_keys_v1.go index 20bc278..695dfba 100644 --- a/xelon/ssh_keys.go +++ b/xelon/ssh_keys_v1.go @@ -8,8 +8,9 @@ import ( const sshBasePath = "vmlist/ssh" -// SSHKeysService handles communication with the ssh keys related methods of the Xelon API. -type SSHKeysService service +// SSHKeysServiceV1 handles communication with the ssh keys related methods of the Xelon API. +// Deprecated. +type SSHKeysServiceV1 service // SSHKey represents a Xelon ssh key. type SSHKey struct { @@ -30,7 +31,7 @@ func (v SSHKey) String() string { } // List provides a list of all added SSH keys. -func (s *SSHKeysService) List(ctx context.Context) ([]SSHKey, *Response, error) { +func (s *SSHKeysServiceV1) List(ctx context.Context) ([]SSHKey, *Response, error) { path := "sshKeys/" req, err := s.client.NewRequest(http.MethodGet, path, nil) @@ -48,7 +49,7 @@ func (s *SSHKeysService) List(ctx context.Context) ([]SSHKey, *Response, error) } // Create makes a new ssh key with given payload. -func (s *SSHKeysService) Create(ctx context.Context, createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error) { +func (s *SSHKeysServiceV1) Create(ctx context.Context, createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error) { if createRequest == nil { return nil, nil, ErrEmptyPayloadNotAllowed } @@ -70,7 +71,7 @@ func (s *SSHKeysService) Create(ctx context.Context, createRequest *SSHKeyCreate } // Delete removes a ssh key identified by id. -func (s *SSHKeysService) Delete(ctx context.Context, sshKeyID int) (*Response, error) { +func (s *SSHKeysServiceV1) Delete(ctx context.Context, sshKeyID int) (*Response, error) { path := fmt.Sprintf("%v/%v/delete", sshBasePath, sshKeyID) req, err := s.client.NewRequest(http.MethodDelete, path, nil) if err != nil { diff --git a/xelon/ssh_keys_test.go b/xelon/ssh_keys_v1_test.go similarity index 100% rename from xelon/ssh_keys_test.go rename to xelon/ssh_keys_v1_test.go diff --git a/xelon/strings.go b/xelon/strings.go index 8c00836..0c79c26 100644 --- a/xelon/strings.go +++ b/xelon/strings.go @@ -8,7 +8,7 @@ import ( ) // Stringify attempts to create a string representation of Xelon types. -func Stringify(message interface{}) string { +func Stringify(message any) string { var buf bytes.Buffer v := reflect.ValueOf(message) stringifyValue(&buf, v) diff --git a/xelon/templates.go b/xelon/templates_v1.go similarity index 84% rename from xelon/templates.go rename to xelon/templates_v1.go index fdc9663..f3a06e0 100644 --- a/xelon/templates.go +++ b/xelon/templates_v1.go @@ -8,8 +8,9 @@ import ( const templatesBasePath = "templates" -// TemplatesService handles communication with the template related methods of the Xelon API. -type TemplatesService service +// TemplatesServiceV1 handles communication with the template related methods of the Xelon API. +// Deprecated. +type TemplatesServiceV1 service type Template struct { Description string `json:"description,omitempty"` @@ -32,7 +33,7 @@ type Templates struct { // List provides a list of available templates. // // Note, passing 0 (zero) for cloudID will retrieve templates across all available clouds. -func (s *TemplatesService) List(ctx context.Context, cloudID int) (*Templates, *Response, error) { +func (s *TemplatesServiceV1) List(ctx context.Context, cloudID int) (*Templates, *Response, error) { path := fmt.Sprintf("device/%s", templatesBasePath) if cloudID != 0 { path = fmt.Sprintf("%v?cloudId=%v", path, cloudID) diff --git a/xelon/tenants.go b/xelon/tenants_v1.go similarity index 77% rename from xelon/tenants.go rename to xelon/tenants_v1.go index 5d9cb80..42cab82 100644 --- a/xelon/tenants.go +++ b/xelon/tenants_v1.go @@ -7,8 +7,9 @@ import ( const tenantBasePath = "tenant" -// TenantsService handles communication with the user related methods of the Xelon API. -type TenantsService service +// TenantsServiceV1 handles communication with the user related methods of the Xelon API. +// Deprecated. +type TenantsServiceV1 service type Tenant struct { Active bool `json:"active,omitempty"` @@ -21,7 +22,7 @@ type Tenant struct { // GetCurrent provides information about organization. // // Note, after calling this method only TenantID field is filled. -func (s *TenantsService) GetCurrent(ctx context.Context) (*Tenant, *Response, error) { +func (s *TenantsServiceV1) GetCurrent(ctx context.Context) (*Tenant, *Response, error) { path := tenantBasePath req, err := s.client.NewRequest(http.MethodGet, path, nil) @@ -39,7 +40,7 @@ func (s *TenantsService) GetCurrent(ctx context.Context) (*Tenant, *Response, er } // List provides information about tenant (aka organizations). -func (s *TenantsService) List(ctx context.Context) ([]Tenant, *Response, error) { +func (s *TenantsServiceV1) List(ctx context.Context) ([]Tenant, *Response, error) { path := "tenants" req, err := s.client.NewRequest(http.MethodGet, path, nil) diff --git a/xelon/tenants_test.go b/xelon/tenants_v1_test.go similarity index 100% rename from xelon/tenants_test.go rename to xelon/tenants_v1_test.go diff --git a/xelon/types.go b/xelon/types_v1.go similarity index 100% rename from xelon/types.go rename to xelon/types_v1.go