Esempio n. 1
0
func (od *OptsDriver) RefreshVirtualboxOptions(opts *options.Options) error {
	cpu := opts.Int("cpu")
	if cpu <= 0 {
		cpu = 1
	}
	opts.Apply("virtualbox-cpu-count", fmt.Sprintf("%d", cpu))

	memory := opts.String("memory")
	if memory == "" {
		memory = "1g"
	}
	membytes, merr := utils.ParseCapacity(memory)
	if merr != nil {
		return fmt.Errorf("'%s' is not a valid memory option.", memory)
	}
	opts.Apply("virtualbox-memory", fmt.Sprintf("%d", membytes/1024/1024))

	disk := opts.String("disk")
	if disk == "" {
		disk = "10g"
	}
	diskbytes, derr := utils.ParseCapacity(disk)
	if derr != nil {
		return fmt.Errorf("'%s' is not a valid disk option.", disk)
	}
	opts.Apply("virtualbox-disk-size", fmt.Sprintf("%d", diskbytes/1024/1024))
	return nil
}
Esempio n. 2
0
func NewCluster(gopt *options.Options) (*Cluster, error) {
	rootPath := gopt.String("storage-path")
	os.Setenv("MACHINE_STORAGE_PATH", rootPath)
	if gopt.Bool("native-ssh") {
		ssh.SetDefaultClient(ssh.Native)
	}

	auth := getTLSAuthOptions(gopt)
	store := libmachine.NewFilestore(rootPath, auth.CaCertPath, auth.CaKeyPath)
	provider, _ := libmachine.New(store)
	hosts, err := provider.List()
	if err != nil {
		return nil, err
	}
	machines := make(map[string]*Machine, len(hosts))
	for _, h := range hosts {
		machines[h.Name] = &Machine{
			Host: h,
		}
	}

	c := &Cluster{
		provider:    provider,
		machines:    machines,
		authOptions: auth,
	}
	c.LoadStates()
	return c, nil
}
Esempio n. 3
0
func getMasterMachine(clusterOpts *options.Options, mcluster *machine.Cluster, td *descriptions.TopologyDescription) (*machine.Machine, error) {
	var m *machine.Machine
	masterName := clusterOpts.String("master-machine-name")
	if masterName != "" {
		exists := false
		m, exists = mcluster.Get(masterName)
		if !exists {
			logrus.Infof("cluster master machine is not exists, crating a new one. name:%s", masterName)
			masterGroup := clusterOpts.String("master-machine-group")
			md := td.GetMachineOptionsBy(masterGroup)
			if md == nil {
				return nil, fmt.Errorf("no machine options found for master '%s'", masterGroup)
			}
			m, err := mcluster.Create(masterName, md.DriverName, md)
			if err != nil {
				return nil, err
			}
			return m, nil
		} else {
			s := m.GetCachedState()
			if !machine.IsRunning(s) {
				logrus.Infof("master machine '%s' is '%s', try to restart.", masterName, s.String())
				if err := m.Start(); err != nil {
					return nil, fmt.Errorf("master machine '%s' exists, but start failed.", masterName)
				}
			}
			return m, nil
		}
	} else {
		logrus.Warnf("master name not specified in container cluster.")
	}
	return m, nil
}
Esempio n. 4
0
func getEngineOptions(opt *options.Options) *EngineOptions {
	return &EngineOptions{
		ArbitraryFlags:   opt.StringSlice("engine-opt"),
		Env:              opt.StringSlice("engine-env"),
		InsecureRegistry: opt.StringSlice("engine-insecure-registry"),
		Labels:           opt.StringSlice("engine-label"),
		RegistryMirror:   opt.StringSlice("engine-registry-mirror"),
		StorageDriver:    opt.String("engine-storage-driver"),
		TlsVerify:        true,
		InstallURL:       opt.String("engine-install-url"),
	}
}
Esempio n. 5
0
func getNum(key string, errVal int, opts *options.Options) int {
	str := opts.String(key)
	if str == "" {
		logrus.Warnf("'%s' options is not found, %d is the default", key, errVal)
		return errVal
	}
	val, err := strconv.Atoi(str)
	if err != nil {
		logrus.Warnf("'%s' is not a valid number, %d is the default. err:%s", str, errVal, err.Error())
		return errVal
	}
	return int(val)
}
Esempio n. 6
0
func getTLSAuthOptions(opt *options.Options) *AuthOptions {
	caCertPath := opt.String("tls-ca-cert")
	caKeyPath := opt.String("tls-ca-key")
	clientCertPath := opt.String("tls-client-cert")
	clientKeyPath := opt.String("tls-client-key")

	if caCertPath == "" {
		caCertPath = filepath.Join(utils.GetMachineCertDir(), "ca.pem")
	}

	if caKeyPath == "" {
		caKeyPath = filepath.Join(utils.GetMachineCertDir(), "ca-key.pem")
	}

	if clientCertPath == "" {
		clientCertPath = filepath.Join(utils.GetMachineCertDir(), "cert.pem")
	}

	if clientKeyPath == "" {
		clientKeyPath = filepath.Join(utils.GetMachineCertDir(), "key.pem")
	}

	return &AuthOptions{
		CaCertPath:     caCertPath,
		CaKeyPath:      caKeyPath,
		ClientCertPath: clientCertPath,
		ClientKeyPath:  clientKeyPath,
	}
}