common

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: MPL-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPasswordStr, DefaultPasswordNum and DefaultPasswordSpe are used to general default value of root password of UHost instance
	DefaultPasswordNum = "012346789"
	DefaultPasswordStr = "abcdefghijklmnopqrstuvwxyz"
	DefaultPasswordSpe = "-_"
)
View Source
const (
	InstanceStateRunning = "Running"
	InstanceStateStopped = "Stopped"

	ImageStateAvailable   = "Available"
	ImageStateUnavailable = "Unavailable"

	BootDiskStateNormal = "Normal"
	OsTypeWindows       = "Windows"
	SecurityGroupNonWeb = "recommend non web"
	IpTypePrivate       = "Private"
)
View Source
const (
	DefaultCreateImageTimeout = 3600
)

Variables

View Source
var BootDiskTypeMap = NewStringConverter(map[string]string{
	"cloud_ssd":    "CLOUD_SSD",
	"local_normal": "LOCAL_NORMAL",
	"local_ssd":    "LOCAL_SSD",
	"cloud_rssd":   "CLOUD_RSSD",
})
View Source
var ChargeModeMap = NewStringConverter(map[string]string{
	"post_accurate_bandwidth": "PostAccurateBandwidth",
	"traffic":                 "Traffic",
	"bandwidth":               "Bandwidth",
})
View Source
var ImageNamePattern = regexp.MustCompile(`^[A-Za-z0-9\p{Han}-_\[\]:,.]{1,63}$`)

Functions

func CheckIntIn

func CheckIntIn(val int, available []int) error

func CheckStringIn

func CheckStringIn(val string, available []string) error

func Halt

func Halt(state multistep.StateBag, err error, prefix string) multistep.StepAction

func IsExpectedStateError

func IsExpectedStateError(err error) bool

func IsNotCompleteError

func IsNotCompleteError(err error) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsStringIn

func IsStringIn(val string, available []string) bool

func NewExpectedStateError

func NewExpectedStateError(product, id string) error

func NewNotCompletedError

func NewNotCompletedError(product string) error

func NewNotFoundError

func NewNotFoundError(product, id string) error

func NewStringConverter

func NewStringConverter(input map[string]string) stringConverter

func SSHHost

func SSHHost(usePrivateIp bool) func(multistep.StateBag) (string, error)

SSHHost returns a function that can be given to the SSH communicator

Types

type AccessConfig

type AccessConfig struct {
	// This is the UCloud public key. It must be provided unless `profile` is set,
	// but it can also be sourced from the `UCLOUD_PUBLIC_KEY` environment variable.
	PublicKey string `mapstructure:"public_key" required:"true"`
	// This is the UCloud private key. It must be provided unless `profile` is set,
	// but it can also be sourced from the `UCLOUD_PRIVATE_KEY` environment variable.
	PrivateKey string `mapstructure:"private_key" required:"true"`
	// This is the UCloud region. It must be provided, but it can also be sourced from
	// the `UCLOUD_REGION` environment variables.
	Region string `mapstructure:"region" required:"true"`
	// This is the UCloud project id. It must be provided, but it can also be sourced
	// from the `UCLOUD_PROJECT_ID` environment variables.
	ProjectId string `mapstructure:"project_id" required:"true"`
	// This is the base url. (Default: `https://api.ucloud.cn`).
	BaseUrl string `mapstructure:"base_url" required:"false"`
	// This is the UCloud profile name as set in the shared credentials file, it can
	// also be sourced from the `UCLOUD_PROFILE` environment variables.
	Profile string `mapstructure:"profile" required:"false"`
	// This is the path to the shared credentials file, it can also be sourced from
	// the `UCLOUD_SHARED_CREDENTIAL_FILE` environment variables. If this is not set
	// and a profile is specified, `~/.ucloud/credential.json` will be used.
	SharedCredentialsFile string `mapstructure:"shared_credentials_file" required:"false"`
	// contains filtered or unexported fields
}

func (*AccessConfig) Client

func (c *AccessConfig) Client() (*UCloudClient, error)

func (*AccessConfig) Config

func (c *AccessConfig) Config() error

func (*AccessConfig) Prepare

func (c *AccessConfig) Prepare(ctx *interpolate.Context) []error

func (*AccessConfig) ValidateProjectId

func (c *AccessConfig) ValidateProjectId(projectId string) error

func (*AccessConfig) ValidateRegion

func (c *AccessConfig) ValidateRegion(region string) error

func (*AccessConfig) ValidateZone

func (c *AccessConfig) ValidateZone(region, zone string) error

type Artifact

type Artifact struct {
	UCloudImages *ImageInfoSet

	BuilderIdValue string

	Client *UCloudClient

	// StateData should store data such as GeneratedData
	// to be shared with post-processors
	StateData map[string]interface{}
}

func (*Artifact) BuilderId

func (a *Artifact) BuilderId() string

func (*Artifact) Destroy

func (a *Artifact) Destroy() error

func (*Artifact) Files

func (*Artifact) Files() []string

func (*Artifact) Id

func (a *Artifact) Id() string

func (*Artifact) State

func (a *Artifact) State(name string) interface{}

func (*Artifact) String

func (a *Artifact) String() string

type ExpectedStateError

type ExpectedStateError struct {
	// contains filtered or unexported fields
}

func (*ExpectedStateError) Error

func (e *ExpectedStateError) Error() string

type FlatImageDestination

type FlatImageDestination struct {
	ProjectId   *string `mapstructure:"project_id" required:"false" cty:"project_id" hcl:"project_id"`
	Region      *string `mapstructure:"region" required:"false" cty:"region" hcl:"region"`
	Name        *string `mapstructure:"name" required:"false" cty:"name" hcl:"name"`
	Description *string `mapstructure:"description" required:"false" cty:"description" hcl:"description"`
}

FlatImageDestination is an auto-generated flat version of ImageDestination. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.

func (*FlatImageDestination) HCL2Spec

func (*FlatImageDestination) HCL2Spec() map[string]hcldec.Spec

HCL2Spec returns the hcl spec of a ImageDestination. This spec is used by HCL to read the fields of ImageDestination. The decoded values from this spec will then be applied to a FlatImageDestination.

type ImageConfig

type ImageConfig struct {
	// The name of the user-defined image, which contains 1-63 characters and only
	// support Chinese, English, numbers, '-\_,.:[]'.
	ImageName string `mapstructure:"image_name" required:"true"`
	// The description of the image.
	ImageDescription string `mapstructure:"image_description" required:"false"`
	// The array of mappings regarding the copied images to the destination regions and projects.
	//
	//  - `project_id` (string) - The destination project id, where copying image in.
	//
	//  - `region` (string) - The destination region, where copying image in.
	//
	//  - `name` (string) - The copied image name. If not defined, builder will use `image_name` as default name.
	//
	//  - `description` (string) - The copied image description.
	//
	// “`json
	// {
	//   "image_copy_to_mappings": [
	//     {
	//       "project_id": "{{user `ucloud_project_id`}}",
	//       "region": "cn-sh2",
	//       "description": "test",
	//       "name": "packer-test-basic-sh"
	//     }
	//   ]
	// }
	// “`
	ImageDestinations []ImageDestination `mapstructure:"image_copy_to_mappings" required:"false"`
	// Timeout of creating image or copying image. The default timeout is 3600 seconds if this option
	// is not set or is set to 0.
	WaitImageReadyTimeout int `mapstructure:"wait_image_ready_timeout" required:"false"`
}

func (*ImageConfig) Prepare

func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error

type ImageDestination

type ImageDestination struct {
	// The destination project id, where copying image in.
	ProjectId string `mapstructure:"project_id" required:"false"`
	// The destination region, where copying image in.
	Region string `mapstructure:"region" required:"false"`
	// The copied image name. If not defined, builder will use `image_name` as default name.
	Name string `mapstructure:"name" required:"false"`
	// The copied image description.
	Description string `mapstructure:"description" required:"false"`
}

func (*ImageDestination) FlatMapstructure

func (*ImageDestination) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }

FlatMapstructure returns a new FlatImageDestination. FlatImageDestination is an auto-generated flat version of ImageDestination. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.

type ImageInfo

type ImageInfo struct {
	ImageId   string
	ProjectId string
	Region    string
}

func (*ImageInfo) Id

func (i *ImageInfo) Id() string

type ImageInfoSet

type ImageInfoSet struct {
	// contains filtered or unexported fields
}

func NewImageInfoSet

func NewImageInfoSet(vL []ImageInfo) *ImageInfoSet

func (*ImageInfoSet) Get

func (i *ImageInfoSet) Get(projectId, region string) *ImageInfo

func (*ImageInfoSet) GetAll

func (i *ImageInfoSet) GetAll() []ImageInfo

func (*ImageInfoSet) Remove

func (i *ImageInfoSet) Remove(id string)

func (*ImageInfoSet) Set

func (i *ImageInfoSet) Set(img ImageInfo)

type InstanceType

type InstanceType struct {
	CPU           int
	Memory        int
	HostType      string
	HostScaleType string
}

func ParseInstanceType

func ParseInstanceType(s string) (*InstanceType, error)

func (*InstanceType) Iscustomized

func (i *InstanceType) Iscustomized() bool

func (*InstanceType) String

func (i *InstanceType) String() string

type NotCompletedError

type NotCompletedError struct {
	// contains filtered or unexported fields
}

func (*NotCompletedError) Error

func (e *NotCompletedError) Error() string

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type RunConfig

type RunConfig struct {
	// This is the UCloud availability zone where UHost instance is located. such as: `cn-bj2-02`.
	// You may refer to [list of availability_zone](https://docs.ucloud.cn/api/summary/regionlist)
	Zone string `mapstructure:"availability_zone" required:"true"`
	// This is the ID of base image which you want to create your customized images with.
	SourceImageId string `mapstructure:"source_image_id" required:"true"`
	// The type of UHost instance.
	// You may refer to [list of instance type](https://docs.ucloud.cn/compute/terraform/specification/instance)
	InstanceType string `mapstructure:"instance_type" required:"true"`
	// The name of instance, which contains 1-63 characters and only support Chinese,
	// English, numbers, '-', '\_', '.'.
	InstanceName string `mapstructure:"instance_name" required:"false"`
	// The type of boot disk associated to UHost instance.
	// Possible values are: `cloud_ssd` and `cloud_rssd` for cloud boot disk, `local_normal` and `local_ssd`
	// for local boot disk. (Default: `cloud_ssd`). The `cloud_ssd` and `local_ssd` are not fully supported
	// by all regions as boot disk type, please proceed to UCloud console for more details.
	//
	//~> **Note:** It takes around 10 mins for boot disk initialization when `boot_disk_type` is `local_normal` or `local_ssd`.
	BootDiskType string `mapstructure:"boot_disk_type" required:"false"`
	// The ID of VPC linked to the UHost instance. If not defined `vpc_id`, the instance will use the default VPC in the current region.
	VPCId string `mapstructure:"vpc_id" required:"false"`
	// The ID of subnet under the VPC. If `vpc_id` is defined, the `subnet_id` is mandatory required.
	// If `vpc_id` and `subnet_id` are not defined, the instance will use the default subnet in the current region.
	SubnetId string `mapstructure:"subnet_id" required:"false"`
	// The ID of the fire wall associated to UHost instance. If `security_group_id` is not defined,
	// the instance will use the non-recommended web fire wall, and open port include 22, 3389 by default.
	// It is supported by ICMP fire wall protocols.
	// You may refer to [security group_id](https://docs.ucloud.cn/network/firewall/firewall).
	SecurityGroupId string `mapstructure:"security_group_id" required:"false"`
	// Maximum bandwidth to the elastic public network, measured in Mbps (Mega bit per second). (Default: `10`).
	EipBandwidth int `mapstructure:"eip_bandwidth" required:"false"`
	// Elastic IP charge mode. Possible values are: `traffic` as pay by traffic, `bandwidth` as pay by bandwidth,
	// `post_accurate_bandwidth` as post pay mode. (Default: `traffic`).
	// Note currently default `traffic` eip charge mode not not fully support by all `availability_zone`
	// in the `region`, please proceed to [UCloud console](https://console.ucloud.cn/unet/eip/create) for more details.
	// You may refer to [eip introduction](https://docs.ucloud.cn/unet/eip/introduction).
	EipChargeMode string `mapstructure:"eip_charge_mode" required:"false"`
	// User data to apply when launching the instance.
	// Note that you need to be careful about escaping characters due to the templates
	// being JSON. It is often more convenient to use user_data_file, instead.
	// Packer will not automatically wait for a user script to finish before
	// shutting down the instance this must be handled in a provisioner.
	// You may refer to [user_data_document](https://docs.ucloud.cn/uhost/guide/metadata/userdata)
	UserData string `mapstructure:"user_data" required:"false"`
	// Path to a file that will be used for the user data when launching the instance.
	UserDataFile string `mapstructure:"user_data_file" required:"false"`
	// Specifies a minimum CPU platform for the the VM instance. (Default: `Intel/Auto`).
	// You may refer to [min_cpu_platform](https://docs.ucloud.cn/uhost/introduction/uhost/type_new)
	//    - The Intel CPU platform:
	//        - `Intel/Auto` as the Intel CPU platform version will be selected randomly by system;
	//        - `Intel/IvyBridge` as Intel V2, the version of Intel CPU platform selected by system will be `Intel/IvyBridge` and above;
	//        - `Intel/Haswell` as Intel V3,  the version of Intel CPU platform selected by system will be `Intel/Haswell` and above;
	//        - `Intel/Broadwell` as Intel V4, the version of Intel CPU platform selected by system will be `Intel/Broadwell` and above;
	//        - `Intel/Skylake` as Intel V5, the version of Intel CPU platform selected by system will be `Intel/Skylake` and above;
	//        - `Intel/Cascadelake` as Intel V6, the version of Intel CPU platform selected by system will be `Intel/Cascadelake`;
	//    - The AMD CPU platform:
	//        - `Amd/Auto` as the Amd CPU platform version will be selected randomly by system;
	//        - `Amd/Epyc2` as the version of Amd CPU platform selected by system will be `Amd/Epyc2` and above;
	MinCpuPlatform string `mapstructure:"min_cpu_platform" required:"false"`
	// Communicator settings
	Comm communicator.Config `mapstructure:",squash"`
	// If this value is true, packer will connect to the created UHost instance via a private ip
	// instead of allocating an EIP (elastic public ip).(Default: `false`).
	UseSSHPrivateIp bool `mapstructure:"use_ssh_private_ip"`
}

func (*RunConfig) Prepare

func (c *RunConfig) Prepare(ctx *interpolate.Context) []error

type UCloudClient

type UCloudClient struct {
	UHostConn    *uhost.UHostClient
	UNetConn     *unet.UNetClient
	VPCConn      *vpc.VPCClient
	UAccountConn *uaccount.UAccountClient
	UFileConn    *ufile.UFileClient
}

func (*UCloudClient) DescribeFirewallById

func (c *UCloudClient) DescribeFirewallById(sgId string) (*unet.FirewallDataSet, error)

func (*UCloudClient) DescribeImageById

func (c *UCloudClient) DescribeImageById(imageId string) (*uhost.UHostImageSet, error)

func (*UCloudClient) DescribeImageByInfo

func (c *UCloudClient) DescribeImageByInfo(projectId, regionId, imageId string) (*uhost.UHostImageSet, error)

func (*UCloudClient) DescribeSubnetById

func (c *UCloudClient) DescribeSubnetById(subnetId string) (*vpc.VPCSubnetInfoSet, error)

func (*UCloudClient) DescribeUHostById

func (c *UCloudClient) DescribeUHostById(uhostId string) (*uhost.UHostInstanceSet, error)

func (*UCloudClient) DescribeVPCById

func (c *UCloudClient) DescribeVPCById(vpcId string) (*vpc.VPCInfo, error)

Jump to

Keyboard shortcuts

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