Commit 39e0d0b1 authored by vaikas-google's avatar vaikas-google

Use the new types structure

parent ded401b3
......@@ -35,7 +35,7 @@ var (
action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update | listtypes | listtypeinstances | types")
name = flag.String("name", "", "Name of template or deployment")
service = flag.String("service", "http://localhost:8080", "URL for deployment manager")
type_registry = flag.String("type_registry", "kubernetes/deployment-manager/examples/guestbook", "Type registry [owner/repo/root], defaults to kubernetes/deployment-manager/")
type_registry = flag.String("type_registry", "kubernetes/deployment-manager", "Type registry [owner/repo], defaults to kubernetes/deployment-manager/")
binary = flag.String("binary", "../expandybird/expansion/expansion.py",
"Path to template expansion binary")
)
......@@ -50,19 +50,21 @@ func main() {
flag.Parse()
name := getNameArgument()
switch *action {
case "repolist":
git := registry.NewGithubRegistry("kubernetes", "deployment-manager", "examples/guestbook")
case "types":
s := strings.Split(*type_registry, "/")
git := registry.NewGithubRegistry(s[0], s[1])
types, err := git.List()
if err != nil {
log.Fatalf("Cannot list %v err")
}
log.Printf("Types:")
for _, t := range types {
log.Printf("Got type: %s:%s", t.Name, t.Version)
log.Printf("%s:%s", t.Name, t.Version)
downloadURL, err := git.GetURL(t)
if err != nil {
log.Printf("Failed to get download URL for %s:%s", t.Name, t.Version)
}
log.Printf("DOWNLOAD URL: %s", downloadURL)
log.Printf("\tdownload URL: %s", downloadURL)
}
case "expand":
......
......@@ -23,21 +23,18 @@ import (
type GithubRegistry struct {
owner string
repository string
root string
client *github.Client
}
func NewGithubRegistry(owner string, repository string, root string) *GithubRegistry {
func NewGithubRegistry(owner string, repository string) *GithubRegistry {
return &GithubRegistry{
owner: owner,
repository: repository,
root: root,
client: github.NewClient(nil),
}
}
func (g *GithubRegistry) List() ([]Type, error) {
log.Printf("Calling ListRefs")
// First list all the types at the top level.
types, err := g.getDirs(TypesDir)
if err != nil {
......@@ -46,7 +43,6 @@ func (g *GithubRegistry) List() ([]Type, error) {
}
var retTypes []Type
for _, t := range types {
log.Printf("Got TYPE: %s, fetching : %s", t, TypesDir+"/"+t)
// Then we need to fetch the versions (directories for this type)
versions, err := g.getDirs(TypesDir + "/" + t)
if err != nil {
......@@ -54,7 +50,6 @@ func (g *GithubRegistry) List() ([]Type, error) {
return nil, err
}
for _, v := range versions {
log.Printf("Got VERSION: %s", v)
retTypes = append(retTypes, Type{Name: t, Version: v})
}
}
......@@ -71,7 +66,7 @@ func (g *GithubRegistry) GetURL(t Type) (string, error) {
}
for _, f := range dc {
if *f.Type == "file" {
if *f.Name == t.Version+".jinja" || *f.Name == t.Version+".py" {
if *f.Name == t.Name+".jinja" || *f.Name == t.Name+".py" {
return *f.DownloadURL, nil
}
}
......@@ -80,12 +75,11 @@ func (g *GithubRegistry) GetURL(t Type) (string, error) {
}
func (g *GithubRegistry) getDirs(dir string) ([]string, error) {
_, dc, resp, err := g.client.Repositories.GetContents(g.owner, g.repository, dir, nil)
_, dc, _, err := g.client.Repositories.GetContents(g.owner, g.repository, dir, nil)
if err != nil {
log.Printf("Failed to call ListRefs : %v", err)
return nil, err
}
log.Printf("Got: %v %v", dc, resp, err)
var dirs []string
for _, entry := range dc {
if *entry.Type == "dir" {
......
......@@ -29,8 +29,7 @@ package registry
// replicatedservice.python
// replicatedservice.python.schema
//const TypesDir string = "types"
const TypesDir string = "examples"
const TypesDir string = "types"
type Type struct {
Name string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment