LEFT | RIGHT |
(no file at all) | |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "fmt" | 5 "fmt" |
6 "io" | 6 "io" |
7 "launchpad.net/gnuflag" | 7 "launchpad.net/gnuflag" |
8 "launchpad.net/juju-core/cmd" | 8 "launchpad.net/juju-core/cmd" |
9 "launchpad.net/juju-core/environs" | 9 "launchpad.net/juju-core/environs" |
| 10 "launchpad.net/juju-core/environs/tools" |
10 "launchpad.net/juju-core/log" | 11 "launchpad.net/juju-core/log" |
11 "launchpad.net/juju-core/state" | 12 "launchpad.net/juju-core/state" |
12 "launchpad.net/juju-core/version" | 13 "launchpad.net/juju-core/version" |
13 ) | 14 ) |
14 | 15 |
15 // SyncToolsCommand copies all the tools from the us-east-1 bucket to the local | 16 // SyncToolsCommand copies all the tools from the us-east-1 bucket to the local |
16 // bucket. | 17 // bucket. |
17 type SyncToolsCommand struct { | 18 type SyncToolsCommand struct { |
18 EnvCommandBase | 19 EnvCommandBase |
19 allVersions bool | 20 allVersions bool |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 "control-bucket": "juju-dist", | 58 "control-bucket": "juju-dist", |
58 "access-key": "", | 59 "access-key": "", |
59 "secret-key": "", | 60 "secret-key": "", |
60 "authorized-keys": "not-really", // We shouldn't need ssh access | 61 "authorized-keys": "not-really", // We shouldn't need ssh access |
61 } | 62 } |
62 | 63 |
63 func copyOne( | 64 func copyOne( |
64 tool *state.Tools, source environs.StorageReader, | 65 tool *state.Tools, source environs.StorageReader, |
65 target environs.Storage, ctx *cmd.Context, | 66 target environs.Storage, ctx *cmd.Context, |
66 ) error { | 67 ) error { |
67 » toolsPath := environs.ToolsStoragePath(tool.Binary) | 68 » toolsName := tools.StorageName(tool.Binary) |
68 » fmt.Fprintf(ctx.Stderr, "copying %v", toolsPath) | 69 » fmt.Fprintf(ctx.Stderr, "copying %v", toolsName) |
69 » srcFile, err := source.Get(toolsPath) | 70 » srcFile, err := source.Get(toolsName) |
70 if err != nil { | 71 if err != nil { |
71 return err | 72 return err |
72 } | 73 } |
73 defer srcFile.Close() | 74 defer srcFile.Close() |
74 // We have to buffer the content, because Put requires the content | 75 // We have to buffer the content, because Put requires the content |
75 // length, but Get only returns us a ReadCloser | 76 // length, but Get only returns us a ReadCloser |
76 buf := &bytes.Buffer{} | 77 buf := &bytes.Buffer{} |
77 nBytes, err := io.Copy(buf, srcFile) | 78 nBytes, err := io.Copy(buf, srcFile) |
78 if err != nil { | 79 if err != nil { |
79 return err | 80 return err |
80 } | 81 } |
81 » log.Infof("downloaded %v (%dkB), uploading", toolsPath, (nBytes+512)/102
4) | 82 » log.Infof("downloaded %v (%dkB), uploading", toolsName, (nBytes+512)/102
4) |
82 fmt.Fprintf(ctx.Stderr, ", download %dkB, uploading\n", (nBytes+512)/102
4) | 83 fmt.Fprintf(ctx.Stderr, ", download %dkB, uploading\n", (nBytes+512)/102
4) |
83 | 84 |
84 » if err := target.Put(toolsPath, buf, nBytes); err != nil { | 85 » if err := target.Put(toolsName, buf, nBytes); err != nil { |
85 return err | 86 return err |
86 } | 87 } |
87 return nil | 88 return nil |
88 } | 89 } |
89 | 90 |
90 func copyTools( | 91 func copyTools( |
91 tools []*state.Tools, source environs.StorageReader, | 92 tools []*state.Tools, source environs.StorageReader, |
92 target environs.Storage, dryRun bool, ctx *cmd.Context, | 93 target environs.Storage, dryRun bool, ctx *cmd.Context, |
93 ) error { | 94 ) error { |
94 for _, tool := range tools { | 95 for _, tool := range tools { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 fmt.Fprintf(ctx.Stderr, "found %d tools in source (%d recent ones)\n", | 127 fmt.Fprintf(ctx.Stderr, "found %d tools in source (%d recent ones)\n", |
127 len(sourceToolsList.Public), len(toolsToCopy)) | 128 len(sourceToolsList.Public), len(toolsToCopy)) |
128 for _, tool := range toolsToCopy { | 129 for _, tool := range toolsToCopy { |
129 log.Debugf("found source tool: %s", tool) | 130 log.Debugf("found source tool: %s", tool) |
130 } | 131 } |
131 fmt.Fprintf(ctx.Stderr, "listing target bucket\n") | 132 fmt.Fprintf(ctx.Stderr, "listing target bucket\n") |
132 targetToolsList, err := environs.ListTools(targetEnv, version.Current.Ma
jor) | 133 targetToolsList, err := environs.ListTools(targetEnv, version.Current.Ma
jor) |
133 if err != nil { | 134 if err != nil { |
134 return err | 135 return err |
135 } | 136 } |
136 for _, tool := range targetToolsList.Private { | |
137 log.Debugf("found target tool: %s", tool) | |
138 } | |
139 targetTools := targetToolsList.Private | 137 targetTools := targetToolsList.Private |
140 targetStorage := targetEnv.Storage() | 138 targetStorage := targetEnv.Storage() |
141 if c.publicBucket { | 139 if c.publicBucket { |
142 targetTools = targetToolsList.Public | 140 targetTools = targetToolsList.Public |
143 var ok bool | 141 var ok bool |
144 if targetStorage, ok = targetEnv.PublicStorage().(environs.Stora
ge); !ok { | 142 if targetStorage, ok = targetEnv.PublicStorage().(environs.Stora
ge); !ok { |
145 return fmt.Errorf("Cannot write to PublicStorage") | 143 return fmt.Errorf("Cannot write to PublicStorage") |
146 } | 144 } |
147 | 145 » } |
| 146 » for _, tool := range targetTools { |
| 147 » » log.Debugf("found target tool: %s", tool) |
148 } | 148 } |
149 missing := toolsToCopy.Exclude(targetTools) | 149 missing := toolsToCopy.Exclude(targetTools) |
150 fmt.Fprintf(ctx.Stdout, "found %d tools in target; %d tools to be copied
\n", | 150 fmt.Fprintf(ctx.Stdout, "found %d tools in target; %d tools to be copied
\n", |
151 len(targetTools), len(missing)) | 151 len(targetTools), len(missing)) |
152 err = copyTools(missing, officialEnviron.PublicStorage(), targetStorage,
c.dryRun, ctx) | 152 err = copyTools(missing, officialEnviron.PublicStorage(), targetStorage,
c.dryRun, ctx) |
153 if err != nil { | 153 if err != nil { |
154 return err | 154 return err |
155 } | 155 } |
156 fmt.Fprintf(ctx.Stderr, "copied %d tools\n", len(missing)) | 156 fmt.Fprintf(ctx.Stderr, "copied %d tools\n", len(missing)) |
157 return nil | 157 return nil |
158 } | 158 } |
LEFT | RIGHT |