Update to version 1.1.0

This commit is contained in:
chihyuwu
2022-04-25 11:10:19 +00:00
parent f0066b40ca
commit ebe7c1d97c
32 changed files with 2197 additions and 445 deletions

View File

@@ -2,14 +2,28 @@
package utils
import (
"fmt"
)
type OutOfFreeSpaceError string
type AlreadyExistError string
type BadParametersError string
type NoSuchLunError string
type LunReachMaxCountError string
type TargetReachMaxCountError string
type NoSuchSnapshotError string
type BadLunTypeError string
type SnapshotReachMaxCountError string
type IscsiDefaultError string
type IscsiDefaultError struct {
ErrCode int
}
type NoSuchShareError string
type ShareReachMaxCountError string
type ShareSystemBusyError string
type ShareDefaultError struct {
ErrCode int
}
func (_ OutOfFreeSpaceError) Error() string {
return "Out of free space"
@@ -17,6 +31,14 @@ func (_ OutOfFreeSpaceError) Error() string {
func (_ AlreadyExistError) Error() string {
return "Already Existed"
}
func (_ BadParametersError) Error() string {
return "Invalid input value"
}
// ISCSI errors
func (_ NoSuchLunError) Error() string {
return "No such LUN"
}
func (_ LunReachMaxCountError) Error() string {
return "Number of LUN reach limit"
@@ -38,6 +60,23 @@ func (_ SnapshotReachMaxCountError) Error() string {
return "Number of snapshot reach limit"
}
func (_ IscsiDefaultError) Error() string {
return "Default ISCSI error"
}
func (e IscsiDefaultError) Error() string {
return fmt.Sprintf("ISCSI API error. Error code: %d", e.ErrCode)
}
// Share errors
func (_ NoSuchShareError) Error() string {
return "No such share"
}
func (_ ShareReachMaxCountError) Error() string {
return "Number of share reach limit"
}
func (_ ShareSystemBusyError) Error() string {
return "Share system is temporary busy"
}
func (e ShareDefaultError) Error() string {
return fmt.Sprintf("Share API error. Error code: %d", e.ErrCode)
}

View File

@@ -8,7 +8,42 @@ import (
"strings"
)
const UNIT_GB = 1024 * 1024 * 1024
type AuthType string
const (
UNIT_GB = 1024 * 1024 * 1024
UNIT_MB = 1024 * 1024
ProtocolSmb = "smb"
ProtocolIscsi = "iscsi"
ProtocolDefault = ProtocolIscsi
AuthTypeReadWrite AuthType = "rw"
AuthTypeReadOnly AuthType = "ro"
AuthTypeNoAccess AuthType = "no"
)
func SliceContains(items []string, s string) bool {
for _, item := range items {
if s == item {
return true
}
}
return false
}
func MBToBytes(size int64) int64 {
return size * UNIT_MB
}
func BytesToMB(size int64) int64 {
return size / UNIT_MB
}
// Ceiling
func BytesToMBCeil(size int64) int64 {
return (size + UNIT_MB - 1) / UNIT_MB
}
func StringToBoolean(value string) bool {
value = strings.ToLower(value)
@@ -30,4 +65,4 @@ func LookupIPv4(name string) ([]string, error) {
}
return nil, fmt.Errorf("Failed to LookupIPv4 by local resolver for: %s", name)
}
}