Example #1
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
}
Example #2
0
func createHost(cluster *machine.Cluster, name string) *machine.Machine {
	opts := make(map[string]string)
	opts["virtualbox-memory"] = "512"
	opts["engine-label"] = "role=worker group=tomcat"
	os.Setenv("VIRTUALBOX_DISK_SIZE", "5000")
	md := &machine.MachineOptions{
		Options: &options.Options{Values: opts},
	}
	m, err := cluster.Create(name, "virtualbox", md)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
	}
	return m
}