// extractFilenames returns the filenames from a "list" operation on the // MAAS API, sorted by name. func (stor *maasStorage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) { list, err := listResult.GetArray() if err != nil { return nil, err } result := make([]string, len(list)) for index, entry := range list { file, err := entry.GetMap() if err != nil { return nil, err } filename, err := file["filename"].GetString() if err != nil { return nil, err } result[index] = filename } sort.Strings(result) return result, nil }
// extractFilenames returns the filenames from a "list" operation on the // MAAS API, sorted by name. func (stor *maasStorage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) { privatePrefix := stor.prefixWithPrivateNamespace("") list, err := listResult.GetArray() if err != nil { return nil, err } result := make([]string, len(list)) for index, entry := range list { file, err := entry.GetMap() if err != nil { return nil, err } filename, err := file["filename"].GetString() if err != nil { return nil, err } // When listing files we need to return them without our special prefix. result[index] = strings.TrimPrefix(filename, privatePrefix) } sort.Strings(result) return result, nil }
// acquireNode allocates a node from the MAAS. func (environ *maasEnviron) acquireNode(cons constraints.Value, possibleTools tools.List) (gomaasapi.MAASObject, *state.Tools, error) { constraintsParams := convertConstraints(cons) var result gomaasapi.JSONObject var err error for a := shortAttempt.Start(); a.Next(); { client := environ.getMAASClient().GetSubObject("nodes/") result, err = client.CallPost("acquire", constraintsParams) if err == nil { break } } if err != nil { return gomaasapi.MAASObject{}, nil, err } node, err := result.GetMAASObject() if err != nil { msg := fmt.Errorf("unexpected result from 'acquire' on MAAS API: %v", err) return gomaasapi.MAASObject{}, nil, msg } tools := possibleTools[0] logger.Warningf("picked arbitrary tools %q", tools) return node, tools, nil }