示例#1
0
文件: marathon.go 项目: ch3lo/crane
func NewMarathon(params *Parameters) (*Marathon, error) {
	helper := new(Marathon)
	endpointUrl := utils.ValidateEndpoint(params.EndpointUrl)

	helper.endpointUrl = endpointUrl
	helper.deployTimeout = params.DeployTimeout
	config := marathon.NewDefaultConfig()
	config.URL = endpointUrl
	if params.HTTPBasicAuthUser != "" {
		config.HTTPBasicAuthUser = params.HTTPBasicAuthUser
		config.HTTPBasicPassword = params.HTTPBasicAuthPassword
	}
	client, err := marathon.NewClient(config)

	if err != nil {
		return nil, err
	}

	helper.client = client
	helper.dockerCfg = params.DockerCfg
	return helper, nil
}
func NewMarathon(params *Parameters) (*Marathon, error) {
	helper := new(Marathon)
	helper.deployTimeout = params.DeployTimeout
	helper.logEntry = logger.Instance().WithFields(params.LogMetadata)
	helper.dockerCfg = params.DockerCfg

	helper.retryTimes = 3
	if params.RetryTimes != -1 {
		helper.retryTimes = params.RetryTimes
	}

	config := marathon.NewDefaultConfig()
	config.URL = utils.ValidateEndpoint(params.EndpointUrl)

	config.HTTPClient = &http.Client{
		Timeout: (time.Duration(10) * time.Second),
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
	}

	if params.HTTPBasicAuthUser != "" {
		config.HTTPBasicAuthUser = params.HTTPBasicAuthUser
		config.HTTPBasicPassword = params.HTTPBasicAuthPassword
	}

	client, err := marathon.NewClient(config)
	if err != nil {
		return nil, framework.NewFrameworkClientError(frameworkID, err)
	}

	helper.client = client
	return helper, nil
}