Exemple #1
0
func (hp *smartOS) ConnectVRes(uuid string) (connection.Client, error) {
	sshClient, err := connection.NewSSHClient(hp.addr, hp.user)
	if err != nil {
		return nil, err
	}
	return connection.NewWrappedClient(sshClient, "zlogin "+uuid), nil
}
Exemple #2
0
func (hp *gboxClient) ConnectVRes(name string) (connection.Client, error) {
	addr, err := gbox.ReadProperty(name, "/VirtualBox/GuestInfo/Net/1/V4/IP")
	if err != nil {
		return nil, errors.Wrap(err, "failed to get IP of vbox")
	}

	return connection.NewSSHClient(addr, "ubuntu")
}
Exemple #3
0
func NewSmartOSHypervisor(addr string) (Client, error) {
	var err error
	hp := new(smartOS)
	hp.addr = addr
	hp.user = "******"
	hp.client, err = connection.NewSSHClient(hp.addr, hp.user)
	return hp, err
}
Exemple #4
0
func (res *smResource) initializeClient() (err error) {
	var ok bool
	switch _, ok = res.Attributes["Hypervisor"]; {
	case ok:
		res.isVirtual = true
	case res.Blueprint != "":
		return errors.Errorf("hypervisor attribute required for blueprint to be supported!")
	default:
		res.address, ok = res.Attributes["Address"]
		if !ok {
			for _, cand := range []string{res.Name, res.ID} {
				ips, err := net.LookupIP(cand)
				if err == nil && len(ips) > 0 {
					res.address = ips[0].String()
					break
				}
			}
		}
		if res.address == "" {
			return fmt.Errorf("Host address attribute not specified!")
		}
	}

	res.username, ok = res.Attributes["Username"]
	if !ok {
		res.username = "******"
	}

	switch {
	case res.isVirtual:
		res.hypervisor, err = hypervisor.New(res.Attributes)
		if err != nil {
			return err
		}

		res.uuid, err = res.hypervisor.UUID(res.ID)
		if err == nil && res.uuid != "" {
			res.client, err = res.hypervisor.ConnectVRes(res.uuid)
		}
		return err
	default:
		res.client, err = connection.NewSSHClient(res.address, res.username)
		return err
	}
}