common

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Index

Constants

View Source
const (
	// VeryShortDuration is a duration for very short-term cache
	VeryShortDuration = 1 * time.Second
	// ShortDuration is a duration for short-term cache
	ShortDuration = 2 * time.Second
	// MediumDuration is a duration for medium-term cache
	MediumDuration = 5 * time.Second
	// LongDuration is a duration for long-term cache
	LongDuration = 10 * time.Second
)
View Source
const (
	// StrSpiderRestUrl              string = "SPIDER_REST_URL"
	// StrDragonflyRestUrl           string = "DRAGONFLY_REST_URL"
	StrTumblebugRestUrl           string = "TUMBLEBUG_REST_URL"
	StrDBUrl                      string = "DB_URL"
	StrDBDatabase                 string = "DB_DATABASE"
	StrDBUser                     string = "DB_USER"
	StrDBPassword                 string = "DB_PASSWORD"
	StrAutocontrolDurationMs      string = "AUTOCONTROL_DURATION_MS"
	CbStoreKeyNotFoundErrorString string = "key not found"
	StrAdd                        string = "add"
	StrDelete                     string = "delete"
	StrSSHKey                     string = "sshKey"
	StrImage                      string = "image"
	StrCustomImage                string = "customImage"
	StrSecurityGroup              string = "securityGroup"
	StrSpec                       string = "spec"
	StrVNet                       string = "vNet"
	StrSubnet                     string = "subnet"
	StrDataDisk                   string = "dataDisk"
	StrNLB                        string = "nlb"
	StrVM                         string = "vm"
	StrMCIS                       string = "mcis"
	StrDefaultResourceName        string = "-systemdefault-"

	// SystemCommonNs is const for SystemCommon NameSpace ID
	SystemCommonNs string = "system-purpose-common-ns"
)
View Source
const (
	AttachDataDisk    string = "attach"
	DetachDataDisk    string = "detach"
	AvailableDataDisk string = "available"
)

type DataDiskCmd string

View Source
const NoBody = "NOBODY"

NoBody is a constant for empty body

Variables

View Source
var AutocontrolDurationMs string

CB-Store

View Source
var CBStore icbs.Store
View Source
var DBDatabase string
View Source
var DBPassword string
View Source
var DBUrl string
View Source
var DBUser string
View Source
var DefaulNamespaceId = "ns-mig01"
View Source
var MyDB *sql.DB
View Source
var RequestMap = sync.Map{}

RequestMap is a map for request details

View Source
var RuntimeCloudInfo = CloudInfo{}

RuntimeCloudInfo is global variable for CloudInfo

View Source
var RuntimeConf = RuntimeConfig{}

RuntimeConf is global variable for cloud config

View Source
var RuntimeCredential = Credential{}
View Source
var RuntimeLatancyMap = [][]string{}

RuntimeLatancyMap is global variable for LatancyMap

View Source
var RuntimeLatancyMapIndex = make(map[string]int)

RuntimeLatancyMapIndex is global variable for LatancyMap (index)

View Source
var StartTime string
View Source
var SystemReady bool

SystemReady is global variable for checking SystemReady status

View Source
var TumblebugRestUrl string

var SpiderRestUrl string var DragonflyRestUrl string

Functions

func ChangeIdString

func ChangeIdString(name string) string

ChangeIdString is func to change strings in id or name (special chars to -, to lower string )

func CheckConfig

func CheckConfig(id string) (bool, error)

func CheckElement

func CheckElement(a string, list []string) bool

func CheckString

func CheckString(name string) error

CheckString is func to check string by the given rule `[a-z]([-a-z0-9]*[a-z0-9])?`

func ConvertToMessage

func ConvertToMessage(inType string, inData string, obj interface{}) error

ConvertToMessage is func to change input data to gRPC message

func ConvertToOutput

func ConvertToOutput(outType string, obj interface{}) (string, error)

ConvertToOutput is func to convert gRPC message to print format

func CopySrcToDest

func CopySrcToDest(src interface{}, dest interface{}) error

CopySrcToDest is func to copy data from source to target

func DeleteObject

func DeleteObject(key string) error

DeleteObject is func to delete the object

func DeleteObjects

func DeleteObjects(key string) error

DeleteObjects is func to delete objects

func EndRequestWithLog added in v0.1.1

func EndRequestWithLog(c echo.Context, reqID string, err error, responseData interface{}) error

EndRequestWithLog updates the request details and sends the final response.

func ExecuteHttpRequest

func ExecuteHttpRequest[B any, T any](
	client *resty.Client,
	method string,
	url string,
	headers map[string]string,
	useBody bool,
	body *B,
	result *T,
	cacheDuration time.Duration,
) error

ExecuteHttpRequest performs the HTTP request and fills the result (var requestBody interface{} = nil for empty body)

func GenChildResourceKey

func GenChildResourceKey(nsId string, resourceType string, parentResourceId string, resourceId string) string

GenChildResourceKey is func to generate a key from resource type and id

func GenMcisKey

func GenMcisKey(nsId string, mcisId string, vmId string) string

GenMcisKey is func to generate a key used in keyValue store

func GenMcisPolicyKey

func GenMcisPolicyKey(nsId string, mcisId string, vmId string) string

GenMcisPolicyKey is func to generate Mcis policy key

func GenMcisSubGroupKey

func GenMcisSubGroupKey(nsId string, mcisId string, groupId string) string

GenMcisSubGroupKey is func to generate a key from subGroupId used in keyValue store

func GenRandomPassword

func GenRandomPassword(length int) string

GenRandomPassword is func to return a RandomPassword

func GenResourceKey

func GenResourceKey(nsId string, resourceType string, resourceId string) string

GenResourceKey is func to generate a key from resource type and id

func GenUid

func GenUid() string

GenUid is func to return a UUID string

func GenerateNewRandomString

func GenerateNewRandomString(n int) string

generate a random string (from CB-MCKS source code)

func GetChildIdList

func GetChildIdList(key string) []string

GetChildIdList is func to get child id list from given key

func GetCspResourceId

func GetCspResourceId(nsId string, resourceType string, resourceId string) (string, error)

GetCspResourceId is func to retrieve CSP native resource ID

func GetFuncName

func GetFuncName() string

GetFuncName is func to get the name of the running function

func GetObjectList

func GetObjectList(key string) []string

GetObjectList is func to return IDs of each child objects that has the same key

func GetObjectValue

func GetObjectValue(key string) (string, error)

GetObjectValue is func to return the object value

func InitAllConfig

func InitAllConfig() error

func InitConfig

func InitConfig(id string) error

func ListConfigId

func ListConfigId() []string

func LookupKeyValueList

func LookupKeyValueList(kvl []KeyValue, key string) string

LookupKeyValueList is func to lookup KeyValue list

func NVL

func NVL(str string, def string) string

NVL is func for null value logic

func OpenSQL

func OpenSQL(path string) error

func PrintJsonPretty

func PrintJsonPretty(v interface{})

PrintJsonPretty is func to print JSON pretty with indent

func RandomSleep

func RandomSleep(from int, to int)

RandomSleep is func to make a caller waits for during random time seconds (random value within x~y)

func SelectDatabase

func SelectDatabase(database string) error

func SetUseBody

func SetUseBody(requestBody interface{}) bool

SetUseBody returns false if the given body is NoBody

func StartRequestWithLog added in v0.1.1

func StartRequestWithLog(c echo.Context) (string, error)

StartRequestWithLog initializes request tracking details

func ToLower

func ToLower(name string) string

ToLower is func to change strings (_ to -, " " to -, to lower string ) (deprecated soon)

func UpdateGlobalVariable

func UpdateGlobalVariable(id string) error

Types

type CSPDetail added in v0.1.2

type CSPDetail struct {
	Description string                  `mapstructure:"description" json:"description"`
	Driver      string                  `mapstructure:"driver" json:"driver"`
	Links       []string                `mapstructure:"link" json:"links"`
	Regions     map[string]RegionDetail `mapstructure:"region" json:"regions"`
}

CSPDetail is structure for CSP information

type CacheItem

type CacheItem[T any] struct {
	Response  T
	ExpiresAt time.Time
}

CacheItem is a struct to store cached item

type Cloud

type Cloud struct {
	Common    CloudSetting `yaml:"common"`
	Aws       CloudSetting `yaml:"aws"`
	Azure     CloudSetting `yaml:"azure"`
	Gcp       CloudSetting `yaml:"gcp"`
	Alibaba   CloudSetting `yaml:"alibaba"`
	Tencent   CloudSetting `yaml:"tencent"`
	Ibm       CloudSetting `yaml:"ibm"`
	Openstack CloudSetting `yaml:"openstack"`
	Cloudit   CloudSetting `yaml:"cloudit"`
}

Cloud is structure for cloud settings per CSP

type CloudDriverInfo added in v0.1.2

type CloudDriverInfo struct {
	DriverName        string
	ProviderName      string
	DriverLibFileName string
}

CloudDriverInfo is struct for containing a CB-Spider struct for cloud driver info

type CloudInfo added in v0.1.2

type CloudInfo struct {
	CSPs map[string]CSPDetail `mapstructure:"cloud" json:"csps"`
}

CloudInfo is structure for cloud information

type CloudSetting

type CloudSetting struct {
	Enable string     `yaml:"enable"`
	Nlb    NlbSetting `yaml:"nlb"`
}

CloudSetting is structure for cloud settings per CSP in details

type ConfigInfo

type ConfigInfo struct {
	Id    string `json:"id" example:"SPIDER_REST_URL"`
	Name  string `json:"name" example:"SPIDER_REST_URL"`
	Value string `json:"value" example:"http://localhost:1024/spider"`
}

swagger:response ConfigInfo

func GetConfig

func GetConfig(id string) (ConfigInfo, error)

func ListConfig

func ListConfig() ([]ConfigInfo, error)

func UpdateConfig

func UpdateConfig(u *ConfigReq) (ConfigInfo, error)

type ConfigReq

type ConfigReq struct {
	Name  string `json:"name" example:"SPIDER_REST_URL"`
	Value string `json:"value" example:"http://localhost:1024/spider"`
}

swagger:request ConfigReq

type ConnConfig

type ConnConfig struct {
	ConfigName           string         `json:"configName"`
	ProviderName         string         `json:"providerName"`
	DriverName           string         `json:"driverName"`
	CredentialName       string         `json:"credentialName"`
	CredentialHolder     string         `json:"credentialHolder"`
	RegionZoneInfoName   string         `json:"regionZoneInfoName"`
	RegionZoneInfo       RegionZoneInfo `json:"regionZoneInfo"`
	RegionDetail         RegionDetail   `json:"regionDetail"`
	RegionRepresentative bool           `json:"regionRepresentative"`
	Verified             bool           `json:"verified"`
}

ConnConfig is struct for containing modified CB-Spider struct for connection config

type Credential added in v0.1.2

type Credential struct {
	Credentialholder map[string]map[string]map[string]string `yaml:"credentialholder"`
}

type CredentialInfo added in v0.1.2

type CredentialInfo struct {
	CredentialName   string     `json:"credentialName"`
	CredentialHolder string     `json:"credentialHolder"`
	ProviderName     string     `json:"providerName"`
	KeyValueInfoList []KeyValue `json:"keyValueInfoList"`
}

CredentialInfo is struct for containing a struct for credential info

type CredentialReq added in v0.1.2

type CredentialReq struct {
	CredentialHolder string     `json:"credentialHolder"`
	ProviderName     string     `json:"providerName"`
	KeyValueInfoList []KeyValue `json:"keyValueInfoList"`
}

CredentialReq is struct for containing a struct for credential request

type IID

type IID struct {
	NameId   string // NameID by user
	SystemId string // SystemID by CloudOS
}

Spider 2020-03-30 https://github.com/cloud-barista/cb-spider/blob/master/cloud-control-manager/cloud-driver/interfaces/resources/IId.go

type IdList

type IdList struct {
	IdList []string `json:"output"`
}

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

type Location added in v0.1.1

type Location struct {
	Display   string  `mapstructure:"display" json:"display"`
	Latitude  float64 `mapstructure:"latitude" json:"latitude"`
	Longitude float64 `mapstructure:"longitude" json:"longitude"`
}

Location is structure for location information

type NlbSetting

type NlbSetting struct {
	Enable    string `yaml:"enable"`
	Interval  string `yaml:"interval"`
	Timeout   string `yaml:"timeout"`
	Threshold string `yaml:"threshold"`
}

NlbSetting is structure for NLB setting

type Nlbsw

type Nlbsw struct {
	Sw                      string `yaml:"sw"`
	Version                 string `yaml:"version"`
	CommandNlbPrepare       string `yaml:"commandNlbPrepare"`
	CommandNlbDeploy        string `yaml:"commandNlbDeploy"`
	CommandNlbAddTargetNode string `yaml:"commandNlbAddTargetNode"`
	CommandNlbApplyConfig   string `yaml:"commandNlbApplyConfig"`
	NlbMcisCommonSpec       string `yaml:"nlbMcisCommonSpec"`
	NlbMcisCommonImage      string `yaml:"nlbMcisCommonImage"`
	NlbMcisSubGroupSize     string `yaml:"nlbMcisSubGroupSize"`
}

Nlbsw is structure for NLB setting

type NsInfo

type NsInfo struct {
	Id          string `json:"id" example:"ns01"`
	Name        string `json:"name" example:"ns01"`
	Description string `json:"description" example:"Description for this namespace"`
}

swagger:response NsInfo

func CreateNamespace added in v0.1.1

func CreateNamespace(nsInfo NsReq) (NsInfo, error)

func GetNamespace added in v0.1.1

func GetNamespace(nsId string) (NsInfo, error)

type NsReq

type NsReq struct {
	Name        string `json:"name" example:"ns01"`
	Description string `json:"description" example:"Description for this namespace"`
}

type RegionDetail added in v0.1.2

type RegionDetail struct {
	RegionId    string   `mapstructure:"id" json:"regionId"`
	RegionName  string   `mapstructure:"regionName" json:"regionName"`
	Description string   `mapstructure:"description" json:"description"`
	Location    Location `mapstructure:"location" json:"location"`
	Zones       []string `mapstructure:"zone" json:"zones"`
}

RegionDetail is structure for region information

type RegionZoneInfo added in v0.1.2

type RegionZoneInfo struct {
	AssignedRegion string `json:"assignedRegion"`
	AssignedZone   string `json:"assignedZone"`
}

RegionZoneInfo is struct for containing region struct

type RequestDetails added in v0.1.1

type RequestDetails struct {
	StartTime     time.Time   `json:"startTime"`     // The time when the request was received by the server.
	EndTime       time.Time   `json:"endTime"`       // The time when the request was fully processed.
	Status        string      `json:"status"`        // The current status of the request (e.g., "Handling", "Error", "Success").
	RequestInfo   RequestInfo `json:"requestInfo"`   // Extracted information about the request.
	ResponseData  interface{} `json:"responseData"`  // The data sent back in response to the request.
	ErrorResponse string      `json:"errorResponse"` // A message describing any error that occurred during request processing.
}

RequestDetails contains detailed information about an HTTP request and its processing status.

type RequestInfo added in v0.1.1

type RequestInfo struct {
	Method string            `json:"method"`         // HTTP method (GET, POST, etc.), indicating the request's action type.
	URL    string            `json:"url"`            // The URL the request is made to.
	Header map[string]string `json:"header"`         // Key-value pairs of the request headers.
	Body   interface{}       `json:"body,omitempty"` // Optional: request body
}

RequestInfo stores the essential details of an HTTP request.

func ExtractRequestInfo added in v0.1.1

func ExtractRequestInfo(r *http.Request) RequestInfo

ExtractRequestInfo extracts necessary information from http.Request

type RestGetAllNsResponse added in v0.1.1

type RestGetAllNsResponse struct {
	//Name string     `json:"name"`
	Ns []NsInfo `json:"ns"`
}

Response structure for RestGetAllNs

func GetAllNamespaces added in v0.1.1

func GetAllNamespaces() (RestGetAllNsResponse, error)

type RuntimeConfig

type RuntimeConfig struct {
	Cloud Cloud `yaml:"cloud"`
	Nlbsw Nlbsw `yaml:"nlbsw"`
}

RuntimeConfig is structure for global variable for cloud config

type SimpleMsg

type SimpleMsg struct {
	Message string `json:"message" example:"Any message"`
}

SimpleMsg is struct for JSON Simple message

func DeleteNamespace added in v0.1.1

func DeleteNamespace(nsId string) (SimpleMsg, error)

type SpiderConnConfig added in v0.1.2

type SpiderConnConfig struct {
	ConfigName     string
	ProviderName   string
	DriverName     string
	CredentialName string
	RegionName     string
}

SpiderConnConfig is struct for containing a CB-Spider struct for connection config

type SpiderConnectionName

type SpiderConnectionName struct {
	ConnectionName string `json:"ConnectionName"`
}

type SpiderRegionZoneInfo added in v0.1.2

type SpiderRegionZoneInfo struct {
	RegionName        string     // ex) "region01"
	ProviderName      string     // ex) "GCP"
	KeyValueInfoList  []KeyValue // ex) { {region, us-east1}, {zone, us-east1-c} }
	AvailableZoneList []string
}

SpiderRegionZoneInfo is struct for containing region struct of CB-Spider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL