This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git
The following commit(s) were added to refs/heads/master by this push:
new a02ed50 config: add inbuilt API precache
a02ed50 is described below
commit a02ed5006cb0daa235f979c426ee68cf919d790d
Author: Rohit Yadav <[email protected]>
AuthorDate: Sat Jun 23 21:29:33 2018 +0530
config: add inbuilt API precache
This adds API precache based on 4.11.1 which is used in environments
without any existing API cache.
Signed-off-by: Rohit Yadav <[email protected]>
---
cli/shell.go | 13 ++++++++++++-
cmk.go | 13 +------------
config/cache.go | 5 +++--
config/precache.go | 20 ++++++++++++++++++++
4 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/cli/shell.go b/cli/shell.go
index cdf46ac..884150c 100644
--- a/cli/shell.go
+++ b/cli/shell.go
@@ -27,12 +27,14 @@ import (
"github.com/mattn/go-shellwords"
"github.com/chzyer/readline"
+ "os"
)
var completer *autoCompleter
// ExecShell starts a shell
-func ExecShell(cfg *config.Config) {
+func ExecShell(sysArgs []string) {
+ cfg := config.NewConfig()
completer = &autoCompleter{
Config: cfg,
}
@@ -59,6 +61,15 @@ func ExecShell(cfg *config.Config) {
}
defer shell.Close()
+ if len(sysArgs) > 0 {
+ err := ExecCmd(cfg, sysArgs, nil)
+ if err != nil {
+ fmt.Println("🙈 Error:", err)
+ os.Exit(1)
+ }
+ os.Exit(0)
+ }
+
cfg.PrintHeader()
for {
diff --git a/cmk.go b/cmk.go
index b557f48..982c19a 100644
--- a/cmk.go
+++ b/cmk.go
@@ -18,23 +18,12 @@
package main
import (
- "fmt"
"os"
"cloudmonkey/cli"
- "cloudmonkey/config"
)
func main() {
args := os.Args[1:]
- cfg := config.NewConfig()
- if len(args) > 0 {
- err := cli.ExecCmd(cfg, args, nil)
- if err != nil {
- fmt.Println("🙈 Error:", err)
- os.Exit(1)
- }
- } else {
- cli.ExecShell(cfg)
- }
+ cli.ExecShell(args)
}
diff --git a/config/cache.go b/config/cache.go
index a40fdf5..88c2480 100644
--- a/config/cache.go
+++ b/config/cache.go
@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
+ "os"
"sort"
"strings"
"unicode"
@@ -81,8 +82,8 @@ func (c *Config) GetCache() map[string]*API {
func LoadCache(c *Config) {
cache, err := ioutil.ReadFile(c.CacheFile)
if err != nil {
- fmt.Println("Please run sync, failed to read the cache file: "
+ c.CacheFile)
- return
+ fmt.Fprintf(os.Stderr, "Loaded in-built API cache. Failed to
read API cache, please run 'sync'.\n")
+ cache = []byte(preCache)
}
var data map[string]interface{}
_ = json.Unmarshal(cache, &data)
diff --git a/config/precache.go b/config/precache.go
new file mode 100644
index 0000000..077a456
--- /dev/null
+++ b/config/precache.go
@@ -0,0 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+var preCache = `{"api":[{"description":"Creates VPC
offering","isasync":true,"name":"createVPCOffering","params":[{"description":"the
name of the vpc
offering","length":255,"name":"name","required":true,"type":"string"},{"description":"services
supported by the vpc
offering","length":255,"name":"supportedservices","required":true,"type":"list"},{"description":"provider
to service mapping. If not specified, the provider for the service will be
mapped to the default provider on the physica [...]