Exemple #1
0
func (this *SolusVM) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	vmIdentificationInt, _ := strconv.Atoi(vm.Identification)
	apiInfo, err := this.Api.VmInfo(vmIdentificationInt)
	if err != nil {
		return nil, err
	}

	bwUsed, _ := strconv.ParseInt(strings.Split(apiInfo.Bandwidth, ",")[1], 10, 64)
	info := lobster.VmInfo{
		Ip:            apiInfo.Ip,
		PrivateIp:     apiInfo.InternalIps,
		Status:        strings.Title(apiInfo.State),
		BandwidthUsed: bwUsed,
		LoginDetails:  "username: root; password: "******"password", "unknown"),
	}

	if this.VirtType == "openvz" {
		info.Actions = append(info.Actions, &lobster.VmActionDescriptor{
			Action:      "tuntap",
			Name:        "TUN/TAP",
			Description: "Enable or disable TUN/TAP.",
			Options: map[string]string{
				"enable":  "On",
				"disable": "Off",
			},
		})
	}

	return &info, nil
}
Exemple #2
0
func (cs *CloudStack) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	details, err := cs.client.GetVirtualMachine(vm.Identification)
	if err != nil {
		return nil, err
	}

	status := details.State
	if status == "Running" {
		status = "Online"
	} else if status == "Stopped" {
		status = "Offline"
	}

	info := lobster.VmInfo{
		Status:       status,
		LoginDetails: "password: "******"password", "unknown"),
	}

	for _, nic := range details.Nics {
		if ipaddr.IsPrivate(nic.Addr) {
			info.PrivateIp = nic.Addr
		} else {
			info.Ip = nic.Addr
		}
	}

	return &info, nil
}
Exemple #3
0
func (this *Linode) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	linodeID, _ := strconv.Atoi(vm.Identification)
	linode, err := this.client.GetLinode(linodeID)
	if err != nil {
		return nil, err
	}

	info := lobster.VmInfo{
		Hostname:     vm.Name,
		LoginDetails: "password: "******"password", "unknown"),
	}

	if linode.StatusString == "Running" {
		info.Status = "Online"
	} else if linode.StatusString == "Powered Off" {
		info.Status = "Offline"
	} else {
		info.Status = linode.StatusString
	}

	ips, err := this.client.ListIP(linodeID)
	if err == nil {
		for _, ip := range ips {
			if ip.IsPublic == 1 {
				info.Ip = ip.Address
			} else {
				info.PrivateIp = ip.Address
			}
		}
	}

	return &info, nil
}
Exemple #4
0
func (cloug *Cloug) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	instance, err := cloug.service.GetInstance(vm.Identification)
	if err != nil {
		return nil, err
	}

	username := vm.Metadata("username", instance.Username)
	if username == "" {
		username = "******"
	}
	password := vm.Metadata("password", instance.Password)
	if password == "" {
		password = "******"
	}

	return &lobster.VmInfo{
		Ip:                   instance.IP,
		PrivateIp:            instance.PrivateIP,
		Status:               strings.Title(string(instance.Status)),
		Hostname:             instance.Name,
		BandwidthUsed:        instance.BandwidthUsed,
		LoginDetails:         fmt.Sprintf("username: %s; password: %s", username, password),
		Details:              instance.Details,
		OverrideCapabilities: true,
		CanVnc:               cloug.vncService != nil,
		CanReimage:           cloug.reimageService != nil,
		CanResize:            cloug.resizeService != nil,
		CanSnapshot:          cloug.imageService != nil,
		CanAddresses:         cloug.addressService != nil,
	}, nil
}
Exemple #5
0
func (this *Linode) VmSnapshot(vm *lobster.VirtualMachine) (string, error) {
	linodeID, _ := strconv.Atoi(vm.Identification)
	diskID, err := strconv.Atoi(vm.Metadata("diskid", ""))
	if err != nil {
		return "", errors.New("failed to retrieve disk ID from metadata")
	}
	imageID, _, err := this.client.ImagizeDisk(linodeID, diskID, "lobster image")
	if err != nil {
		return "", err
	} else {
		return fmt.Sprintf("image:%d", imageID), nil
	}
}
Exemple #6
0
func (this *DigitalOcean) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	vmIdentification, _ := strconv.Atoi(vm.Identification)
	droplet, _, err := this.client.Droplets.Get(vmIdentification)
	if err != nil {
		return nil, err
	}

	info := lobster.VmInfo{
		Hostname:     droplet.Name,
		LoginDetails: "username: root; password: "******"password", "unknown"),
	}
	for _, addr4 := range droplet.Networks.V4 {
		if addr4.Type == "public" {
			info.Ip = addr4.IPAddress
		} else if addr4.Type == "private" {
			info.PrivateIp = addr4.IPAddress
		}
	}
	if droplet.Status == "active" {
		info.Status = "Online"
	} else if droplet.Status == "off" {
		info.Status = "Offline"
	} else {
		info.Status = strings.Title(droplet.Status)
	}

	// list droplet actions
	var pendingActions []string
	actionList, _, err := this.client.Droplets.Actions(droplet.ID, &godo.ListOptions{PerPage: 25})
	if err == nil {
		for _, action := range actionList {
			if action.Status == "in-progress" {
				pendingActions = append(pendingActions, action.Type)
			}
		}
		if len(pendingActions) >= 1 {
			info.Details = make(map[string]string)
			if len(pendingActions) == 1 {
				info.Details["Pending action"] = pendingActions[0]
			} else {
				info.Details["Pending actions"] = strings.Join(pendingActions, ", ")
			}
		}
	}

	return &info, nil
}
Exemple #7
0
func (this *Fake) VmAddresses(vm *lobster.VirtualMachine) ([]*lobster.IpAddress, error) {
	var addresses []*lobster.IpAddress
	for _, addrString := range strings.Split(vm.Metadata("addresses", ""), ",") {
		addrString = strings.TrimSpace(addrString)
		if addrString != "" {
			parts := strings.Split(addrString, ":")
			ipAddr := &lobster.IpAddress{
				Ip:        parts[0],
				PrivateIp: "255.255.255.255",
				CanRdns:   true,
			}
			if len(parts) > 1 {
				ipAddr.Hostname = parts[1]
			}
			addresses = append(addresses, ipAddr)
		}
	}
	return addresses, nil
}
Exemple #8
0
func (cloug *Cloug) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	instance, err := cloug.service.GetInstance(vm.Identification)
	if err != nil {
		return nil, err
	}

	username := vm.Metadata("username", instance.Username)
	if username == "" {
		username = "******"
	}
	password := vm.Metadata("password", instance.Password)
	if password == "" {
		password = "******"
	}

	info := &lobster.VmInfo{
		Ip:                   instance.IP,
		PrivateIp:            instance.PrivateIP,
		Status:               strings.Title(string(instance.Status)),
		Hostname:             instance.Name,
		BandwidthUsed:        instance.BandwidthUsed,
		LoginDetails:         fmt.Sprintf("username: %s; password: %s", username, password),
		Details:              instance.Details,
		OverrideCapabilities: true,
		CanVnc:               cloug.vncService != nil,
		CanReimage:           cloug.reimageService != nil,
		CanResize:            cloug.resizeService != nil,
		CanSnapshot:          cloug.imageService != nil,
		CanAddresses:         cloug.addressService != nil,
	}

	for _, action := range instance.Actions {
		info.Actions = append(info.Actions, &lobster.VmActionDescriptor{
			Action:      hex.EncodeToString([]byte(action.Label)),
			Name:        action.Label,
			Description: action.Description,
			Options:     action.Options,
		})
	}

	return info, nil
}
Exemple #9
0
func (this *OpenStack) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	server, err := servers.Get(this.ComputeClient, vm.Identification).Extract()
	if err != nil {
		return nil, err
	}

	status := server.Status
	if status == "ACTIVE" {
		status = "Online"
	} else if status == "SHUTOFF" {
		status = "Offline"
	}

	info := lobster.VmInfo{
		Status:       status,
		Hostname:     server.Name,
		LoginDetails: "password: "******"password", "unknown"),
	}

	servers.ListAddresses(this.ComputeClient, vm.Identification).EachPage(func(page pagination.Page) (bool, error) {
		addresses, err := servers.ExtractAddresses(page)
		if err != nil {
			return false, err
		}

		for _, networkAddresses := range addresses {
			for _, addr := range networkAddresses {
				if ipaddr.IsPrivate(addr.Address) {
					info.PrivateIp = addr.Address
				} else {
					info.Ip = addr.Address
				}
			}
		}
		return true, nil
	})

	return &info, nil
}