Skip to content

tutengdihuang/cloud_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

简介

  • golang开发版本 go1.18.2
  • 本项目主要提供多云服务器sdk服务 目前支持阿里云,腾讯云,AWS
  • 支持的接口
    StartInstancesWithChan
    RunInstancesWithChan
    StopInstancesWithChan
    DescribeInstancesStatusWithChan
    AllocateEipAddressWithChan
    AssociateEipAddressWithChan
    DescribeEipAddressesWithChan
    UnassociateEipAddressWithChan
    ReleaseEipAddressWithChan
    ChangeInstancePasswordWithChan
    DescribeInstancesAllWithChan
    DescribeInstancesByIDsWithChan
    ReplaceSystemDiskWithChan
    DeleteInstancesWithChan
    DescribeImagesWithChan
    CreateImageWithChan
    CopyImageWithChan
    DeleteImageWithChan

使用

  • 可以参考case_set文件夹中的测试用例

以阿里云为例子

  • 初始化变量对象serverAliyun
	cfg := &zero_model.CloudServerConfig{}
	cfg.Region = "cn-hangzhou"
	cfg.AccessKey = Aliyun_accessKeyID
	cfg.SecretKey = Aliyun_accessKeySecret
	cfg.Driver = zero_model.Aliyun
	var err error
	serverAliyun, err = cloud_server.New(cfg)
	if err != nil {
		panic(err)
	}
  • 调用并创建服务器实例
	request := new(zero_model.RunInstanceWithChanRequest)
	request.RegionId = "cn-hangzhou" //placement
	request.InstanceName = "cn-beijing-allen-test-3"

	request.ImageId = "aliyun_3_x64_20G_alibase_20221102.vhd"
	request.Password = "Allen123!"
	request.SecurityGroupId = "sg-bp14o9edhrbueomfc1f2"
	request.VSwitchId = "vsw-bp1tw0ukcxmwt2vvp2kcl"
	request.InstanceType = "ecs.s6-c1m1.small"
	request.InstanceChargeType = "PostPaid"
	//request.InternetChargeType = "PayByBandwidth"
	//request.InternetMaxBandwidthOut = 1
	request.Amount = 1
	request.SystemDiskSize = "40"
	//request.SystemDiskCategory = "cloud_essd"

	if request == nil {
		panic("request is nil")
	}
	if serverAliyun == nil {
		panic("serverAliyun is nil")
	}
	respChan, errChan := serverAliyun.RunInstancesWithChan(request)
	select {
	case resp := <-respChan:
		fmt.Printf("resp: %+v", resp)
	case err := <-errChan:
		fmt.Printf("err: %+v", err)
		if err == nil && cap(respChan) > 0 {
			resp := <-respChan
			fmt.Printf("\n resp RequestId: %+v \n", resp.RequestId)
		}
	}

参考

tencent

ali

AWS

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages