1
0
mirror of https://github.com/rancher/os.git synced 2025-09-02 07:15:41 +00:00

ros list shows all the active services and any cache available updates

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-03-03 14:02:44 +10:00
parent 23e51e3b8d
commit 8d941162d8
9 changed files with 378 additions and 122 deletions

52
util/network/network.go Normal file → Executable file
View File

@@ -32,6 +32,48 @@ func GetEngines(urls []string) ([]string, error) {
return getServices(urls, "engines")
}
func FetchAllServices() error {
cfg := config.LoadConfig()
for name, url := range cfg.Rancher.Repositories {
log.Infof("repo index %s: %v", name, url.URL)
indexURL := fmt.Sprintf("%s/index.yml", url.URL)
content, err := loadFromNetwork(indexURL)
if err != nil {
log.Errorf("Failed to load %s: %v", indexURL, err)
continue
}
// save the index file to the cache dir
cacheAdd(fmt.Sprintf("%s/index.yml", name), content)
// load it, and then download each service file and cache too
services := make(map[string][]string)
err = yaml.Unmarshal(content, &services)
if err != nil {
log.Errorf("Failed to unmarshal %s: %v", indexURL, err)
continue
}
for serviceType, serviceList := range services {
for _, serviceName := range serviceList {
fmt.Printf("\t%s is type %s from %s\n", serviceName, serviceType, name)
serviceURL := serviceURL(url.URL, serviceName)
content, err := loadFromNetwork(serviceURL)
if err != nil {
log.Errorf("Failed to load %s: %v", serviceURL, err)
continue
}
// save the service file to the cache dir
if err = cacheAdd(fmt.Sprintf("%s/%s.yml", name, serviceName), content); err != nil {
log.Errorf("cacheAdd: %s", err)
}
//display which services are new, and which are updated from previous cache
//and `listServices` will need to compare the cached servcies with the version that was enabled/up
//also list the services that are no longer updated (ie, purge candidates)
}
}
}
return nil
}
func getServices(urls []string, key string) ([]string, error) {
result := []string{}
@@ -80,11 +122,11 @@ func SetProxyEnvironmentVariables(cfg *config.CloudConfig) {
}
func loadFromNetwork(location string) ([]byte, error) {
bytes := cacheLookup(location)
if bytes != nil {
return bytes, nil
}
/* bytes := cacheLookup(location)
if bytes != nil {
return bytes, nil
}
*/
cfg := config.LoadConfig()
SetProxyEnvironmentVariables(cfg)