diff --git a/docs/style-guide/sdk.md b/docs/style-guide/sdk.md index 37258d2c..2210a81b 100644 --- a/docs/style-guide/sdk.md +++ b/docs/style-guide/sdk.md @@ -18,13 +18,16 @@ When this document refers to the SDK, it references the code in the [/proxmox](. - [Implementation of the Validator Pattern](#implementation-of-the-validator-pattern) - [Explicit Validator](#explicit-validator) - [Implicit Validator](#implicit-validator) + - [Validation](#validation) - [Validator Errors](#validator-errors) - [Error Constant](#error-constant) - [Error Function](#error-function) - - [Safe and Unsafe Functions](#safe-and-unsafe-functions) - - [Safe function](#safe-function) - - [Unsafe function](#unsafe-function) - [Public and Private](#public-and-private) + - [Types](#types) + - [Public Types](#public-types) + - [Private Types](#private-types) + - [Enumerations](#enumerations) + - [Safe and Unsafe functions](#safe-and-unsafe-functions) - [Standardized Interfaces](#standardized-interfaces) - [Pure and Impure Functions](#pure-and-impure-functions) - [Pure Functions](#pure-functions) @@ -231,6 +234,34 @@ err := StringValidate(exampleString) } ``` +### Validation + +By default, all functions validate user input unless explicitly stated otherwise. Functions that bypass validation are suffixed with `NoCheck`. These `NoCheck` functions provide developers with the flexibility to skip validation when they are certain the input is already validated. + +In some scenarios, input validation might require multiple API calls, which can impact performance. By offering a choice between performance optimization and strict validation, the SDK ensures both efficiency and correctness, making it more developer-friendly. + +```go +type User struct + +// Create validates input before proceeding. +func (user *User) Create(password string) (err error) { + err = user.Validate() + if err != nil { + return + } + // Additional validation logic (omitted for brevity). + err = user.CreateNoCheck(password) + return +} + +// CreateNoCheck skips validation entirely. +func (user *User) CreateNoCheck(password string) (err error) { + // Implementation omitted for brevity. + return +} + +``` + ### Validator Errors When dealing with validation errors, it is crucial for the SDK to respond with a clear and informative error message. @@ -275,45 +306,6 @@ func (u UserName) Error_InvalidUsername() error { } ``` -## Safe and Unsafe Functions - -Safe and unsafe functions serve as key components for interacting with the API. The rationale behind their existence lies in the trade-off between validating input for correctness and maintaining performance efficiency. For instance, consider the validation of whether a given name adheres to the API's naming conventions. While this validation is essential, performing it with every API interaction can significantly impact performance. - -In certain scenarios, input validation may necessitate multiple API calls. Explicit unsafe functions are introduced to convey to developers that input validation is not carried out automatically, placing the responsibility for validation squarely on the developer. By offering both safe and unsafe functions, the SDK becomes more developer-friendly, as it allows developers to make informed choices between performance optimization and safety without the need to create their customized SDK version. - -### Safe function - -By default, all functions are considered safe functions, meaning that input validation occurs before the function execution. These functions are expected to provide developers with clear error messages when the input is invalid. - -```go -type User struct - -func (user *User) Create(password string) (err error) { - err = user.Validate() - if err != nil { - return - } - // omitted for brevity. - // more validation logic. - err = user.Create_Unsafe(password) - return -} -``` - -### Unsafe function - -Unsafe functions, on the other hand, do not validate the input. These functions directly transmit the provided data to the API. They should be employed when the input is already validated, either by the developer or by a safe function. - -```go -type User struct - -// No validation is done here. -func (user *User) Create_Unsafe(password string) (err error) { - // omitted for brevity. - return -} -``` - ## Public and Private In crafting our SDK, we prioritize developer-friendliness, aiming to make it as intuitive as possible. @@ -346,6 +338,10 @@ For private types we use the following naming conventions: For an internal enum type, the name must be suffixed with `Enum`. +## Safe and Unsafe functions + +By default, all functions in the SDK are safe unless explicitly stated otherwise. Functions suffixed with `_Unsafe` are considered unsafe and should be used sparingly. These functions are intended for internal use only and should never be exposed publicly. + ## Standardized Interfaces Standardized interfaces are key in software development for consistent functionality exposure. They enhance code understanding, usage, and system interoperability. diff --git a/proxmox/config_guest.go b/proxmox/config_guest.go index 30902642..79468097 100644 --- a/proxmox/config_guest.go +++ b/proxmox/config_guest.go @@ -184,32 +184,32 @@ func GuestReboot(ctx context.Context, vmr *VmRef, client *Client) (err error) { return } -func guestSetPool_Unsafe(ctx context.Context, c *Client, guestID uint, newPool PoolName, currentPool *PoolName, version Version) (err error) { +func guestSetPoolNoCheck(ctx context.Context, c *Client, guestID uint, newPool PoolName, currentPool *PoolName, version Version) (err error) { if newPool == "" { if *currentPool != "" { // leave pool - if err = (*currentPool).removeGuests_Unsafe(ctx, c, []uint{guestID}, version); err != nil { + if err = (*currentPool).removeGuestsNoCheck(ctx, c, []uint{guestID}, version); err != nil { return } } } else { if *currentPool == "" { // join pool if version.Smaller(Version{8, 0, 0}) { - if err = newPool.addGuests_UnsafeV7(ctx, c, []uint{guestID}); err != nil { + if err = newPool.addGuestsNoCheckV7(ctx, c, []uint{guestID}); err != nil { return } } else { - newPool.addGuests_UnsafeV8(ctx, c, []uint{guestID}) + newPool.addGuestsNoCheckV8(ctx, c, []uint{guestID}) } } else if newPool != *currentPool { // change pool if version.Smaller(Version{8, 0, 0}) { - if err = (*currentPool).removeGuests_Unsafe(ctx, c, []uint{guestID}, version); err != nil { + if err = (*currentPool).removeGuestsNoCheck(ctx, c, []uint{guestID}, version); err != nil { return } - if err = newPool.addGuests_UnsafeV7(ctx, c, []uint{guestID}); err != nil { + if err = newPool.addGuestsNoCheckV7(ctx, c, []uint{guestID}); err != nil { return } } else { - if err = newPool.addGuests_UnsafeV8(ctx, c, []uint{guestID}); err != nil { + if err = newPool.addGuestsNoCheckV8(ctx, c, []uint{guestID}); err != nil { return } } diff --git a/proxmox/config_pool.go b/proxmox/config_pool.go index f9598d04..6b3c250b 100644 --- a/proxmox/config_pool.go +++ b/proxmox/config_pool.go @@ -94,16 +94,16 @@ func (config ConfigPool) Create(ctx context.Context, c *Client) error { return err } // TODO check permissions - if exists, err := config.Name.Exists_Unsafe(ctx, c); err != nil { + if exists, err := config.Name.ExistsNoCheck(ctx, c); err != nil { return err } else if exists { return errors.New(PoolName_Error_Exists) } - return config.Create_Unsafe(ctx, c) + return config.CreateNoCheck(ctx, c) } -// Create_Unsafe creates a new pool without validating the input -func (config ConfigPool) Create_Unsafe(ctx context.Context, c *Client) error { +// CreateNoCheck creates a new pool without validating the input +func (config ConfigPool) CreateNoCheck(ctx context.Context, c *Client) error { version, err := c.GetVersion(ctx) if err != nil { return err @@ -112,7 +112,7 @@ func (config ConfigPool) Create_Unsafe(ctx context.Context, c *Client) error { return err } if config.Guests != nil { - return config.Name.addGuests_Unsafe(ctx, c, *config.Guests, nil, version) + return config.Name.addGuestsNoCheck(ctx, c, *config.Guests, nil, version) } return nil } @@ -132,18 +132,18 @@ func (config ConfigPool) Set(ctx context.Context, c *Client) error { return err } // TODO check permissions - return config.Set_Unsafe(ctx, c) + return config.SetNoCheck(ctx, c) } -func (config ConfigPool) Set_Unsafe(ctx context.Context, c *Client) error { - exists, err := config.Name.Exists_Unsafe(ctx, c) +func (config ConfigPool) SetNoCheck(ctx context.Context, c *Client) error { + exists, err := config.Name.ExistsNoCheck(ctx, c) if err != nil { return err } if exists { - return config.Update_Unsafe(ctx, c) + return config.UpdateNoCheck(ctx, c) } - return config.Create_Unsafe(ctx, c) + return config.CreateNoCheck(ctx, c) } func (config ConfigPool) Update(ctx context.Context, c *Client) error { @@ -159,16 +159,16 @@ func (config ConfigPool) Update(ctx context.Context, c *Client) error { return errors.New(PoolName_Error_NotExists) } // TODO check permissions - return config.Update_Unsafe(ctx, c) + return config.UpdateNoCheck(ctx, c) } -// Update_Unsafe updates a pool without validating the input -func (config ConfigPool) Update_Unsafe(ctx context.Context, c *Client) error { +// UpdateNoCheck updates a pool without validating the input +func (config ConfigPool) UpdateNoCheck(ctx context.Context, c *Client) error { version, err := c.GetVersion(ctx) if err != nil { return err } - current, err := config.Name.Get_Unsafe(ctx, c) + current, err := config.Name.GetNoCheck(ctx, c) if err != nil { return err } @@ -178,7 +178,7 @@ func (config ConfigPool) Update_Unsafe(ctx context.Context, c *Client) error { } } if config.Guests != nil { - return config.Name.SetGuests_Unsafe(ctx, c, *config.Guests) + return config.Name.SetGuestsNoChecks(ctx, c, *config.Guests) } return nil } @@ -201,7 +201,7 @@ const ( var regex_PoolName = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`) -func (config PoolName) addGuests_Unsafe(ctx context.Context, c *Client, guestIDs []uint, currentGuests *[]uint, version Version) error { +func (config PoolName) addGuestsNoCheck(ctx context.Context, c *Client, guestIDs []uint, currentGuests *[]uint, version Version) error { var guestsToAdd []uint if currentGuests != nil && len(*currentGuests) > 0 { guestsToAdd = subtractArray(guestIDs, *currentGuests) @@ -212,26 +212,26 @@ func (config PoolName) addGuests_Unsafe(ctx context.Context, c *Client, guestIDs return nil } if !version.Smaller(Version{8, 0, 0}) { - return config.addGuests_UnsafeV8(ctx, c, guestsToAdd) + return config.addGuestsNoCheckV8(ctx, c, guestsToAdd) } guests, err := ListGuests(ctx, c) if err != nil { return err } for i, e := range PoolName("").guestsToRemoveFromPools(guests, guestsToAdd) { - if err = i.removeGuests_Unsafe(ctx, c, e, version); err != nil { + if err = i.removeGuestsNoCheck(ctx, c, e, version); err != nil { return err } } - return config.addGuests_UnsafeV7(ctx, c, guestsToAdd) + return config.addGuestsNoCheckV7(ctx, c, guestsToAdd) } -func (pool PoolName) addGuests_UnsafeV7(ctx context.Context, c *Client, guestIDs []uint) error { +func (pool PoolName) addGuestsNoCheckV7(ctx context.Context, c *Client, guestIDs []uint) error { return pool.putV7(ctx, c, map[string]interface{}{"vms": PoolName("").mapToString(guestIDs)}) } // from 8.0.0 on proxmox can move the guests to the pool while they are still in another pool -func (pool PoolName) addGuests_UnsafeV8(ctx context.Context, c *Client, guestIDs []uint) error { +func (pool PoolName) addGuestsNoCheckV8(ctx context.Context, c *Client, guestIDs []uint) error { return pool.putV8(ctx, c, map[string]interface{}{ "vms": PoolName("").mapToString(guestIDs), "allow-move": "1"}) @@ -242,26 +242,26 @@ func (config PoolName) AddGuests(ctx context.Context, c *Client, guestIDs []uint return err } // TODO: permission check - exists, err := config.Exists_Unsafe(ctx, c) + exists, err := config.ExistsNoCheck(ctx, c) if err != nil { return err } if !exists { return errors.New(PoolName_Error_NotExists) } - return config.AddGuests_Unsafe(ctx, c, guestIDs) + return config.AddGuestsNoCheck(ctx, c, guestIDs) } -func (pool PoolName) AddGuests_Unsafe(ctx context.Context, c *Client, guestIDs []uint) error { +func (pool PoolName) AddGuestsNoCheck(ctx context.Context, c *Client, guestIDs []uint) error { version, err := c.GetVersion(ctx) if err != nil { return err } - config, err := pool.Get_Unsafe(ctx, c) + config, err := pool.GetNoCheck(ctx, c) if err != nil { return err } - return pool.addGuests_Unsafe(ctx, c, guestIDs, config.Guests, version) + return pool.addGuestsNoCheck(ctx, c, guestIDs, config.Guests, version) } func (config PoolName) Delete(ctx context.Context, c *Client) error { @@ -269,17 +269,17 @@ func (config PoolName) Delete(ctx context.Context, c *Client) error { return err } // TODO: permission check - exists, err := config.Exists_Unsafe(ctx, c) + exists, err := config.ExistsNoCheck(ctx, c) if err != nil { return err } if !exists { return errors.New(PoolName_Error_NotExists) } - return config.Delete_Unsafe(ctx, c) + return config.DeleteNoCheck(ctx, c) } -func (config PoolName) Delete_Unsafe(ctx context.Context, c *Client) error { +func (config PoolName) DeleteNoCheck(ctx context.Context, c *Client) error { if c == nil { return errors.New(Client_Error_Nil) } @@ -294,10 +294,10 @@ func (config PoolName) Exists(ctx context.Context, c *Client) (bool, error) { return false, err } // TODO: permission check - return config.Exists_Unsafe(ctx, c) + return config.ExistsNoCheck(ctx, c) } -func (config PoolName) Exists_Unsafe(ctx context.Context, c *Client) (bool, error) { +func (config PoolName) ExistsNoCheck(ctx context.Context, c *Client) (bool, error) { raw, err := listPools(ctx, c) if err != nil { return false, err @@ -310,10 +310,10 @@ func (pool PoolName) Get(ctx context.Context, c *Client) (*ConfigPool, error) { return nil, err } // TODO: permission check - return pool.Get_Unsafe(ctx, c) + return pool.GetNoCheck(ctx, c) } -func (pool PoolName) Get_Unsafe(ctx context.Context, c *Client) (*ConfigPool, error) { +func (pool PoolName) GetNoCheck(ctx context.Context, c *Client) (*ConfigPool, error) { if c == nil { return nil, errors.New(Client_Error_Nil) } @@ -385,23 +385,23 @@ func (pool PoolName) RemoveGuests(ctx context.Context, c *Client, guestID []uint return errors.New(PoolName_Error_NoGuestsSpecified) } // TODO: permission check - if exists, err := pool.Exists_Unsafe(ctx, c); err != nil { + if exists, err := pool.ExistsNoCheck(ctx, c); err != nil { return err } else if !exists { return errors.New(PoolName_Error_NotExists) } - return pool.removeGuests_Unsafe(ctx, c, guestID, version) + return pool.removeGuestsNoCheck(ctx, c, guestID, version) } -func (pool PoolName) RemoveGuests_Unsafe(ctx context.Context, c *Client, guestID []uint) error { +func (pool PoolName) RemoveGuestsNoChecks(ctx context.Context, c *Client, guestID []uint) error { version, err := c.GetVersion(ctx) if err != nil { return err } - return pool.removeGuests_Unsafe(ctx, c, guestID, version) + return pool.removeGuestsNoCheck(ctx, c, guestID, version) } -func (pool PoolName) removeGuests_Unsafe(ctx context.Context, c *Client, guestID []uint, version Version) error { +func (pool PoolName) removeGuestsNoCheck(ctx context.Context, c *Client, guestID []uint, version Version) error { return pool.put(ctx, c, map[string]interface{}{ "vms": PoolName("").mapToString(guestID), "delete": "1"}, @@ -421,10 +421,10 @@ func (pool PoolName) SetGuests(ctx context.Context, c *Client, guestID []uint) e return errors.New(PoolName_Error_NotExists) } // TODO: permission check - return pool.SetGuests_Unsafe(ctx, c, guestID) + return pool.SetGuestsNoChecks(ctx, c, guestID) } -func (pool PoolName) SetGuests_Unsafe(ctx context.Context, c *Client, guestID []uint) error { +func (pool PoolName) SetGuestsNoChecks(ctx context.Context, c *Client, guestID []uint) error { version, err := c.GetVersion(ctx) if err != nil { return err @@ -433,16 +433,16 @@ func (pool PoolName) SetGuests_Unsafe(ctx context.Context, c *Client, guestID [] if err != nil { return err } - return pool.setGuests_Unsafe(ctx, c, guestID, config.Guests, version) + return pool.setGuestsNoCheck(ctx, c, guestID, config.Guests, version) } -func (pool PoolName) setGuests_Unsafe(ctx context.Context, c *Client, guestIDs []uint, currentGuests *[]uint, version Version) error { +func (pool PoolName) setGuestsNoCheck(ctx context.Context, c *Client, guestIDs []uint, currentGuests *[]uint, version Version) error { if currentGuests != nil && len(*currentGuests) > 0 { - if err := pool.removeGuests_Unsafe(ctx, c, subtractArray(*currentGuests, guestIDs), version); err != nil { + if err := pool.removeGuestsNoCheck(ctx, c, subtractArray(*currentGuests, guestIDs), version); err != nil { return err } } - return pool.addGuests_Unsafe(ctx, c, guestIDs, currentGuests, version) + return pool.addGuestsNoCheck(ctx, c, guestIDs, currentGuests, version) } func (config PoolName) Validate() error { diff --git a/proxmox/config_pool_test.go b/proxmox/config_pool_test.go index 449bed18..aa2183f1 100644 --- a/proxmox/config_pool_test.go +++ b/proxmox/config_pool_test.go @@ -136,9 +136,9 @@ func Test_ConfigPool_Create(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_ConfigPool_Create_Unsafe(t *testing.T) { +func Test_ConfigPool_CreateNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.Create_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.CreateNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -160,9 +160,9 @@ func Test_ConfigPool_Set(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_ConfigPool_Set_Unsafe(t *testing.T) { +func Test_ConfigPool_SetNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.Set_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.SetNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -172,9 +172,9 @@ func Test_ConfigPool_Update(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_ConfigPool_Update_Unsafe(t *testing.T) { +func Test_ConfigPool_UpdateNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.Update_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { err = ConfigPool{Name: "test"}.UpdateNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -209,9 +209,9 @@ func Test_PoolName_AddGuests(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_AddGuests_Unsafe(t *testing.T) { +func Test_PoolName_AddGuestsNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = PoolName("test").AddGuests_Unsafe(context.Background(), nil, nil) }) + require.NotPanics(t, func() { err = PoolName("test").AddGuestsNoCheck(context.Background(), nil, nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -221,9 +221,9 @@ func Test_PoolName_Delete(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_Delete_Unsafe(t *testing.T) { +func Test_PoolName_DeleteNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = PoolName("test").Delete_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { err = PoolName("test").DeleteNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -233,9 +233,9 @@ func Test_PoolName_Exists(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_Exists_Unsafe(t *testing.T) { +func Test_PoolName_ExistsNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { _, err = PoolName("test").Exists_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { _, err = PoolName("test").ExistsNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -245,9 +245,9 @@ func Test_PoolName_Get(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_Get_Unsafe(t *testing.T) { +func Test_PoolName_GetNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { _, err = PoolName("test").Get_Unsafe(context.Background(), nil) }) + require.NotPanics(t, func() { _, err = PoolName("test").GetNoCheck(context.Background(), nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -306,9 +306,9 @@ func Test_PoolName_RemoveGuests(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_RemoveGuests_Unsafe(t *testing.T) { +func Test_PoolName_RemoveGuestsNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = PoolName("test").RemoveGuests_Unsafe(context.Background(), nil, nil) }) + require.NotPanics(t, func() { err = PoolName("test").RemoveGuestsNoChecks(context.Background(), nil, nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } @@ -318,9 +318,9 @@ func Test_PoolName_SetGuests(t *testing.T) { require.Equal(t, errors.New(Client_Error_Nil), err) } -func Test_PoolName_SetGuests_Unsafe(t *testing.T) { +func Test_PoolName_SetGuestsNoCheck(t *testing.T) { var err error - require.NotPanics(t, func() { err = PoolName("test").SetGuests_Unsafe(context.Background(), nil, nil) }) + require.NotPanics(t, func() { err = PoolName("test").SetGuestsNoChecks(context.Background(), nil, nil) }) require.Equal(t, errors.New(Client_Error_Nil), err) } diff --git a/proxmox/config_qemu.go b/proxmox/config_qemu.go index 31d37ce7..b4ae949f 100644 --- a/proxmox/config_qemu.go +++ b/proxmox/config_qemu.go @@ -573,7 +573,7 @@ func (newConfig ConfigQemu) setAdvanced(ctx context.Context, currentConfig *Conf } if newConfig.Pool != nil { // update pool membership - guestSetPool_Unsafe(ctx, client, uint(vmr.vmId), *newConfig.Pool, currentConfig.Pool, version) + guestSetPoolNoCheck(ctx, client, uint(vmr.vmId), *newConfig.Pool, currentConfig.Pool, version) } if stopped { // start vm if it was stopped diff --git a/proxmox/snapshot.go b/proxmox/snapshot.go index ee63c627..b5d749d6 100644 --- a/proxmox/snapshot.go +++ b/proxmox/snapshot.go @@ -33,11 +33,11 @@ func (config ConfigSnapshot) Create(ctx context.Context, c *Client, vmr *VmRef) if err = config.Validate(); err != nil { return } - return config.Create_Unsafe(ctx, c, vmr) + return config.CreateNoCheck(ctx, c, vmr) } // Create a snapshot without validating the input, use ConfigSnapshot.Create() to validate the input. -func (config ConfigSnapshot) Create_Unsafe(ctx context.Context, c *Client, vmr *VmRef) error { +func (config ConfigSnapshot) CreateNoCheck(ctx context.Context, c *Client, vmr *VmRef) error { params := config.mapToApiValues() _, err := c.PostWithTask(ctx, params, "/nodes/"+vmr.node.String()+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/") if err != nil { @@ -156,11 +156,11 @@ func (snap SnapshotName) Delete(ctx context.Context, c *Client, vmr *VmRef) (exi return } // TODO check if snapshot exists - return snap.Delete_Unsafe(ctx, c, vmr) + return snap.DeleteNoCheck(ctx, c, vmr) } // Deletes the specified snapshot without validating the input, use SnapshotName.Delete() to validate the input. -func (snap SnapshotName) Delete_Unsafe(ctx context.Context, c *Client, vmr *VmRef) (exitStatus string, err error) { +func (snap SnapshotName) DeleteNoCheck(ctx context.Context, c *Client, vmr *VmRef) (exitStatus string, err error) { return c.DeleteWithTask(ctx, "/nodes/"+vmr.node.String()+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/"+string(snap)) } @@ -173,11 +173,11 @@ func (snap SnapshotName) Rollback(ctx context.Context, c *Client, vmr *VmRef) (e return } // TODO check if snapshot exists - return snap.Rollback_Unsafe(ctx, c, vmr) + return snap.RollbackNoCheck(ctx, c, vmr) } // Rollback to the specified snapshot without validating the input, use SnapshotName.Rollback() to validate the input. -func (snap SnapshotName) Rollback_Unsafe(ctx context.Context, c *Client, vmr *VmRef) (exitStatus string, err error) { +func (snap SnapshotName) RollbackNoCheck(ctx context.Context, c *Client, vmr *VmRef) (exitStatus string, err error) { return c.PostWithTask(ctx, nil, "/nodes/"+vmr.node.String()+"/"+vmr.vmType+"/"+strconv.FormatInt(int64(vmr.vmId), 10)+"/snapshot/"+string(snap)+"/rollback") } @@ -190,11 +190,11 @@ func (snap SnapshotName) UpdateDescription(ctx context.Context, c *Client, vmr * return } // TODO check if snapshot exists - return snap.UpdateDescription_Unsafe(ctx, c, vmr, description) + return snap.UpdateDescriptionNoCheck(ctx, c, vmr, description) } // Updates the description of the specified snapshot without validating the input, use SnapshotName.UpdateDescription() to validate the input. -func (snap SnapshotName) UpdateDescription_Unsafe(ctx context.Context, c *Client, vmr *VmRef, description string) error { +func (snap SnapshotName) UpdateDescriptionNoCheck(ctx context.Context, c *Client, vmr *VmRef, description string) error { return c.Put(ctx, map[string]interface{}{"description": description}, "/nodes/"+vmr.node.String()+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/"+string(snap)+"/config") }