本文整理汇总了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())
}
示例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())
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例8: GetRancherClient
func GetRancherClient(conf Config) (*client.RancherClient, error) {
return client.NewRancherClient(&client.ClientOpts{
Url: conf.CattleURL,
AccessKey: conf.CattleAccessKey,
SecretKey: conf.CattleSecretKey,
})
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}