当前位置: 首页>>代码示例>>Golang>>正文


Golang client.NewRancherClient函数代码示例

本文整理汇总了Golang中github.com/rancher/go-rancher/client.NewRancherClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRancherClient函数的具体用法?Golang NewRancherClient怎么用?Golang NewRancherClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewRancherClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMain

func TestMain(m *testing.M) {
	var err error

	apiUrl := "http://localhost:8080/v1/projects/1a5/schema"
	accessKey := ""
	secretKey := ""

	//1a5 is admin account, 1a6 will be the service account, therefore trying to create a new account of type starting from 1a7
	//if 1a7 exists, and is not a user account then a new account with the next available id will be created
	id := createIfNoAccount("1a7")
	apiUrl2 := "http://localhost:8080/v1/projects/" + id + "/schema"

	apiClient, err = client.NewRancherClient(&client.ClientOpts{
		Url:       apiUrl,
		AccessKey: accessKey,
		SecretKey: secretKey,
	})
	if err != nil {
		log.Fatal("Error while initializing rancher client, err = ", err)
	}
	apiClient2, err = client.NewRancherClient(&client.ClientOpts{
		Url:       apiUrl2,
		AccessKey: accessKey,
		SecretKey: secretKey,
	})
	if err != nil {
		log.Fatal("Error while initializing rancher client, err = ", err)
	}
	os.Exit(m.Run())
}
开发者ID:wlan0,项目名称:rancher-compose-executor,代码行数:30,代码来源:common_test.go

示例2: TestMain

func TestMain(m *testing.M) {
	var err error

	adminUrl := "http://localhost:8080/v1"
	apiUrl := adminUrl + "/projects/1a5/schemas"
	accessKey := ""
	secretKey := ""

	adminClient, err := client.NewRancherClient(&client.ClientOpts{
		Url:       adminUrl,
		AccessKey: accessKey,
		SecretKey: secretKey,
	})
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; ; i++ {
		handlers, err := adminClient.ExternalHandler.List(&client.ListOpts{
			Filters: map[string]interface{}{
				"name":  "rancher-compose-executor",
				"state": "active",
			},
		})
		if err != nil {
			log.Fatal(err)
		}
		if len(handlers.Data) > 0 {
			break
		}
		if i > 3 {
			log.Fatal("Handler is not available")
		}
		time.Sleep(1 * time.Second)
	}

	id := createIfNoAccount(adminUrl, "rancher-compose-executor-tests")
	apiUrl2 := adminUrl + "/projects/" + id + "/schemas"

	apiClient, err = client.NewRancherClient(&client.ClientOpts{
		Url:       apiUrl,
		AccessKey: accessKey,
		SecretKey: secretKey,
	})
	if err != nil {
		log.Fatal("Error while initializing rancher client, err = ", err)
	}
	apiClient2, err = client.NewRancherClient(&client.ClientOpts{
		Url:       apiUrl2,
		AccessKey: accessKey,
		SecretKey: secretKey,
	})
	if err != nil {
		log.Fatal("Error while initializing rancher client, err = ", err)
	}
	os.Exit(m.Run())
}
开发者ID:alena1108,项目名称:rancher-compose-executor,代码行数:57,代码来源:common_test.go

示例3: open

func (c *Context) open() error {
	if c.isOpen {
		return nil
	}

	if err := c.readRancherConfig(); err != nil {
		return err
	}

	if c.Url == "" {
		return fmt.Errorf("RANCHER_URL is not set")
	}

	if client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
		Url:       c.Url,
		AccessKey: c.AccessKey,
		SecretKey: c.SecretKey,
	}); err != nil {
		return err
	} else {
		c.Client = client
	}

	if err := c.loadEnv(); err != nil {
		return err
	}

	c.isOpen = true
	return nil
}
开发者ID:wlan0,项目名称:rancher-compose-executor,代码行数:30,代码来源:context.go

示例4: createIfNoAccount

func createIfNoAccount(apiUrl, name string) string {
	apiClient, err := client.NewRancherClient(&client.ClientOpts{
		Url: apiUrl,
	})
	if err != nil {
		log.Fatalf("Error while initializing rancher client, err = [%v]", err)
	}
	accs, err := apiClient.Account.List(&client.ListOpts{
		Filters: map[string]interface{}{
			"name": name,
		},
	})
	if err != nil {
		log.Fatalf("Failed to list accounts")
	}

	if len(accs.Data) == 0 {
		acc, err := apiClient.Account.Create(&client.Account{
			Kind: "project",
			Name: name,
		})
		if err != nil {
			log.Fatalf("Error while creating new account, err = [%v]", err)
		}
		waitTransition(apiClient, acc)
		return acc.Id
	}

	return accs.Data[0].Id
}
开发者ID:alena1108,项目名称:rancher-compose-executor,代码行数:30,代码来源:common_test.go

示例5: NewEventRouter

func NewEventRouter(name string, priority int, apiUrl string, accessKey string, secretKey string,
	apiClient *client.RancherClient, eventHandlers map[string]EventHandler, resourceName string, workerCount int) (*EventRouter, error) {

	if apiClient == nil {
		var err error
		apiClient, err = client.NewRancherClient(&client.ClientOpts{

			Url:       apiUrl,
			AccessKey: accessKey,
			SecretKey: secretKey,
		})
		if err != nil {
			return nil, err
		}
	}

	// TODO Get subscribe collection URL from API instead of hard coding
	subscribeUrl := strings.Replace(apiUrl+"/subscribe", "http", "ws", -1)

	return &EventRouter{
		name:          name,
		priority:      priority,
		apiUrl:        apiUrl,
		accessKey:     accessKey,
		secretKey:     secretKey,
		apiClient:     apiClient,
		subscribeUrl:  subscribeUrl,
		eventHandlers: eventHandlers,
		workerCount:   workerCount,
		mu:            &sync.Mutex{},
		resourceName:  resourceName,
	}, nil
}
开发者ID:att-innovate,项目名称:go-machine-service,代码行数:33,代码来源:listener.go

示例6: NewEventRouter

func NewEventRouter(name string, priority int, apiURL string, accessKey string, secretKey string,
	apiClient *client.RancherClient, eventHandlers map[string]EventHandler, resourceName string, workerCount int,
	pingConfig PingConfig) (*EventRouter, error) {

	if apiClient == nil {
		var err error
		apiClient, err = client.NewRancherClient(&client.ClientOpts{
			Timeout:   time.Second * 30,
			Url:       apiURL,
			AccessKey: accessKey,
			SecretKey: secretKey,
		})
		if err != nil {
			return nil, err
		}
	}

	// TODO Get subscribe collection URL from API instead of hard coding
	subscribeURL := strings.Replace(apiURL+"/subscribe", "http", "ws", -1)

	return &EventRouter{
		name:          name,
		priority:      priority,
		apiURL:        apiURL,
		accessKey:     accessKey,
		secretKey:     secretKey,
		apiClient:     apiClient,
		subscribeURL:  subscribeURL,
		eventHandlers: eventHandlers,
		workerCount:   workerCount,
		resourceName:  resourceName,
		pingConfig:    pingConfig,
	}, nil
}
开发者ID:rancher,项目名称:kubernetes-agent,代码行数:34,代码来源:listener.go

示例7: NewClient

// NewClient returns a new client for the Rancher/Cattle API
func NewClient(rancherUrl string, rancherAccessKey string, rancherSecretKey string) (*Client, error) {
	opts := &rancherClient.ClientOpts{
		Url:       rancherUrl,
		AccessKey: rancherAccessKey,
		SecretKey: rancherSecretKey,
		Timeout:   time.Second * 5,
	}

	var err error
	var apiClient *rancherClient.RancherClient
	maxTime := 10 * time.Second

	for i := 1 * time.Second; i < maxTime; i *= time.Duration(2) {
		apiClient, err = rancherClient.NewRancherClient(opts)
		if err == nil {
			break
		}
		time.Sleep(i)
	}

	if err != nil {
		return nil, err
	}

	return &Client{apiClient}, nil
}
开发者ID:janeczku,项目名称:rancher-letsencrypt,代码行数:27,代码来源:client.go

示例8: GetRancherClient

func GetRancherClient(conf Config) (*client.RancherClient, error) {
	return client.NewRancherClient(&client.ClientOpts{
		Url:       conf.CattleURL,
		AccessKey: conf.CattleAccessKey,
		SecretKey: conf.CattleSecretKey,
	})
}
开发者ID:cjellick,项目名称:kubernetes-agent,代码行数:7,代码来源:config.go

示例9: NewCattleClient

func NewCattleClient(cattleUrl string, cattleAccessKey string, cattleSecretKey string) (*CattleClient, error) {
	apiClient, err := client.NewRancherClient(&client.ClientOpts{
		Url:       cattleUrl,
		AccessKey: cattleAccessKey,
		SecretKey: cattleSecretKey,
	})

	if err != nil {
		return nil, err
	}

	return &CattleClient{
		rancherClient: apiClient,
	}, nil
}
开发者ID:rancher,项目名称:external-dns,代码行数:15,代码来源:cattle.go

示例10: createEnv

func createEnv(rancherUrl, projectName string, composeBytes []byte, rancherComposeMap map[string]rancher.RancherConfig, env *client.Environment) error {
	context := rancher.Context{
		Url:           rancherUrl,
		RancherConfig: rancherComposeMap,
		Uploader:      nil,
	}
	context.ProjectName = projectName
	context.ComposeBytes = composeBytes
	context.ConfigLookup = nil
	context.EnvironmentLookup = &lookup.OsEnvLookup{}
	context.LoggerFactory = logger.NewColorLoggerFactory()
	context.ServiceFactory = &rancher.RancherServiceFactory{
		Context: &context,
	}

	p := project.NewProject(&context.Context)

	err := p.Parse()
	if err != nil {
		log.WithFields(log.Fields{
			"err": err,
		}).Errorf("Error parsing docker-compose.yml")
		return err
	}

	apiClient, err := client.NewRancherClient(&client.ClientOpts{
		Url:       rancherUrl,
		AccessKey: os.Getenv("CATTLE_ACCESS_KEY"),
		SecretKey: os.Getenv("CATTLE_SECRET_KEY"),
	})

	context.Client = apiClient

	c := &context

	c.Environment = env

	context.SidekickInfo = rancher.NewSidekickInfo(p)

	err = p.Create([]string{}...)
	if err != nil {
		log.WithFields(log.Fields{
			"err": err,
		}).Error("Error while creating project.")
		return err
	}
	return nil
}
开发者ID:wlan0,项目名称:rancher-compose-executor,代码行数:48,代码来源:createHandler.go

示例11: EnvironmentClient

func (c *Config) EnvironmentClient(env string) (*rancherClient.RancherClient, error) {

	url := c.APIURL + "/projects/" + env + "/schemas"
	client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
		Url:       url,
		AccessKey: c.AccessKey,
		SecretKey: c.SecretKey,
	})
	if err != nil {
		return nil, err
	}

	log.Printf("[INFO] Rancher Client configured for url: %s", url)

	return client, nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:16,代码来源:config.go

示例12: CreateClient

// Create creates a generic Rancher client
func (c *Config) CreateClient() error {
	client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
		Url:       c.APIURL,
		AccessKey: c.AccessKey,
		SecretKey: c.SecretKey,
	})
	if err != nil {
		return err
	}

	log.Printf("[INFO] Rancher Client configured for url: %s", c.APIURL)

	c.RancherClient = client

	return nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:17,代码来源:config.go

示例13: NewCattleClient

func NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey string) (*CattleClient, error) {
	if cattleUrl == "" {
		return nil, errors.New("cattle url is empty")
	}

	apiClient, err := client.NewRancherClient(&client.ClientOpts{
		Url:       cattleUrl,
		AccessKey: cattleAccessKey,
		SecretKey: cattleSecretKey,
	})

	if err != nil {
		return nil, err
	}

	return &CattleClient{
		rancherClient: apiClient,
	}, nil
}
开发者ID:ibuildthecloud,项目名称:convoy-agent,代码行数:19,代码来源:cattle.go

示例14: loadClient

func (c *Context) loadClient() (*rancherClient.RancherClient, error) {
	if c.Client == nil {
		if c.Url == "" {
			return nil, fmt.Errorf("RANCHER_URL is not set")
		}

		if client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
			Url:       c.Url,
			AccessKey: c.AccessKey,
			SecretKey: c.SecretKey,
		}); err != nil {
			return nil, err
		} else {
			c.Client = client
		}
	}

	return c.Client, nil
}
开发者ID:cloudnautique,项目名称:rancher-compose,代码行数:19,代码来源:context.go

示例15: loadRancherClient

func (c *Context) loadRancherClient() error {
	if c.Client == nil {
		if c.RancherURL == "" {
			return fmt.Errorf("RancherURL is nil, can not change Scale")
		}

		client, err := client.NewRancherClient(&client.ClientOpts{
			Url:       c.RancherURL,
			AccessKey: c.accessKey,
			SecretKey: c.secretKey,
		})
		if err != nil {
			return err
		}

		c.Client = client
	}
	return nil
}
开发者ID:cloudnautique,项目名称:cowbell,代码行数:19,代码来源:config.go


注:本文中的github.com/rancher/go-rancher/client.NewRancherClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。