예제 #1
0
func newOVirtCloud(config io.Reader) (*OVirtCloud, error) {
	if config == nil {
		return nil, fmt.Errorf("missing configuration file for ovirt cloud provider")
	}

	oVirtConfig := OVirtApiConfig{}

	/* defaults */
	oVirtConfig.Connection.Username = "******"

	if err := gcfg.ReadInto(&oVirtConfig, config); err != nil {
		return nil, err
	}

	if oVirtConfig.Connection.ApiEntry == "" {
		return nil, fmt.Errorf("missing ovirt uri in cloud provider configuration")
	}

	request, err := url.Parse(oVirtConfig.Connection.ApiEntry)
	if err != nil {
		return nil, err
	}

	request.Path = path.Join(request.Path, "vms")
	request.User = url.UserPassword(oVirtConfig.Connection.Username, oVirtConfig.Connection.Password)
	request.RawQuery = url.Values{"search": {oVirtConfig.Filters.VmsQuery}}.Encode()

	return &OVirtCloud{VmsRequest: request}, nil
}
예제 #2
0
func ReadConfiguration(reader io.Reader, config *Config) error {
	wrapper := configWrapper{Default: *config}
	wrapper.Default.ResyncPeriod = 0

	buffer := readSection(reader, "default")
	err := gcfg.ReadInto(&wrapper, bytes.NewReader(buffer.Bytes()))
	if err != nil {
		return err
	}

	if wrapper.Default.ResyncPeriod != 0 {
		wrapper.Default.ResyncPeriod = wrapper.Default.ResyncPeriod * time.Second
	} else {
		wrapper.Default.ResyncPeriod = config.ResyncPeriod
	}

	if clusterIp := wrapper.Default.ClusterIpRange; clusterIp != "" {
		if _, _, err := net.ParseCIDR(clusterIp); err != nil {
			return err
		}
	}

	*config = wrapper.Default
	return nil
}
예제 #3
0
func readConfig(config io.Reader) (Config, error) {
	if config == nil {
		err := fmt.Errorf("no OpenStack cloud provider config file given")
		return Config{}, err
	}

	var cfg Config
	err := gcfg.ReadInto(&cfg, config)
	return cfg, err
}
예제 #4
0
파일: config.go 프로젝트: qinguoan/vulcan
func (c *Config) Read(configReader io.Reader) error {
	wrapper := &ConfigWrapper{Scheduler: *c}
	if configReader != nil {
		if err := gcfg.ReadInto(wrapper, configReader); err != nil {
			return err
		}
		*c = wrapper.Scheduler
	}
	return nil
}
예제 #5
0
func readConfig(configReader io.Reader) (*Config, error) {
	config := createDefaultConfig()
	wrapper := &ConfigWrapper{Mesos_Cloud: *config}
	if configReader != nil {
		if err := gcfg.ReadInto(wrapper, configReader); err != nil {
			return nil, err
		}
		config = &(wrapper.Mesos_Cloud)
	}
	return config, nil
}
예제 #6
0
func readConfig(configFile string) (openStackConfig, error) {
	var config *os.File
	config, err := os.Open(configFile)
	if err != nil {
		return openStackConfig{}, err
	}
	defer config.Close()

	if config == nil {
		err := fmt.Errorf("no OpenStack cloud provider config file given")
		return openStackConfig{}, err
	}

	var cfg openStackConfig
	err = gcfg.ReadInto(&cfg, config)
	return cfg, err
}
예제 #7
0
func (c *Config) ReadConfiguration(global *network.Config, reader io.Reader) error {
	if global != nil && c.ServiceSubnet == DefaultServiceSubnet {
		c.ServiceSubnet = global.ClusterIpRange
	}

	if reader == nil {
		return nil
	}

	wrapper := configWrapper{OpenContrail: *c}
	if err := gcfg.ReadInto(&wrapper, reader); err != nil {
		return err
	}
	if err := wrapper.OpenContrail.Validate(); err != nil {
		return err
	}
	*c = wrapper.OpenContrail
	return nil
}
예제 #8
0
파일: gce.go 프로젝트: pyk/kubernetes
// newGCECloud creates a new instance of GCECloud.
func newGCECloud(config io.Reader) (*GCECloud, error) {
	projectID, zone, err := getProjectAndZone()
	if err != nil {
		return nil, err
	}
	// TODO: if we want to use this on a machine that doesn't have the http://metadata server
	// e.g. on a user's machine (not VM) somewhere, we need to have an alternative for
	// instance id lookup.
	instanceID, err := getInstanceID()
	if err != nil {
		return nil, err
	}
	externalID, err := getCurrentExternalID()
	if err != nil {
		return nil, err
	}
	networkName, err := getNetworkName()
	if err != nil {
		return nil, err
	}
	networkURL := gceNetworkURL(projectID, networkName)
	tokenSource := google.ComputeTokenSource("")
	if config != nil {
		var cfg Config
		if err := gcfg.ReadInto(&cfg, config); err != nil {
			glog.Errorf("Couldn't read config: %v", err)
			return nil, err
		}
		if cfg.Global.ProjectID != "" {
			projectID = cfg.Global.ProjectID
		}
		if cfg.Global.NetworkName != "" {
			if strings.Contains(cfg.Global.NetworkName, "/") {
				networkURL = cfg.Global.NetworkName
			} else {
				networkURL = gceNetworkURL(cfg.Global.ProjectID, cfg.Global.NetworkName)
			}
		}
		if cfg.Global.TokenURL != "" {
			tokenSource = newAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
		}
	}
	client := oauth2.NewClient(oauth2.NoContext, tokenSource)
	svc, err := compute.New(client)
	if err != nil {
		return nil, err
	}
	containerSvc, err := container.New(client)
	if err != nil {
		return nil, err
	}
	return &GCECloud{
		service:          svc,
		containerService: containerSvc,
		projectID:        projectID,
		zone:             zone,
		instanceID:       instanceID,
		externalID:       externalID,
		networkURL:       networkURL,
	}, nil
}