From 0eb6cd5aa85d926568a0800854a0fbab0a76480a Mon Sep 17 00:00:00 2001 From: Brendan Melville Date: Wed, 18 Nov 2015 10:01:11 -0800 Subject: [PATCH 1/2] Deployment name can now be set when doing "dm deploy". The default is still either template file name or -. Override using the "name" flag. --- dm/dm.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dm/dm.go b/dm/dm.go index 35af4860b..fec9ed482 100644 --- a/dm/dm.go +++ b/dm/dm.go @@ -36,6 +36,7 @@ import ( ) var ( + deployment_name = flag.String("name", "", "Name of deployment, used for deploy and update commands (defaults to template name)") stdin = flag.Bool("stdin", false, "Reads a configuration from the standard input") properties = flag.String("properties", "", "Properties to use when deploying a template (e.g., --properties k1=v1,k2=v2)") template_registry = flag.String("registry", "kubernetes/deployment-manager/templates", "Github based template registry (owner/repo[/path])") @@ -250,6 +251,11 @@ func loadTemplate(args []string) *expander.Template { log.Fatalf("cannot create configuration from supplied arguments: %s\n", err) } + // Override name if set from flags. + if *deployment_name != "" { + template.Name = *deployment_name + } + return template } From 3bbd6e8a3ed21e262af9200cae91e8e1f487b586 Mon Sep 17 00:00:00 2001 From: Brendan Melville Date: Wed, 18 Nov 2015 10:17:32 -0800 Subject: [PATCH 2/2] Adds support for dm deployed-instances :. When you deploy with :, the type actually seen by DM is the template URL. While the template URL still shows up as the type when performing a "dm deployed-types", this at least lets you look for instances of a known type. Refactoring the type URL code in client a bit. Refactoring getTypeUrl. --- dm/dm.go | 60 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/dm/dm.go b/dm/dm.go index 35af4860b..c90b94536 100644 --- a/dm/dm.go +++ b/dm/dm.go @@ -110,10 +110,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) } @@ -159,8 +156,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() @@ -204,28 +202,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 \":\": %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 \":\": %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 { @@ -267,11 +275,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 != "" {