本文整理汇总了Golang中github.com/cloudawan/cloudone_utility/restclient.RequestGet函数的典型用法代码示例。如果您正苦于以下问题:Golang RequestGet函数的具体用法?Golang RequestGet怎么用?Golang RequestGet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RequestGet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetAllReplicationControllerName
func GetAllReplicationControllerName(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (returnedNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedNameSlice = nil
returnedError = err.(error)
}
}()
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/"
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
jsonMap, err := restclient.RequestGet(url, headerMap, true)
if err != nil {
log.Error(err)
return nil, err
} else {
nameSlice := make([]string, 0)
for _, item := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
name, ok := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if ok {
nameSlice = append(nameSlice, name)
}
}
return nameSlice, nil
}
}
开发者ID:cloudawan,项目名称:cloudone_analysis,代码行数:30,代码来源:replication_controller.go
示例2: Get
// @Title get
// @Description get container log in the pod
// @Param namespace path string true "The name of namespace"
// @Param pod path string true "The name of pod"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /podlog/:namespace/:pod [get]
func (c *PodLogController) Get() {
namespace := c.GetString(":namespace")
pod := c.GetString(":pod")
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/podlogs/" + namespace + "/" + pod
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
result, err := restclient.RequestGet(url, tokenHeaderMap, true)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
jsonMap, _ := result.(map[string]interface{})
if err != nil {
// Error
c.Data["json"] = make(map[string]interface{})
c.Data["json"].(map[string]interface{})["error"] = err.Error()
c.Ctx.Output.Status = 404
c.ServeJSON()
return
} else {
c.Data["json"] = make(map[string]interface{})
c.Data["json"].(map[string]interface{})["logJsonMap"] = jsonMap
c.ServeJSON()
}
}
开发者ID:cloudawan,项目名称:cloudone_gui,代码行数:41,代码来源:pod_log.go
示例3: GetAllNamespaceName
func GetAllNamespaceName(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllNamespaceName Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedNameSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/", headerMap, true)
if err != nil {
log.Error("Fail to get all namespace name with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
}
jsonMap, _ := result.(map[string]interface{})
nameSlice := make([]string, 0)
for _, data := range jsonMap["items"].([]interface{}) {
name, ok := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if ok {
statusJsonMap, _ := data.(map[string]interface{})["status"].(map[string]interface{})
phase, _ := statusJsonMap["phase"].(string)
if phase == "Active" {
nameSlice = append(nameSlice, name)
}
}
}
return nameSlice, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:35,代码来源:namespace.go
示例4: GetAllEvent
func GetAllEvent(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedEventSlice []map[string]interface{}, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllEvent Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedEventSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
jsonMap, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/events/", headerMap, true)
if err != nil {
log.Error("Fail to get all event with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
}
eventSlice := make([]map[string]interface{}, 0)
for _, data := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
value, ok := data.(map[string]interface{})
if ok {
eventSlice = append(eventSlice, value)
}
}
return eventSlice, nil
}
开发者ID:cloudawan,项目名称:cloudone_analysis,代码行数:29,代码来源:event.go
示例5: UpdateReplicationControllerSize
func UpdateReplicationControllerSize(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, size int) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("UpdateReplicationControllerSize Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
result, err := restclient.RequestGet(url, headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Get replication controller information failure where size: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", size, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return err
} else {
jsonMap["spec"].(map[string]interface{})["replicas"] = float64(size)
_, err := restclient.RequestPut(url, jsonMap, headerMap, true)
if err != nil {
return err
} else {
return nil
}
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:29,代码来源:replication_controller.go
示例6: GetAllImageTag
func (privateRegistry *PrivateRegistry) GetAllImageTag(repositoryName string) ([]string, error) {
result, err := restclient.RequestGet(privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/tags/list", nil, false)
if err != nil {
log.Error("Fail to get all image tags with repository %s and private registry: %v, error: %s", repositoryName, privateRegistry, err)
return nil, err
}
jsonMap, _ := result.(map[string]interface{})
tagJsonSlice, _ := jsonMap["tags"].([]interface{})
tagSlice := make([]string, 0)
for _, tagJsonInterface := range tagJsonSlice {
if tag, ok := tagJsonInterface.(string); ok {
request, err := http.NewRequest("GET", privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/manifests/"+tag, nil)
if err != nil {
log.Error(err)
return nil, err
}
// For registry version 2.3 and later
request.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json")
response, err := restclient.GetInsecureHTTPSClient().Do(request)
if err != nil {
log.Error(err)
return nil, err
}
digest := response.Header.Get("Docker-Content-Digest")
if len(digest) > 0 {
tagSlice = append(tagSlice, tag)
}
}
}
return tagSlice, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:35,代码来源:private.go
示例7: ResizeReplicationController
func ResizeReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, delta int, maximumSize int, minimumSize int) (resized bool, size int, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("ResizeReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
resized = false
size = -1
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
result, err := restclient.RequestGet(url, headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Get replication controller information failure where delta: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", delta, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return false, -1, err
} else {
replicas, _ := jsonparse.ConvertToInt64(jsonMap["spec"].(map[string]interface{})["replicas"])
currentSize := int(replicas)
newSize := currentSize + delta
if newSize < minimumSize {
newSize = minimumSize
}
if newSize > maximumSize {
newSize = maximumSize
}
if newSize == currentSize {
return false, currentSize, nil
}
jsonMap["spec"].(map[string]interface{})["replicas"] = float64(newSize)
result, err := restclient.RequestPut(url, jsonMap, headerMap, true)
resultJsonMap, _ := result.(map[string]interface{})
if err != nil {
return false, currentSize, err
} else {
replicas, _ := jsonparse.ConvertToInt64(resultJsonMap["spec"].(map[string]interface{})["replicas"])
return true, int(replicas), nil
}
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:46,代码来源:replication_controller.go
示例8: getContainerMonitorData
func getContainerMonitorData(urlSlice []string) ([]map[string]interface{}, []error) {
dataMapSlice := make([]map[string]interface{}, 0)
errorSlice := make([]error, 0)
for _, url := range urlSlice {
result, err := restclient.RequestGet(url, nil, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
dataMapSlice = append(dataMapSlice, nil)
errorSlice = append(errorSlice, err)
} else {
dataMapSlice = append(dataMapSlice, jsonMap)
errorSlice = append(errorSlice, nil)
}
}
return dataMapSlice, errorSlice
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:17,代码来源:pod.go
示例9: GetPodLog
func GetPodLog(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, podName string) (returnedLog map[string]interface{}, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetPodLog Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedLog = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/"+podName, headerMap, false)
if err != nil {
log.Error("Fail to get pod information with namespace %s pod %s endpoint: %s, token: %s, error: %s", namespace, podName, kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
}
containerNameSlice := make([]string, 0)
jsonMap, _ := result.(map[string]interface{})
specJsonMap, _ := jsonMap["spec"].(map[string]interface{})
containerSlice, _ := specJsonMap["containers"].([]interface{})
for _, container := range containerSlice {
containerJsonMap, _ := container.(map[string]interface{})
containerName, ok := containerJsonMap["name"].(string)
if ok {
containerNameSlice = append(containerNameSlice, containerName)
}
}
logJsonMap := make(map[string]interface{})
for _, containerName := range containerNameSlice {
byteSlice, err := restclient.RequestGetByteSliceResult(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/"+podName+"/log?container="+containerName, headerMap)
if err != nil {
log.Error("Fail to get log with namespace %s pod %s container %s endpoint: %s, token: %s, error: %s", namespace, podName, containerName, kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
} else {
logJsonMap[containerName] = string(byteSlice)
}
}
return logJsonMap, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:45,代码来源:pod_log.go
示例10: GetAllRepository
func (privateRegistry *PrivateRegistry) GetAllRepository() ([]string, error) {
result, err := restclient.RequestGet(privateRegistry.getPrivateRegistryEndpoint()+"/v2/_catalog", nil, false)
if err != nil {
log.Error("Fail to get all repository with private registry: %v, error: %s", privateRegistry, err)
return nil, err
}
jsonMap, _ := result.(map[string]interface{})
repositoryJsonSlice, _ := jsonMap["repositories"].([]interface{})
repositorySlice := make([]string, 0)
for _, repositoryJsonInterface := range repositoryJsonSlice {
if repository, ok := repositoryJsonInterface.(string); ok {
repositorySlice = append(repositorySlice, repository)
}
}
return repositorySlice, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:18,代码来源:private.go
示例11: ExistReplicationController
func ExistReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedExist bool, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("ExistReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedExist = false
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
_, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/"+replicationControllerName, headerMap, true)
if err != nil {
log.Error("Fail to detect replication controller existence with endpoint: %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return false, err
} else {
return true, nil
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:21,代码来源:replication_controller.go
示例12: GetReplicationControllerNameFromSelector
func GetReplicationControllerNameFromSelector(kubeApiServerEndPoint, kubeApiServerToken, namespace string, targetSelectorName string) (returnedReplicationControllerNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetReplicationControllerNameFromSelector Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedReplicationControllerNameSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/", headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Fail to get all replication controller with endpoint: %s, token: %s, namespace: %s, selector name: %s",
kubeApiServerEndPoint, kubeApiServerToken, namespace, targetSelectorName)
return nil, err
}
nameSlice := make([]string, 0)
for _, item := range jsonMap["items"].([]interface{}) {
selector, ok := item.(map[string]interface{})["spec"].(map[string]interface{})["selector"].(map[string]interface{})
if ok {
selectorName, ok := selector["name"].(string)
if ok {
if targetSelectorName == selectorName {
name, ok := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if ok {
nameSlice = append(nameSlice, name)
}
}
}
}
}
return nameSlice, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:39,代码来源:replication_controller.go
示例13: GetAllPodBelongToReplicationController
func GetAllPodBelongToReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedPodSlice []Pod, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllPodBelongToReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedPodSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Fail to get all pod inofrmation with endpoint %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return nil, err
}
return GetAllPodBelongToReplicationControllerFromData(replicationControllerName, jsonMap)
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:22,代码来源:pod.go
示例14: GetAllPodNameBelongToReplicationController
func GetAllPodNameBelongToReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllPodNameBelongToReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedNameSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
if err != nil {
log.Error("Fail to get replication controller inofrmation with endpoint %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return nil, err
}
jsonMap, _ := result.(map[string]interface{})
generateName := replicationControllerName + "-"
podNameSlice := make([]string, 0)
for _, data := range jsonMap["items"].([]interface{}) {
generateNameField, _ := data.(map[string]interface{})["metadata"].(map[string]interface{})["generateName"].(string)
nameField, nameFieldOk := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if generateName == generateNameField {
if nameFieldOk {
podNameSlice = append(podNameSlice, nameField)
}
} else if replicationControllerName == nameField {
if nameFieldOk {
podNameSlice = append(podNameSlice, nameField)
}
}
}
return podNameSlice, nil
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:38,代码来源:pod.go
示例15: SendSMSNexmo
func (smsNexmo *SMSNexmo) SendSMSNexmo(smsNexmoURL string, smsNexmoAPIKey string, smsNexmoAPISecret string,
sender string, receiverNumberSlice []string, text string) error {
hasError := false
buffer := bytes.Buffer{}
for _, receiverNumber := range receiverNumberSlice {
convertedURL, err := url.Parse(smsNexmoURL)
if err != nil {
log.Error("Parse url %s error %s", smsNexmoURL, err)
return err
}
parameters := url.Values{}
parameters.Add("api_key", smsNexmoAPIKey)
parameters.Add("api_secret", smsNexmoAPISecret)
parameters.Add("from", sender)
parameters.Add("to", receiverNumber)
parameters.Add("text", text)
convertedURL.RawQuery = parameters.Encode()
result, err := restclient.RequestGet(convertedURL.String(), nil, true)
bodyJsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Request url %s error bodyJsonMap %s error %s", convertedURL.String(), bodyJsonMap, err)
hasError = true
buffer.WriteString(err.Error())
} else {
log.Info("SMS send to %s, bodyJsonMap %s", convertedURL.String(), bodyJsonMap)
}
}
if hasError {
return errors.New(buffer.String())
} else {
return nil
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:37,代码来源:sms.go
示例16: UpdateReplicationControllerWithJson
func UpdateReplicationControllerWithJson(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, bodyJsonMap map[string]interface{}) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("UpdateReplicationControllerWithJson Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName
result, err := restclient.RequestGet(url, headerMap, true)
if err != nil {
log.Error(err)
return err
}
jsonMap, _ := result.(map[string]interface{})
metadataJsonMap, _ := jsonMap["metadata"].(map[string]interface{})
resourceVersion, _ := metadataJsonMap["resourceVersion"].(string)
// Update requires the resoruce version
bodyJsonMap["metadata"].(map[string]interface{})["resourceVersion"] = resourceVersion
url = kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName
_, err = restclient.RequestPut(url, bodyJsonMap, headerMap, true)
if err != nil {
log.Error(err)
return err
} else {
return nil
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:37,代码来源:replication_controller.go
示例17: UpdateServiceWithJson
func UpdateServiceWithJson(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, serviceName string, bodyJsonMap map[string]interface{}) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("CreateServiceWithJson Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/services/" + serviceName
result, err := restclient.RequestGet(url, headerMap, true)
jsonMap, _ := result.(map[string]interface{})
metadataJsonMap, _ := jsonMap["metadata"].(map[string]interface{})
resourceVersion, _ := metadataJsonMap["resourceVersion"].(string)
specJsonMap, _ := jsonMap["spec"].(map[string]interface{})
clusterIP, _ := specJsonMap["clusterIP"].(string)
// Update requires the resoruce version and cluster ip
bodyJsonMap["metadata"].(map[string]interface{})["resourceVersion"] = resourceVersion
bodyJsonMap["spec"].(map[string]interface{})["clusterIP"] = clusterIP
url = kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/services/" + serviceName
_, err = restclient.RequestPut(url, bodyJsonMap, headerMap, true)
if err != nil {
log.Error(err)
return err
} else {
return nil
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:36,代码来源:service.go
示例18: Get
func (c *PodLogController) Get() {
c.TplName = "inventory/replicationcontroller/pod_log.html"
guimessage := guimessagedisplay.GetGUIMessage(c)
// Authorization for web page display
c.Data["layoutMenu"] = c.GetSession("layoutMenu")
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
namespace := c.GetString("namespace")
pod := c.GetString("pod")
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/pods/" + namespace + "/" + pod + "/logs"
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
result, err := restclient.RequestGet(url, tokenHeaderMap, true)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
jsonMap, _ := result.(map[string]interface{})
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
c.Data["logJsonMap"] = jsonMap
}
guimessage.OutputMessage(c.Data)
}
开发者ID:cloudawan,项目名称:cloudone_gui,代码行数:36,代码来源:pod_log.go
示例19: GetAllService
func GetAllService(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (returnedServiceSlice []Service, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllService Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedServiceSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/services/"
result, err := restclient.RequestGet(url, headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
return nil, err
} else {
serviceSlice := make([]Service, 0)
for _, item := range jsonMap["items"].([]interface{}) {
service := Service{}
service.Name, _ = item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
service.Namespace, _ = item.(map[string]interface{})["metadata"].(map[string]interface{})["namespace"].(string)
service.LabelMap, _ = item.(map[string]interface{})["metadata"].(map[string]interface{})["labels"].(map[string]interface{})
service.ClusterIP, _ = item.(map[string]interface{})["spec"].(map[string]interface{})["clusterIP"].(string)
service.Selector, _ = item.(map[string]interface{})["spec"].(map[string]interface{})["selector"].(map[string]interface{})
service.SessionAffinity, _ = item.(map[string]interface{})["spec"].(map[string]interface{})["sessionAffinity"].(string)
portSlice := item.(map[string]interface{})["spec"].(map[string]interface{})["ports"].([]interface{})
servicePortSlice := make([]ServicePort, 0)
for _, port := range portSlice {
servicePort := ServicePort{}
servicePort.Name, _ = port.(map[string]interface{})["name"].(string)
servicePort.Protocol, _ = port.(map[string]interface{})["protocol"].(string)
unknownTypePort := port.(map[string]interface{})["port"]
switch knowTypePort := unknownTypePort.(type) {
case json.Number:
portInt64, _ := knowTypePort.Int64()
servicePort.Port = int(portInt64)
case string:
servicePort.Port, _ = strconv.Atoi(knowTypePort)
case int64:
servicePort.Port = int(knowTypePort)
case float64:
servicePort.Port = int(knowTypePort)
}
unknownTypeTargetPort := port.(map[string]interface{})["targetPort"]
switch knowTypeTargetPort := unknownTypeTargetPort.(type) {
case json.Number:
servicePort.TargetPort = knowTypeTargetPort.String()
case string:
servicePort.TargetPort = knowTypeTargetPort
case int64:
servicePort.TargetPort = strconv.FormatInt(knowTypeTargetPort, 10)
case float64:
servicePort.TargetPort = strconv.FormatFloat(knowTypeTargetPort, 'f', -1, 64)
}
unknownTypeNodePort := port.(map[string]interface{})["nodePort"]
switch knowTypeNodePort := unknownTypeNodePort.(type) {
case json.Number:
nodePortInt64, _ := knowTypeNodePort.Int64()
servicePort.NodePort = int(nodePortInt64)
case string:
servicePort.NodePort, _ = strconv.Atoi(knowTypeNodePort)
case int64:
servicePort.NodePort = int(knowTypeNodePort)
case float64:
servicePort.NodePort = int(knowTypeNodePort)
default:
servicePort.NodePort = -1
}
servicePortSlice = append(servicePortSlice, servicePort)
}
service.PortSlice = servicePortSlice
serviceSlice = append(serviceSlice, service)
}
return serviceSlice, nil
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:79,代码来源:service.go
示例20: GetAllReplicationControllerAndRelatedPodSlice
func GetAllReplicationControllerAndRelatedPodSlice(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (
returnedReplicationControllerAndRelatedPodSlice []ReplicationControllerAndRelatedPod, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedReplicationControllerAndRelatedPodSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/", headerMap, true)
replicationControllerJsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Fail to get all replication controller inofrmation with endpoint %s, token: %s, namespace: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, err.Error())
return nil, err
} else {
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
podJsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Fail to get all pod information with endpoint %s, token: %s, namespace: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, err.Error())
return nil, err
} else {
replicationControllerAndRelatedPodSlice := make([]ReplicationControllerAndRelatedPod, 0)
itemSlice, _ := replicationControllerJsonMap["items"].([]interface{})
for _, item := range itemSlice {
name, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
namespace, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["namespace"].(string)
replicaAmount, _ := jsonparse.ConvertToInt64(item.(map[string]interface{})["spec"].(map[string]interface{})["replicas"])
aliveReplicaAmount, _ := jsonparse.ConvertToInt64(item.(map[string]interface{})["status"].(map[string]interface{})["replicas"])
selectorField, _ := item.(map[string]interface{})["spec"].(map[string]interface{})["selector"].(map[string]interface{})
labelField, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["labels"].(map[string]interface{})
selectorMap := make(map[string]string)
for key, value := range selectorField {
selectorMap[key], _ = value.(string)
}
labelMap := make(map[string]string)
for key, value := range labelField {
labelMap[key], _ = value.(string)
}
podSlice, _ := GetAllPodBelongToReplicationControllerFromData(name, podJsonMap)
replicationControllerAndRelatedPod := ReplicationControllerAndRelatedPod{
name,
namespace,
int(replicaAmount),
int(aliveReplicaAmount),
selectorMap,
labelMap,
podSlice,
}
replicationControllerAndRelatedPodSlice = append(replicationControllerAndRelatedPodSlice, replicationControllerAndRelatedPod)
}
return replicationControllerAndRelatedPodSlice, nil
}
}
}
开发者ID:cloudawan,项目名称:cloudone,代码行数:65,代码来源:replication_controller_and_related_pod.go
注:本文中的github.com/cloudawan/cloudone_utility/restclient.RequestGet函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论