本文整理匯總了Golang中launchpad/net/gomaasapi.MAASObject類的典型用法代碼示例。如果您正苦於以下問題:Golang MAASObject類的具體用法?Golang MAASObject怎麽用?Golang MAASObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MAASObject類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: maasGetSingleNode
/*
This is a *low level* function that access a MAAS Server and returns a MAASObject
referring to a single MAAS managed node.
The function takes a pointer to an already active MAASObject as well as a system_id and returns a MAASObject array
and an error code.
*/
func maasGetSingleNode(maas *gomaasapi.MAASObject, system_id string) (gomaasapi.MAASObject, error) {
log.Printf("[DEBUG] [maasGetSingleNode] Getting a node (%s) from MAAS\n", system_id)
nodeObject, err := maas.GetSubObject("nodes").GetSubObject(system_id).Get()
if err != nil {
log.Printf("[ERROR] [maasGetSingleNode] Unable to get node (%s) from MAAS\n", system_id)
return gomaasapi.MAASObject{}, err
}
return nodeObject, nil
}
示例2: maasReleaseNode
func maasReleaseNode(maas *gomaasapi.MAASObject, system_id string) error {
log.Printf("[DEBUG] [maasReleaseNode] Releasing node: %s", system_id)
_, err := maas.GetSubObject("nodes").GetSubObject(system_id).CallPost("release", url.Values{})
if err != nil {
log.Printf("[DEBUG] [maasReleaseNode] Unable to release node (%s)", system_id)
return err
}
return nil
}
示例3: maasAllocateNodes
/*
This is a *low level* function that attempts to acquire a MAAS managed node for future deployment.
*/
func maasAllocateNodes(maas *gomaasapi.MAASObject, params url.Values) (gomaasapi.MAASObject, error) {
log.Printf("[DEBUG] [maasAllocateNodes] Allocating one or more nodes with following params: %+v", params)
nodeObject, err := maas.GetSubObject("nodes").CallPost("acquire", params)
if err != nil {
log.Printf("[ERROR] [maasAllocateNodes] Unable to acquire a node ... bailing")
return gomaasapi.MAASObject{}, err
}
return nodeObject.GetMAASObject()
}
示例4: startNode
// startNode installs and boots a node.
func (environ *maasEnviron) startNode(node gomaasapi.MAASObject, series string, userdata []byte) error {
userDataParam := base64.StdEncoding.EncodeToString(userdata)
params := url.Values{
"distro_series": {series},
"user_data": {userDataParam},
}
// Initialize err to a non-nil value as a sentinel for the following
// loop.
err := fmt.Errorf("(no error)")
for a := shortAttempt.Start(); a.Next() && err != nil; {
_, err = node.CallPost("start", params)
}
return err
}
示例5: maasListAllNodes
/*
This is a *low level* function that access a MAAS Server and returns an array of MAASObject
The function takes a pointer to an already active MAASObject and returns a JSONObject array
and an error code.
*/
func maasListAllNodes(maas *gomaasapi.MAASObject) ([]gomaasapi.JSONObject, error) {
nodeListing := maas.GetSubObject("nodes")
log.Printf("[DEBUG] [maasListAllNodes] Fetching list of nodes...\n")
listNodeObjects, err := nodeListing.CallGet("list", url.Values{})
if err != nil {
log.Printf("[ERROR] [maasListAllNodes] Unable to get list of nodes ...\n")
return nil, err
}
listNodes, err := listNodeObjects.GetArray()
if err != nil {
log.Printf("[ERROR] [maasListAllNodes] Unable to get the node list array ...\n")
return nil, err
}
return listNodes, err
}
示例6: maasObjectId
func maasObjectId(maasObject *gomaasapi.MAASObject) instance.Id {
// Use the node's 'resource_uri' value.
return instance.Id(maasObject.URI().String())
}
示例7: 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)
}
//.........這裏部分代碼省略.........