當前位置: 首頁>>代碼示例>>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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例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;未經允許,請勿轉載。