Пример #1
0
func ec2Child(info *childInfo) error {
	instanceName := info.childConfig.Ec2.Instance
	ec2HostConfig, ok := info.hostConfig.Ec2[instanceName]
	if !ok {
		return fmt.Errorf("EC2 instance %q not defined in configuration file", instanceName)
	}

	svc, err := setupEc2(ec2HostConfig, info.childConfig)
	if err != nil {
		return fmt.Errorf("while setting up ec2 access: %s", err)
	}

	// look up the instance matching this description
	instance, err := findInstance(ec2HostConfig, svc)
	if err != nil {
		return fmt.Errorf("while searching for ec2 instance: %s", err)
	}
	log.Printf("Found instance id %s (type %s)", *instance.InstanceId, *instance.InstanceType)

	err = startInstance(ec2HostConfig, instance, svc)
	if err != nil {
		return fmt.Errorf("while starting instance: %s", err)
	}

	// re-fetch the instance to get an IP address
	if instance.PublicIpAddress == nil {
		instance, err = findInstance(ec2HostConfig, svc)
		if err != nil {
			return fmt.Errorf("while searcihng for running instance: %s", err)
		}
	}

	return ssh.Run(*instance.PublicIpAddress, &ec2HostConfig.SshCommonConfig, info.path)
}
Пример #2
0
func sshChild(info *childInfo) error {
	host := info.childConfig.Ssh.Host
	sshHostConfig, ok := info.hostConfig.Ssh[host]
	if !ok {
		return fmt.Errorf("no ssh configuration for host %q", host)
	}

	return ssh.Run(sshHostConfig.Hostname, &sshHostConfig.SshCommonConfig, info.path)
}