func main() { flag.Parse() if flag.Arg(0) == "" { errorf("no command") os.Exit(2) } auth, err := aws.EnvAuth() if err != nil { fatalf("envauth: %v", err) } region, ok := aws.Regions[*regionName] if !ok { fatalf("no such region") } signer := aws.SignV4Factory(region.Name, "ec2") conn := ec2.New(auth, region, signer) if flag.Arg(0) == "help" { for _, c := range cmds { c.printUsage() } return } for _, c := range cmds { if flag.Arg(0) == c.name { c.run(conn, flag.Args()[1:]) return } } errorf("unknown command %q", flag.Arg(0)) os.Exit(2) }
// Get ... func Get(machine *Machine, auth aws.Auth) error { ec2Ref := ec2.New(auth, aws.Regions[machine.Instance.Region], aws.SignV4Factory(machine.Instance.Region, "ec2")) // Verify if cloud-config file exists if machine.Instance.CloudConfig != "" { _, err := os.Stat(machine.Instance.CloudConfig) if err != nil { return err } } // get list of volumes to format volumesToFormat := make([]volume.Volume, 0) for key := range machine.Volumes { volumeConfig := &machine.Volumes[key] format := false if volumeConfig.ID == "" && volumeConfig.SnapshotID == "" { format = true } volumeConfig.AvailableZone = machine.Instance.AvailableZone _, err := volume.Get(ec2Ref, volumeConfig) if err != nil { return err } if format == true { volumesToFormat = append(volumesToFormat, *volumeConfig) } } // Create a machine to format theses volumes if len(volumesToFormat) > 0 { err := FormatVolumes(ec2Ref, *machine, volumesToFormat) if err != nil { return err } } _, err := instance.Get(ec2Ref, &machine.Instance) if err != nil { return err } err = AttachVolumes(ec2Ref, machine.Instance.ID, machine.Volumes) if err != nil { return err } err = instance.Reboot(ec2Ref, machine.Instance) if err != nil { return err } logger.Printf("The instance Id <%s> with IP Address <%s> is running with %d volume(s)!\n", machine.Instance.ID, machine.Instance.PrivateIPAddress, len(machine.Volumes)) return nil }
func awsClients(cloud environs.CloudSpec) (*ec2.EC2, *s3.S3, error) { if err := validateCloudSpec(cloud); err != nil { return nil, nil, errors.Annotate(err, "validating cloud spec") } credentialAttrs := cloud.Credential.Attributes() accessKey := credentialAttrs["access-key"] secretKey := credentialAttrs["secret-key"] auth := aws.Auth{ AccessKey: accessKey, SecretKey: secretKey, } // TODO(axw) define region in terms of EC2 and S3 endpoints. region := aws.Regions[cloud.Region] signer := aws.SignV4Factory(region.Name, "ec2") return ec2.New(auth, region, signer), s3.New(auth, region), nil }
func awsClient(cloud environs.CloudSpec) (*ec2.EC2, error) { if err := validateCloudSpec(cloud); err != nil { return nil, errors.Annotate(err, "validating cloud spec") } credentialAttrs := cloud.Credential.Attributes() accessKey := credentialAttrs["access-key"] secretKey := credentialAttrs["secret-key"] auth := aws.Auth{ AccessKey: accessKey, SecretKey: secretKey, } region := aws.Region{ Name: cloud.Region, EC2Endpoint: cloud.Endpoint, } signer := aws.SignV4Factory(cloud.Region, "ec2") return ec2.New(auth, region, signer), nil }