forked from rancher/shepherd
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5448651
commit 9779b21
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package aliyun | ||
|
||
import ( | ||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk" | ||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" | ||
ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" | ||
"github.com/rancher/shepherd/pkg/config" | ||
) | ||
|
||
// ECSClient is a struct that wraps the needed ALIYUNECSConfig object, and ecs.ECs which makes the actual calls to aliyun. | ||
type ECSClient struct { | ||
Client *ecs.Client | ||
ClientConfig *ALIYUNECSConfigs | ||
} | ||
|
||
// NewECSClient is a constructor that creates an *ECSClient which a wrapper for a "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" session and | ||
// the aliyun ecs config. | ||
func NewECSClient() (*ECSClient, error) { | ||
ecsConfig := sdk.NewConfig() | ||
aliyunecsClientConfig := new(ALIYUNECSConfigs) | ||
config.LoadConfig(ConfigurationFileKey, aliyunecsClientConfig) | ||
credential := credentials.NewAccessKeyCredential(aliyunecsClientConfig.ALIYUNECSAccessKeyID, aliyunecsClientConfig.ALIYUNECSSecretAccessKey) | ||
client, err := ecs.NewClientWithOptions(aliyunecsClientConfig.Region, ecsConfig, credential) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ECSClient{ | ||
Client: client, | ||
ClientConfig: aliyunecsClientConfig, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package aliyun | ||
|
||
// The json/yaml config key for the ALIYUNECSConfig | ||
const ConfigurationFileKey = "aliyunECSConfigs" | ||
|
||
// ALIYUNECSConfigs is the AWS authentication configuration for accessing and launching ec2 instances | ||
type ALIYUNECSConfigs struct { | ||
ALIYUNECSConfig []ALIYUNECSConfig `json:"aliyunECSConfig" yaml:"aliyunECSConfig"` | ||
ALIYUNECSAccessKeyID string `json:"aliyunAccessKeyID" yaml:"aliyunAccessKeyID"` | ||
ALIYUNECSSecretAccessKey string `json:"aliyunSecretAccessKey" yaml:"aliyunSecretAccessKey"` | ||
Region string `json:"region" yaml:"region"` | ||
} | ||
|
||
// ALIYUNECSConfig is the instance-specific configuration needed to launch ec2 instances in AWS | ||
type ALIYUNECSConfig struct { | ||
ImageID string `json:"imageId" yaml:"imageId"` | ||
SSHPassword string `json:"sshPassword" yaml:"sshPassword"` | ||
SSHKeyPairName string `json:"sshKeypair" yaml:"sshKeypair"` | ||
SSHPrivateKeyPath string `json:"sshPrivateKeyPath" yaml:"sshPrivateKeyPath"` | ||
InstanceType string `json:"instanceType" yaml:"instanceType"` | ||
SecurityGroupId string `json:"securityGroupId" yaml:"securityGroupId"` | ||
SecurityGroupName string `json:"securityGroup" yaml:"securityGroup"` | ||
VpcId string `json:"vpcId" yaml:"vpcId"` | ||
VSwitchId string `json:"vswitchId" yaml:"vswitchId"` | ||
Zone string `json:"zone" yaml:"zone"` | ||
PrivateIPOnly bool `json:"privateAddressOnly" yaml:"privateAddressOnly"` | ||
InternetMaxBandwidthOut string `json:"internetMaxBandwidth" yaml:"internetMaxBandwidth"` | ||
InternetChargeType string `json:"internetChargeType" yaml:"internetChargeType"` | ||
RouteCIDR string `json:"routeCidr" yaml:"routeCidr"` | ||
SLBID string `json:"slbId" yaml:"slbId"` | ||
DiskSize string `json:"diskSize" yaml:"diskSize"` | ||
DiskFS string `json:"diskFs" yaml:"diskFs"` | ||
DiskCategory string `json:"diskCategory" yaml:"diskCategory"` | ||
Description string `json:"description" yaml:"description"` | ||
APIEndpoint string `json:"apiEndpoint" yaml:"apiEndpoint"` | ||
SystemDiskCategory string `json:"systemDiskCategory" yaml:"systemDiskCategory"` | ||
SystemDiskSize string `json:"SystemDiskSize" yaml:"SystemDiskSize"` | ||
ResourceGroupId string `json:"resourceGroupId" yaml:"resourceGroupId"` | ||
InstanceChargeType string `json:"instanceChargeType" yaml:"instanceChargeType"` | ||
Period string `json:"period" yaml:"period"` | ||
PeriodUnit string `json:"periodUnit" yaml:"periodUnit"` | ||
SpotStrategy string `json:"spotStrategy" yaml:"spotStrategy"` | ||
SpotPriceLimit string `json:"spotPriceLimit" yaml:"spotPriceLimit"` | ||
SpotDuration string `json:"spotDuration" yaml:"spotDuration"` | ||
AliyunUser string `json:"aliyunUser" yaml:"aliyunUser"` | ||
DockerVersion string `json:"dockerVersion" yaml:"dockerVersion"` | ||
System string `json:"system" yaml:"system"` | ||
OpenPorts []string `json:"openPort" yaml:"openPort"` | ||
Roles []string `json:"roles" yaml:"roles"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters