Exemple #1
0
func (inst *openstackInstance) DNSName() (string, error) {
	addresses, err := inst.Addresses()
	if err != nil {
		return "", err
	}
	addr := instance.SelectPublicAddress(addresses)
	if addr == "" {
		return "", instance.ErrNoDNSName
	}
	return addr, nil
}
Exemple #2
0
func (c *NatCommand) ExecSsh(m *state.Machine, script string) error {
	host := instance.SelectPublicAddress(m.Addresses())
	if host == "" {
		return fmt.Errorf("could not resolve machine's public address")
	}
	log.Println("Configuring NAT routing on machine ", m.Id())
	var options ssh.Options
	cmd := ssh.Command("ubuntu@"+host, []string{"sh -c 'NATCMD=$(mktemp); cat >${NATCMD}; sudo sh -x ${NATCMD}'"}, &options)
	cmd.Stdin = strings.NewReader(script)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd.Run()
}
Exemple #3
0
// PublicAddress returns the public address of the unit and whether it is valid.
func (u *Unit) PublicAddress() (string, bool) {
	publicAddress := u.doc.PublicAddress
	id := u.doc.MachineId
	if id != "" {
		m, err := u.st.Machine(id)
		if err != nil {
			unitLogger.Errorf("unit %v misses machine id %v", u, id)
			return "", false
		}
		addresses := m.Addresses()
		if len(addresses) > 0 {
			publicAddress = instance.SelectPublicAddress(addresses)
		}
	}
	return publicAddress, publicAddress != ""
}
Exemple #4
0
func (u *UnitContainment) NewForward() (*Forward, error) {
	fwd := &Forward{
		UnitContainment:       *u,
		InternalPorts:         u.Unit.OpenedPorts(),
		ExternalGatewayDevice: "eth0",
		PortMap:               make(map[int]int),
	}

	var err error
	fwd.InternalHostAddr, fwd.InternalGatewayAddr, err = MatchNetworks(u.HostMachine, u.GatewayMachine)
	if err != nil {
		return nil, err
	}

	if fwd.ExternalGatewayAddr = instance.SelectPublicAddress(u.GatewayMachine.Addresses()); fwd.ExternalGatewayAddr == "" {
		return nil, fmt.Errorf("failed to get internal address: %q", u.GatewayMachine.Id())
	}
	return fwd, fwd.validate()
}
Exemple #5
0
func InstanceAddress(addresses map[string][]nova.IPAddress) string {
	return instance.SelectPublicAddress(convertNovaAddresses(addresses))
}