|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + log "github.com/Sirupsen/logrus" |
| 6 | + "io/ioutil" |
| 7 | + "os" |
| 8 | +) |
| 9 | + |
| 10 | +type ContainerResource struct { |
| 11 | + Name string `json:"Name"` |
| 12 | + RequestsMemory string `json:"RequestsMemory"` |
| 13 | + RequestsCPU float64 `json:"RequestsCPU"` |
| 14 | + LimitsMemory string `json:"LimitsMemory"` |
| 15 | + LimitsCPU float64 `json:"LimitsCPU"` |
| 16 | +} |
| 17 | + |
| 18 | +type Cluster struct { |
| 19 | + CCPImagePrefix string `json:"CCPImagePrefix"` |
| 20 | + CCPImageTag string `json:"CCPImageTag"` |
| 21 | + Port int `json:"Port"` |
| 22 | + User string `json:"User"` |
| 23 | + Database string `json:"Database"` |
| 24 | + PasswordAgeDays int `json:"PasswordAgeDays"` |
| 25 | + PasswordLength int `json:"PasswordLength"` |
| 26 | + Strategy int `json:"Strategy"` |
| 27 | + Replicas int `json:"Replicas"` |
| 28 | +} |
| 29 | + |
| 30 | +type Storage struct { |
| 31 | + Name string `json:"Name"` |
| 32 | + AccessMode string `json:"AccessMode"` |
| 33 | + Size string `json:"Size"` |
| 34 | + StorageType string `json:"StorageType"` |
| 35 | +} |
| 36 | +type Pgo struct { |
| 37 | + Audit bool `json:"Audit"` |
| 38 | + Metrics bool `json:"Metrics"` |
| 39 | + LSPVCTemplate string `json:"LSPVCTemplate"` |
| 40 | + LoadTemplate string `json:"LoadTemplate"` |
| 41 | + COImagePrefix string `json:"COImagePrefix"` |
| 42 | + COImageTag string `json:"COImageTag"` |
| 43 | +} |
| 44 | + |
| 45 | +type PgoConfig struct { |
| 46 | + ClusterDef Cluster |
| 47 | + PrimaryStorage string `json:"PrimaryStorage"` |
| 48 | + BackupStorage string `json:"BackupStorage"` |
| 49 | + ReplicaStorage string `json:"ReplicaStorage"` |
| 50 | + StorageDef []Storage `json:"Storage"` |
| 51 | + DefaultContainerResource string `json:"DefaultContainerResource"` |
| 52 | + ContainerResources []ContainerResource `json:"ContainerResources"` |
| 53 | + PgoDef Pgo `json:"Pgo"` |
| 54 | +} |
| 55 | + |
| 56 | +func main() { |
| 57 | + log.Info("hi") |
| 58 | + path := "./conf/apiserver/pgo.json" |
| 59 | + _, err := ioutil.ReadFile(path) |
| 60 | + if err != nil { |
| 61 | + log.Error("error loading template path=" + path + err.Error()) |
| 62 | + panic(err.Error()) |
| 63 | + } |
| 64 | + |
| 65 | + thisconfig := PgoConfig{} |
| 66 | + thisconfig.PrimaryStorage = "storage1" |
| 67 | + thisconfig.StorageDef = make([]Storage, 1) |
| 68 | + thisconfig.StorageDef[0].Name = "storage1" |
| 69 | + thisconfig.StorageDef[0].AccessMode = "ReadWriteMany" |
| 70 | + thisconfig.DefaultContainerResource = "res1" |
| 71 | + thisconfig.ContainerResources = make([]ContainerResource, 1) |
| 72 | + thisconfig.ContainerResources[0].Name = "res1" |
| 73 | + thisconfig.ClusterDef = Cluster{} |
| 74 | + thisconfig.ClusterDef.Port = 5432 |
| 75 | + thisconfig.PgoDef.Audit = false |
| 76 | + thisconfig.PgoDef.Metrics = false |
| 77 | + thisconfig.PgoDef.LSPVCTemplate = "this lspvc template" |
| 78 | + thisconfig.PgoDef.LoadTemplate = "loadtempaltepath" |
| 79 | + thisconfig.PgoDef.COImagePrefix = "crunchydata" |
| 80 | + thisconfig.PgoDef.COImageTag = "centos7-2.6" |
| 81 | + |
| 82 | + //json.Unmarshal(buf, &c) |
| 83 | + |
| 84 | + //log.Info("Pgo.LSPVCTemplate is [" + c.PgoDef.LSPVCTemplate + "]") |
| 85 | + |
| 86 | + //log.Infof("%v\n", c.ContainerResources) |
| 87 | + |
| 88 | + b, err := json.MarshalIndent(thisconfig, "", " ") |
| 89 | + if err != nil { |
| 90 | + log.Error(err) |
| 91 | + } else { |
| 92 | + os.Stdout.Write(b) |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments