當前位置: 首頁>>代碼示例>>Golang>>正文


Golang VmInfo.Status方法代碼示例

本文整理匯總了Golang中github.com/LunaNode/lobster.VmInfo.Status方法的典型用法代碼示例。如果您正苦於以下問題:Golang VmInfo.Status方法的具體用法?Golang VmInfo.Status怎麽用?Golang VmInfo.Status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/LunaNode/lobster.VmInfo的用法示例。


在下文中一共展示了VmInfo.Status方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: VmInfo

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: " + vm.Metadata("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
}
開發者ID:carriercomm,項目名稱:lobster,代碼行數:33,代碼來源:linode.go

示例2: VmInfo

func (this *Vultr) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	server, err := this.client.GetServer(vm.Identification)
	if err != nil {
		return nil, err
	}

	info := lobster.VmInfo{
		Ip:            server.MainIP,
		PrivateIp:     server.InternalIP,
		Hostname:      server.Name,
		BandwidthUsed: int64(server.CurrentBandwidth * 1024 * 1024 * 1024),
		LoginDetails:  "password: " + server.DefaultPassword,
	}

	if server.Status == "pending" {
		info.Status = "Installing"
	} else if server.Status == "active" {
		if server.PowerStatus == "stopped" {
			info.Status = "Offline"
		} else if server.PowerStatus == "running" {
			info.Status = "Online"
		} else {
			info.Status = server.PowerStatus
		}
	} else {
		info.Status = fmt.Sprintf("%s (%s)", strings.Title(server.Status), strings.Title(server.PowerStatus))
	}

	return &info, nil
}
開發者ID:nhocconan,項目名稱:lobster,代碼行數:30,代碼來源:vmvultr.go

示例3: VmInfo

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: " + vm.Metadata("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
}
開發者ID:yashodhank,項目名稱:lobster,代碼行數:47,代碼來源:digitalocean.go


注:本文中的github.com/LunaNode/lobster.VmInfo.Status方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。