本文整理汇总了Golang中github.com/juju/juju/cmd/envcmd.GetDefaultEnvironment函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDefaultEnvironment函数的具体用法?Golang GetDefaultEnvironment怎么用?Golang GetDefaultEnvironment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDefaultEnvironment函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetDefaultEnvironmentCurrentEnvironmentSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentCurrentEnvironmentSet(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "fubar")
c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:7,代码来源:environmentcommand_test.go
示例2: TestGetDefaultEnvironmentBothSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentBothSet(c *gc.C) {
os.Setenv(osenv.JujuEnvEnvKey, "magic")
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "magic")
c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:8,代码来源:environmentcommand_test.go
示例3: TestGetDefaultEnvironmentNothingSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentNothingSet(c *gc.C) {
envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
err := os.Remove(envPath)
c.Assert(err, gc.IsNil)
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "")
c.Assert(err, jc.Satisfies, environs.IsNoEnv)
}
开发者ID:klyachin,项目名称:juju,代码行数:8,代码来源:environmentcommand_test.go
示例4: switchEnvironment
// switchEnvironment changes the default environment to the given name and
// return, if set, the current default environment name.
func switchEnvironment(envName string) (string, error) {
if defaultEnv := os.Getenv(osenv.JujuEnvEnvKey); defaultEnv != "" {
return "", errors.Errorf("cannot switch when %s is overriding the environment (set to %q)", osenv.JujuEnvEnvKey, defaultEnv)
}
currentEnv, err := envcmd.GetDefaultEnvironment()
if err != nil {
return "", errors.Annotate(err, "cannot get the default environment")
}
if err := envcmd.WriteCurrentEnvironment(envName); err != nil {
return "", errors.Trace(err)
}
return currentEnv, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:15,代码来源:jenv.go
示例5: TestGetDefaultEnvironmentJujuEnvSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentJujuEnvSet(c *gc.C) {
os.Setenv(osenv.JujuEnvEnvKey, "magic")
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "magic")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:6,代码来源:environmentcommand_test.go
示例6: TestGetDefaultEnvironment
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironment(c *gc.C) {
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "erewhemos")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:5,代码来源:environmentcommand_test.go
示例7: answer
// TODO(axw) define an error for "no answer"
func (s *jujuNameServer) answer(q dns.Question) (dns.RR, error) {
if q.Qtype != dns.TypeA {
return nil, nil
}
var envName string
entityName := strings.ToLower(strings.TrimSuffix(q.Name, "."+zone))
if i := strings.IndexRune(entityName, '.'); i >= 0 {
envName = entityName[i+1:]
entityName = entityName[:i]
} else {
var err error
envName, err = envcmd.GetDefaultEnvironment()
if err != nil {
return nil, err
}
}
// TODO(axw) cache API connection
api, err := s.openAPI(envName)
if err != nil {
return nil, err
}
defer api.Close()
client := api.Client()
// If the entity name parses as a tag, extract the ID. This enables
// us to address "unit-mysql-0", where we couldn't otherwise, since
// slashes are not allowed in domain names. Similarly for container
// machines (e.g. to address "0/lxc/0", pass "machine-0-lxc-0").
if tag, err := names.ParseTag(entityName); err == nil {
entityName = tag.Id()
}
var addr string
if names.IsValidService(entityName) {
status, err := client.Status([]string{entityName})
if err != nil {
return nil, err
}
service := status.Services[entityName]
addresses := make([]string, 0, len(service.Units))
for _, unit := range service.Units {
if unit.PublicAddress == "" {
continue
}
if includeLost || unit.UnitAgent.Status != "lost" {
addresses = append(addresses, unit.PublicAddress)
}
}
// Might be nice to have additional info in TXT?
if len(addresses) == 0 {
return nil, nil
}
addr = addresses[rand.Intn(len(addresses))]
} else {
// Assume it's a machine or unit name.
addr, err = client.PublicAddress(entityName)
if err != nil {
return nil, err
}
}
ip := net.ParseIP(addr)
if ip != nil {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0,
}
rr.A = ip
return rr, nil
} else {
rr := new(dns.CNAME)
rr.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: 0,
}
rr.Target = addr + "."
return rr, nil
}
}
开发者ID:axw,项目名称:jns,代码行数:87,代码来源:main.go
注:本文中的github.com/juju/juju/cmd/envcmd.GetDefaultEnvironment函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论