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


Golang MAASObject.URL方法代碼示例

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


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

示例1: toNodeInfo

/*
Convenience function to convert a MAASObject to a NodeInfo instance
The function takes a fully initialized MAASObject and returns a NodeInfo instance
with an error
*/
func toNodeInfo(nodeObject *gomaasapi.MAASObject) (*NodeInfo, error) {
	log.Println("[DEBUG] [toNodeInfo] Attempting to convert node information from MAASObject to NodeInfo")

	nodeMap := nodeObject.GetMap()

	system_id, err := nodeMap["system_id"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get node (%s)\n", system_id)
		return nil, err
	}

	hostname, err := nodeMap["hostname"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the node (%s) hostname\n", system_id)
		return nil, err
	}

	url := nodeObject.URL().String()
	if len(url) == 0 {
		return nil, errors.New("[ERROR] [toNodeInfo] Empty URL for node")
	}

	power_state, err := nodeMap["power_state"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the power_state for node: %s\n", system_id)
		return nil, err
	}

	cpu_count_float, err := nodeMap["cpu_count"].GetFloat64()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the cpu_count for node: %s\n", system_id)
		log.Printf("[ERROR] [toNodeInfo] Error: %s\n", err)
		log.Printf("[ERROR] [toNodeInfo] cpu_count_float: %v\n", cpu_count_float)
		log.Println("[ERROR] [toNodeInfo] Defaulting cpu_count to 0")
		cpu_count_float = 0
	}
	cpu_count := uint16(cpu_count_float)

	architecture, err := nodeMap["architecture"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the node (%s) architecture\n", system_id)
		return nil, err
	}

	distro_series, err := nodeMap["distro_series"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the distro_series for node: %s\n", system_id)
		return nil, err
	}

	memory_float, err := nodeMap["memory"].GetFloat64()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the memory for node: %s\n", system_id)
		log.Printf("[ERROR] [toNodeInfo] Error: %s\n", err)
		log.Printf("[ERROR] [toNodeInfo] memory_float: %v\n", memory_float)
		log.Printf("[ERROR] [toNodeInfo] Defaulting memory to 0")
		memory_float = 0
	}
	memory := uint64(memory_float)

	osystem, err := nodeMap["osystem"].GetString()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the OS for node: %s\n", system_id)
		return nil, err
	}

	status_float, err := nodeMap["status"].GetFloat64()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the status for node: %s\n", system_id)
		return nil, err
	}
	status := uint16(status_float)

	substatus_float, err := nodeMap["substatus"].GetFloat64()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the node (%s) substatus\n", system_id)
		return nil, err
	}
	substatus := uint16(substatus_float)

	tag_names, err := nodeMap["tag_names"].GetArray()
	if err != nil {
		log.Printf("[ERROR] [toNodeInfo] Unable to get the tags for node: %s\n", system_id)
		return nil, err
	}

	tag_array := make([]string, 0, 1)
	for _, tag_object := range tag_names {
		tag_name, err := tag_object.GetString()
		if err != nil {
			log.Printf("[ERROR] [toNodeInfo] Unable to parse tag information (%v) for node (%s)", tag_object, system_id)
			return nil, err
		}
		tag_array = append(tag_array, tag_name)
	}
//.........這裏部分代碼省略.........
開發者ID:negronjl,項目名稱:terraform-provider-maas,代碼行數:101,代碼來源:maas_client.go


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