common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights resvered.

The common package defines some common functions, which are mainly used for the functions of the following services.

The difference between common package and utils:

  1. Common functions under common are related to the project, and common functions are placed here.
  2. Utils are some stored tool functions, which are not related to the project. Such as: date conversion, type conversion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaseInsensitiveFunc

func CaseInsensitiveFunc() schema.SchemaDiffSuppressFunc

func CheckDeleted

func CheckDeleted(d *schema.ResourceData, err error, msg string) error

CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so, sets the resource ID to the empty string instead of throwing an error.

func CheckDeletedDiag

func CheckDeletedDiag(d *schema.ResourceData, err error, msg string) diag.Diagnostics

CheckDeletedDiag checks the error to see if it's a 404 (Not Found) and, if so, sets the resource ID to the empty string instead of throwing an error.

func CheckForRetryableError

func CheckForRetryableError(err error) *resource.RetryError

func GetAutoPay

func GetAutoPay(d *schema.ResourceData) string

GetAutoPay is a method to return whether order is auto pay according to the user input. auto_pay parameter inputs and returns:

false: false
true, empty: true

Before using this function, make sure the parameter behavior is auto pay (the default value is "true").

func GetEipIDbyAddress

func GetEipIDbyAddress(client *golangsdk.ServiceClient, address, epsID string) (string, error)

GetEipIDbyAddress returns the EIP ID of address when success.

func GetEnterpriseProjectID

func GetEnterpriseProjectID(d *schema.ResourceData, config *config.Config) string

GetEnterpriseProjectID returns the enterprise_project_id that was specified in the resource. If it was not set, the provider-level value is checked. The provider-level value can either be set by the `enterprise_project_id` argument or by HCSO_ENTERPRISE_PROJECT_ID.

func GetRegion

func GetRegion(d *schema.ResourceData, config *config.Config) string

GetRegion returns the region that was specified ina the resource. If a region was not set, the provider-level region is checked. The provider-level region can either be set by the region argument or by HCSO_REGION_NAME.

func HasFilledOpt

func HasFilledOpt(d *schema.ResourceData, param string) bool

func MigrateEnterpriseProject

func MigrateEnterpriseProject(client *golangsdk.ServiceClient, targetEPSId string, migrateOpts enterpriseprojects.MigrateResourceOpts) error

func NewCustomClient

func NewCustomClient(insecure bool, endpoints ...string) *golangsdk.ServiceClient

NewCustomClient creates a custom client assembled from user-provided endpoints. URLs will be assembled according to the endpoints array, separated each element by slashes. for example, array ["https://www.example.com", "v2", "test", ...] will form the address "https://www.example.com/v2/test/.../". NOTE: You can decide whether to skip the SSL certificate check with the insecure parameter.

func RetryContextWithWaitForState

func RetryContextWithWaitForState(param *RetryContextWithWaitForStateParam) (interface{}, error)

RetryContextWithWaitForState The RetryFunc will be called first if the error of the return is nil, the retry will be ended and the res of the return will be returned if the retry of the return is true, the RetryFunc will be retried, and the WaitFunc will be called if it is not nil if the retry of the return is false, the retry will be ended and the error of the retry func will be returned

func SchemaAutoPay

func SchemaAutoPay(conflicts []string) *schema.Schema

func SchemaAutoRenew

func SchemaAutoRenew(conflicts []string) *schema.Schema

func SchemaAutoRenewUpdatable

func SchemaAutoRenewUpdatable(conflicts []string) *schema.Schema

func SchemaChargingMode

func SchemaChargingMode(conflicts []string) *schema.Schema

func SchemaPeriod

func SchemaPeriod(conflicts []string) *schema.Schema

func SchemaPeriodUnit

func SchemaPeriodUnit(conflicts []string) *schema.Schema

func TagsComputedSchema

func TagsComputedSchema() *schema.Schema

TagsComputedSchema returns the schema to use for tags as an attribute

func TagsForceNewSchema

func TagsForceNewSchema() *schema.Schema

TagsForceNewSchema returns the schema to use for tags with ForceNew

func TagsSchema

func TagsSchema() *schema.Schema

TagsSchema returns the schema to use for tags.

func UnsubscribePrePaidResource

func UnsubscribePrePaidResource(d *schema.ResourceData, config *config.Config, resourceIDs []string) error

UnsubscribePrePaidResource impl the action of unsubscribe resource

func UpdateAutoRenew

func UpdateAutoRenew(c *golangsdk.ServiceClient, enabled, resourceId string) error

func UpdateEcsInstanceKeyPair

func UpdateEcsInstanceKeyPair(ctx context.Context, ecsClient, kmsClient *golangsdk.ServiceClient, opts *KeypairAuthOpts) error

func ValidatePrePaidChargeInfo

func ValidatePrePaidChargeInfo(d *schema.ResourceData) error

func WaitOrderComplete

func WaitOrderComplete(ctx context.Context, client *golangsdk.ServiceClient, orderId string,
	timeout time.Duration) error

func WaitOrderResourceComplete

func WaitOrderResourceComplete(ctx context.Context, client *golangsdk.ServiceClient, orderId string,
	timeout time.Duration) (string, error)

WaitOrderResourceComplete is the method to wait for the resource to be generated. Notes: Note that this method needs to be used in conjunction with method "WaitOrderComplete", because the ID of some resources may not be generated when the order is not completed.

Types

type ErrorResp

type ErrorResp struct {
	ErrorCode string `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`
}

ErrorResp is the response when API failed

func ParseErrorMsg

func ParseErrorMsg(body []byte) (ErrorResp, error)

type KeypairAuthOpts

type KeypairAuthOpts struct {
	// the ECS instance ID
	InstanceID string
	// the keypair name in used
	InUsedKeyPair string
	// the replaced keypair name
	NewKeyPair string
	// the private key of the keypair name in used, it's used to replace or unbind the keypair
	InUsedPrivateKey string
	// the root password of the ECS instance, it's used to bind a new keypair
	Password string
	// whether to disable SSH login on the VM
	DisablePassword bool
	// the timeout to wait for the task
	Timeout time.Duration
}

type RetryContextWithWaitForStateParam

type RetryContextWithWaitForStateParam struct {
	Ctx context.Context
	// The func that need to be retried
	RetryFunc RetryFunc
	// The wait func when the retry which returned by the retry func is true
	WaitFunc resource.StateRefreshFunc
	// The target of the wait func
	WaitTarget []string
	// The pending of the wait func
	WaitPending []string
	// The timeout of the retry func and wait func
	Timeout time.Duration
	// The delay timeout of the retry func and wait func
	DelayTimeout time.Duration
	// The poll interval of the retry func and wait func
	PollInterval time.Duration
}

type RetryFunc

type RetryFunc func() (res interface{}, retry bool, err error)

RetryFunc is the function retried until it succeeds. The first return parameter is the result of the retry func. The second return parameter indicates whether a retry is required. The last return parameter is the error of the func.

Jump to

Keyboard shortcuts

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