Example #1
0
func (i *INILoader) setField(field *structs.Field, c *goconfig.ConfigFile, section string) error {
	//first process each subfield of a struct field
	switch field.Kind() {
	case reflect.Struct:
		for _, f := range field.Fields() {
			var subsection string
			if section == "" {
				subsection = field.Name()
			} else {
				subsection = section + "." + field.Name()
			}
			if err := i.setField(f, c, subsection); err != nil {
				return err
			}
		}
	default:
		v, err := c.GetValue(section, field.Name())
		if err == nil && v != "" {
			err := fieldSet(field, v)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
Example #2
0
func GetLocal(c *goconfig.ConfigFile) map[string]string {
	local := make(map[string]string)
	dir := c.GetKeyList("local")
	for _, v := range dir {
		row, _ := c.GetValue("local", v)
		local[strings.Trim(v, "#")] = row
	}
	return local
}
Example #3
0
func GetHost(c *goconfig.ConfigFile) map[string][]string {
	server := make(map[string][]string)
	host := c.GetKeyList("host")
	for _, v := range host {
		row, _ := c.GetValue("host", v)
		server[strings.Trim(v, "#")] = strings.Split(row, "`")
	}
	return server
}
Example #4
0
func GetGlobal(c *goconfig.ConfigFile) map[string]string {
	global := make(map[string]string)
	cmds := c.GetKeyList("global")
	for _, v := range cmds {
		row, _ := c.GetValue("global", v)
		global[strings.Trim(v, "#")] = row
	}
	return global
}
Example #5
0
func config(cfg *goconfig.ConfigFile, section string, key string, lvl level) string {
	value, err := cfg.GetValue(section, key)
	if err != nil {
		switch lvl {
		case FATAL:
			logger.Critical("Can't Read config %s", err.Error())
			panic(err.Error())
		case ERROR:
			logger.Error("Can't Read config %s", err.Error())
		case WARMING:
			logger.Warn("Can't Read config %s", err.Error())
		case INFO:
			logger.Info("Can't Read config %s", err.Error())
		}
		return ""
	}
	return value
}
Example #6
0
func NewDaemonFromDirectory(cfg *goconfig.ConfigFile) (*Daemon, error) {
	kernel, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Kernel")
	initrd, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Initrd")
	glog.V(0).Infof("The config: kernel=%s, initrd=%s", kernel, initrd)
	vboxImage, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Vbox")
	glog.V(0).Infof("The config: vbox image=%s", vboxImage)
	biface, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bridge")
	bridgeip, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "BridgeIP")
	glog.V(0).Infof("The config: bridge=%s, ip=%s", biface, bridgeip)
	bios, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bios")
	cbfs, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Cbfs")
	glog.V(0).Infof("The config: bios=%s, cbfs=%s", bios, cbfs)
	host, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Host")

	var tempdir = path.Join(utils.HYPER_ROOT, "run")
	os.Setenv("TMPDIR", tempdir)
	if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}

	var realRoot = path.Join(utils.HYPER_ROOT, "lib")
	// Create the root directory if it doesn't exists
	if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}

	var (
		db_file = fmt.Sprintf("%s/hyper.db", realRoot)
	)
	db, err := daemondb.NewDaemonDB(db_file)
	if err != nil {
		return nil, err
	}

	daemon := &Daemon{
		ID:          fmt.Sprintf("%d", os.Getpid()),
		db:          db,
		Kernel:      kernel,
		Initrd:      initrd,
		Bios:        bios,
		Cbfs:        cbfs,
		VboxImage:   vboxImage,
		PodList:     NewPodList(),
		VmList:      NewVmList(),
		Host:        host,
		BridgeIP:    bridgeip,
		BridgeIface: biface,
	}

	daemon.Daemon, err = docker.NewDaemon(dockerCfg, registryCfg)
	if err != nil {
		return nil, err
	}

	// Get the docker daemon info
	sysinfo, err := daemon.Daemon.SystemInfo()
	if err != nil {
		return nil, err
	}
	stor, err := StorageFactory(sysinfo)
	if err != nil {
		return nil, err
	}
	daemon.Storage = stor
	daemon.Storage.Init()

	return daemon, nil
}
Example #7
0
// downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only.
func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
	// Check all packages, they may be raw packages path.
	for _, n := range nodes {
		// Check if local reference
		if n.Type == doc.LOCAL {
			continue
		}
		// Check if it is a valid remote path or C.
		if n.ImportPath == "C" {
			continue
		} else if !doc.IsValidRemotePath(n.ImportPath) {
			// Invalid import path.
			log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%s@%s:%s",
				n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
			failConut++
			continue
		}

		// Valid import path.
		gopathDir := path.Join(installGopath, n.ImportPath)
		n.RootPath = doc.GetProjectPath(n.ImportPath)
		installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value)

		if isSubpackage(n.RootPath, ".") {
			continue
		}

		// Indicates whether need to download package again.
		if n.IsFixed() && com.IsExist(installPath) {
			n.IsGetDepsOnly = true
		}

		if !ctx.Bool("update") {
			// Check if package has been downloaded.
			if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
				com.IsExist(installPath) {
				log.Trace("Skipped installed package: %s@%s:%s",
					n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))

				// Only copy when no version control.
				if ctx.Bool("gopath") && com.IsExist(installPath) ||
					len(getVcsName(gopathDir)) == 0 {
					copyToGopath(installPath, gopathDir)
				}
				continue
			} else {
				doc.LocalNodes.SetValue(n.RootPath, "value", "")
			}
		}

		if downloadCache[n.RootPath] {
			log.Trace("Skipped downloaded package: %s@%s:%s",
				n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
			continue
		}

		// Download package.
		nod, imports := downloadPackage(ctx, n)
		if len(imports) > 0 {
			var gf *goconfig.ConfigFile

			// Check if has gopmfile.
			if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) {
				log.Log("Found gopmfile: %s@%s:%s",
					n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
				gf = doc.NewGopmfile(installPath)
			}

			// Need to download dependencies.
			// Generate temporary nodes.
			nodes := make([]*doc.Node, len(imports))
			for i := range nodes {
				nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true)

				if gf == nil {
					continue
				}

				// Check if user specified the version.
				if v, err := gf.GetValue("deps", imports[i]); err == nil && len(v) > 0 {
					nodes[i].Type, nodes[i].Value = validPath(v)
				}
			}
			downloadPackages(ctx, nodes)
		}

		// Only save package information with specific commit.
		if nod == nil {
			continue
		}

		// Save record in local nodes.
		log.Success("SUCC", "GET", fmt.Sprintf("%s@%s:%s",
			n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
		downloadCount++

		// Only save non-commit node.
		if len(nod.Value) == 0 && len(nod.Revision) > 0 {
			doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision)
		}

		if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") &&
			len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 {
			copyToGopath(installPath, gopathDir)
		}
	}
}