Merge pull request #101 from bmelville/98

Adds support for "dm deployed-instances <type>:<version>"
pull/97/head
vaikas-google 9 years ago
commit 5396209510

@ -111,10 +111,7 @@ func main() {
fmt.Printf("Templates:\n")
for _, t := range templates {
fmt.Printf("%s:%s\n", t.Name, t.Version)
downloadURL, err := git.GetURL(t)
if err != nil {
log.Printf("Failed to get download URL for template %s:%s", t.Name, t.Version)
}
downloadURL := getDownloadUrl(t)
fmt.Printf("\tdownload URL: %s\n", downloadURL)
}
@ -160,8 +157,9 @@ func main() {
usage()
}
path := fmt.Sprintf("types/%s/instances", url.QueryEscape(args[1]))
action := fmt.Sprintf("list deployed instances of type %s", args[1])
tUrl := getTypeUrl(args[1])
path := fmt.Sprintf("types/%s/instances", url.QueryEscape(tUrl))
action := fmt.Sprintf("list deployed instances of type %s", tUrl)
callService(path, "GET", action, nil)
default:
usage()
@ -211,28 +209,38 @@ func describeType(args []string) {
usage()
}
var tUrl string
tUrl := getTypeUrl(args[1])
schemaUrl := tUrl + ".schema"
fmt.Println(callHttp(schemaUrl, "GET", "get schema for type ("+tUrl+")", nil))
}
if strings.HasPrefix(args[1], "http://") || strings.HasPrefix(args[1], "https://") {
func getTypeUrl(tName string) string {
if isHttp(tName) {
// User can pass raw URL to template.
tUrl = args[1]
} else {
// User can pass registry type.
t := getRegistryType(args[1])
if t == nil {
log.Fatalf("Invalid type name, must be in the form \"<type-name>:<version>\": %s", args[1])
}
return tName
}
git := getGitRegistry()
url, err := git.GetURL(*t)
if err != nil {
log.Fatalf("Failed to fetch type information for %s: %s", args[1], err)
}
tUrl = url
// User can pass registry type.
t := getRegistryType(tName)
if t == nil {
log.Fatalf("Invalid type name, must be in the form \"<type-name>:<version>\": %s", tName)
}
schemaUrl := tUrl + ".schema"
fmt.Println(callHttp(schemaUrl, "GET", "get schema for type ("+tUrl+")", nil))
return getDownloadUrl(*t)
}
func getDownloadUrl(t registry.Type) string {
git := getGitRegistry()
url, err := git.GetURL(t)
if err != nil {
log.Fatalf("Failed to fetch type information for \"%s:%s\": %s", t.Name, t.Version, err)
}
return url
}
func isHttp(t string) bool {
return strings.HasPrefix(t, "http://") || strings.HasPrefix(t, "https://")
}
func loadTemplate(args []string) *expander.Template {
@ -279,11 +287,7 @@ func getRegistryType(fullType string) *registry.Type {
}
func buildTemplateFromType(t registry.Type) *expander.Template {
git := getGitRegistry()
downloadURL, err := git.GetURL(t)
if err != nil {
log.Fatalf("Failed to get download URL for type %s:%s\n%s\n", t.Name, t.Version, err)
}
downloadURL := getDownloadUrl(t)
props := make(map[string]interface{})
if *properties != "" {

Loading…
Cancel
Save