本文整理汇总了Golang中github.com/juju/juju/network.SetPreferIPv6函数的典型用法代码示例。如果您正苦于以下问题:Golang SetPreferIPv6函数的具体用法?Golang SetPreferIPv6怎么用?Golang SetPreferIPv6使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetPreferIPv6函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSelectInternalMachineAddress
func (s *AddressSuite) TestSelectInternalMachineAddress(c *gc.C) {
oldValue := network.GetPreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t := range selectInternalMachineTests {
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
c.Check(network.SelectInternalAddress(t.addresses, true), gc.Equals, t.expected())
}
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:address_test.go
示例2: TestSelectInternalHostPorts
func (s *AddressSuite) TestSelectInternalHostPorts(c *gc.C) {
oldValue := network.PreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t := range selectInternalHostPortsTests {
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
c.Check(network.SelectInternalHostPorts(t.addresses, false), gc.DeepEquals, t.expected)
}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:11,代码来源:address_test.go
示例3: TestSelectInternalMachineHostPort
func (s *PortSuite) TestSelectInternalMachineHostPort(c *gc.C) {
oldValue := network.GetPreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t0 := range selectInternalMachineTests {
t := t0.hostPortTest()
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
c.Check(network.SelectInternalHostPort(t.hostPorts, true), gc.DeepEquals, t.expected())
}
}
开发者ID:kapilt,项目名称:juju,代码行数:12,代码来源:port_test.go
示例4: TestSelectPublicHostPort
func (*HostPortSuite) TestSelectPublicHostPort(c *gc.C) {
oldValue := network.GetPreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t0 := range selectPublicTests {
t := t0.hostPortTest()
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
c.Check(network.SelectPublicHostPort(t.hostPorts), jc.DeepEquals, t.expected())
}
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:hostport_test.go
示例5: TestSelectInternalAddress
func (s *AddressSuite) TestSelectInternalAddress(c *gc.C) {
oldValue := network.PreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t := range selectInternalTests {
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
expectAddr, expectOK := t.expected()
actualAddr, actualOK := network.SelectInternalAddress(t.addresses, false)
c.Check(actualOK, gc.Equals, expectOK)
c.Check(actualAddr, gc.Equals, expectAddr)
}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:address_test.go
示例6: TestInitializeFromConfig
func (*NetworkSuite) TestInitializeFromConfig(c *gc.C) {
c.Check(network.PreferIPv6(), jc.IsFalse)
envConfig := testing.CustomModelConfig(c, testing.Attrs{
"prefer-ipv6": true,
})
network.SetPreferIPv6(envConfig.PreferIPv6())
c.Check(network.PreferIPv6(), jc.IsTrue)
envConfig = testing.CustomModelConfig(c, testing.Attrs{
"prefer-ipv6": false,
})
network.SetPreferIPv6(envConfig.PreferIPv6())
c.Check(network.PreferIPv6(), jc.IsFalse)
}
开发者ID:pmatulis,项目名称:juju,代码行数:15,代码来源:network_test.go
示例7: TestExactScopeMatchHonoursPreferIPv6
func (*AddressSuite) TestExactScopeMatchHonoursPreferIPv6(c *gc.C) {
network.SetPreferIPv6(true)
addr := network.NewScopedAddress("10.0.0.2", network.ScopeCloudLocal)
match := network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsFalse)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsFalse)
addr = network.NewScopedAddress("8.8.8.8", network.ScopePublic)
match = network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsFalse)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsFalse)
addr = network.NewScopedAddress("2001:db8::ff00:42:8329", network.ScopePublic)
match = network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsFalse)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsTrue)
addr = network.NewScopedAddress("fc00::1", network.ScopeCloudLocal)
match = network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsTrue)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsFalse)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:26,代码来源:address_test.go
示例8: Run
// Run runs a unit agent.
func (a *UnitAgent) Run(ctx *cmd.Context) error {
defer a.tomb.Done()
if err := a.ReadConfig(a.Tag().String()); err != nil {
return err
}
agentConfig := a.CurrentConfig()
agentLogger.Infof("unit agent %v start (%s [%s])", a.Tag().String(), jujuversion.Current, runtime.Compiler)
if flags := featureflag.String(); flags != "" {
logger.Warningf("developer feature flags enabled: %s", flags)
}
network.SetPreferIPv6(agentConfig.PreferIPv6())
// Sometimes there are upgrade steps that are needed for each unit.
// There are plans afoot to unify the unit and machine agents. When
// this happens, there will be a simple helper function for the upgrade
// steps to run something for each unit on the machine. Until then, we
// need to have the uniter do it, as the overhead of getting a full
// upgrade process in the unit agent out weights the current benefits.
// So.. since the upgrade steps are all idempotent, we will just call
// the upgrade steps when we start the uniter. To be clear, these
// should move back to the upgrade package when we do unify the agents.
runUpgrades(agentConfig.Tag(), agentConfig.DataDir())
a.runner.StartWorker("api", a.APIWorkers)
err := cmdutil.AgentDone(logger, a.runner.Wait())
a.tomb.Kill(err)
return err
}
开发者ID:makyo,项目名称:juju,代码行数:30,代码来源:unit.go
示例9: SetUpTest
func (s *BaseSuite) SetUpTest(c *gc.C) {
s.CleanupSuite.SetUpTest(c)
s.LoggingSuite.SetUpTest(c)
s.JujuOSEnvSuite.SetUpTest(c)
// We do this to isolate invocations of bash from pulling in the
// ambient user environment, and potentially affecting the tests.
// We can't always just use IsolationSuite because we still need
// PATH and possibly a couple other envars.
s.PatchEnvironment("BASH_ENV", "")
network.SetPreferIPv6(false)
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:base.go
示例10: TestExactScopeMatch
func (*AddressSuite) TestExactScopeMatch(c *gc.C) {
network.SetPreferIPv6(false)
addr := network.NewScopedAddress("10.0.0.2", network.ScopeCloudLocal)
match := network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsTrue)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsFalse)
addr = network.NewScopedAddress("8.8.8.8", network.ScopePublic)
match = network.ExactScopeMatch(addr, network.ScopeCloudLocal)
c.Assert(match, jc.IsFalse)
match = network.ExactScopeMatch(addr, network.ScopePublic)
c.Assert(match, jc.IsTrue)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:address_test.go
示例11: Run
// Run initializes state for an environment.
func (c *BootstrapCommand) Run(_ *cmd.Context) error {
envCfg, err := config.New(config.NoDefaults, c.ControllerModelConfig)
if err != nil {
return err
}
err = c.ReadConfig("machine-0")
if err != nil {
return err
}
agentConfig := c.CurrentConfig()
network.SetPreferIPv6(agentConfig.PreferIPv6())
// agent.Jobs is an optional field in the agent config, and was
// introduced after 1.17.2. We default to allowing units on
// machine-0 if missing.
jobs := agentConfig.Jobs()
if len(jobs) == 0 {
jobs = []multiwatcher.MachineJob{
multiwatcher.JobManageModel,
multiwatcher.JobHostUnits,
multiwatcher.JobManageNetworking,
}
}
// Get the bootstrap machine's addresses from the provider.
env, err := environs.New(envCfg)
if err != nil {
return err
}
newConfigAttrs := make(map[string]interface{})
// Check to see if a newer agent version has been requested
// by the bootstrap client.
desiredVersion, ok := envCfg.AgentVersion()
if ok && desiredVersion != jujuversion.Current {
// If we have been asked for a newer version, ensure the newer
// tools can actually be found, or else bootstrap won't complete.
stream := envtools.PreferredStream(&desiredVersion, envCfg.Development(), envCfg.AgentStream())
logger.Infof("newer tools requested, looking for %v in stream %v", desiredVersion, stream)
filter := tools.Filter{
Number: desiredVersion,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
_, toolsErr := envtools.FindTools(env, -1, -1, stream, filter)
if toolsErr == nil {
logger.Infof("tools are available, upgrade will occur after bootstrap")
}
if errors.IsNotFound(toolsErr) {
// Newer tools not available, so revert to using the tools
// matching the current agent version.
logger.Warningf("newer tools for %q not available, sticking with version %q", desiredVersion, jujuversion.Current)
newConfigAttrs["agent-version"] = jujuversion.Current.String()
} else if toolsErr != nil {
logger.Errorf("cannot find newer tools: %v", toolsErr)
return toolsErr
}
}
instanceId := instance.Id(c.InstanceId)
instances, err := env.Instances([]instance.Id{instanceId})
if err != nil {
return err
}
addrs, err := instances[0].Addresses()
if err != nil {
return err
}
// When machine addresses are reported from state, they have
// duplicates removed. We should do the same here so that
// there is not unnecessary churn in the mongo replicaset.
// TODO (cherylj) Add explicit unit tests for this - tracked
// by bug #1544158.
addrs = network.MergedAddresses([]network.Address{}, addrs)
// Generate a private SSH key for the controllers, and add
// the public key to the environment config. We'll add the
// private key to StateServingInfo below.
privateKey, publicKey, err := sshGenerateKey(config.JujuSystemKey)
if err != nil {
return errors.Annotate(err, "failed to generate system key")
}
authorizedKeys := config.ConcatAuthKeys(envCfg.AuthorizedKeys(), publicKey)
newConfigAttrs[config.AuthKeysConfig] = authorizedKeys
// Generate a shared secret for the Mongo replica set, and write it out.
sharedSecret, err := mongo.GenerateSharedSecret()
if err != nil {
return err
}
info, ok := agentConfig.StateServingInfo()
if !ok {
return fmt.Errorf("bootstrap machine config has no state serving info")
}
info.SharedSecret = sharedSecret
info.SystemIdentity = privateKey
err = c.ChangeConfig(func(agentConfig agent.ConfigSetter) error {
agentConfig.SetStateServingInfo(info)
//.........这里部分代码省略.........
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:101,代码来源:bootstrap.go
示例12: Bootstrap
func (e *environ) Bootstrap(ctx environs.BootstrapContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) {
series := config.PreferredSeries(e.Config())
availableTools, err := args.AvailableTools.Match(coretools.Filter{Series: series})
if err != nil {
return nil, err
}
arch := availableTools.Arches()[0]
defer delay()
if err := e.checkBroken("Bootstrap"); err != nil {
return nil, err
}
network.SetPreferIPv6(e.Config().PreferIPv6())
password := e.Config().AdminSecret()
if password == "" {
return nil, fmt.Errorf("admin-secret is required for bootstrap")
}
if _, ok := e.Config().CACert(); !ok {
return nil, fmt.Errorf("no CA certificate in model configuration")
}
logger.Infof("would pick tools from %s", availableTools)
cfg, err := environs.BootstrapConfig(e.Config())
if err != nil {
return nil, fmt.Errorf("cannot make bootstrap config: %v", err)
}
estate, err := e.state()
if err != nil {
return nil, err
}
estate.mu.Lock()
defer estate.mu.Unlock()
if estate.bootstrapped {
return nil, fmt.Errorf("model is already bootstrapped")
}
estate.preferIPv6 = e.Config().PreferIPv6()
// Create an instance for the bootstrap node.
logger.Infof("creating bootstrap instance")
i := &dummyInstance{
id: BootstrapInstanceId,
addresses: network.NewAddresses("localhost"),
ports: make(map[network.PortRange]bool),
machineId: agent.BootstrapMachineId,
series: series,
firewallMode: e.Config().FirewallMode(),
state: estate,
controller: true,
}
estate.insts[i.id] = i
if e.ecfg().controller() {
// TODO(rog) factor out relevant code from cmd/jujud/bootstrap.go
// so that we can call it here.
info := stateInfo(estate.preferIPv6)
// Since the admin user isn't setup until after here,
// the password in the info structure is empty, so the admin
// user is constructed with an empty password here.
// It is set just below.
st, err := state.Initialize(
names.NewUserTag("[email protected]"), info, cfg,
mongotest.DialOpts(), estate.statePolicy)
if err != nil {
panic(err)
}
if err := st.SetModelConstraints(args.ModelConstraints); err != nil {
panic(err)
}
if err := st.SetAdminMongoPassword(password); err != nil {
panic(err)
}
if err := st.MongoSession().DB("admin").Login("admin", password); err != nil {
panic(err)
}
env, err := st.Model()
if err != nil {
panic(err)
}
owner, err := st.User(env.Owner())
if err != nil {
panic(err)
}
// We log this out for test purposes only. No one in real life can use
// a dummy provider for anything other than testing, so logging the password
// here is fine.
logger.Debugf("setting password for %q to %q", owner.Name(), password)
owner.SetPassword(password)
estate.apiStatePool = state.NewStatePool(st)
estate.apiServer, err = apiserver.NewServer(st, estate.apiListener, apiserver.ServerConfig{
Cert: []byte(testing.ServerCert),
Key: []byte(testing.ServerKey),
Tag: names.NewMachineTag("0"),
DataDir: DataDir,
LogDir: LogDir,
StatePool: estate.apiStatePool,
})
//.........这里部分代码省略.........
开发者ID:xushiwei,项目名称:juju,代码行数:101,代码来源:environs.go
注:本文中的github.com/juju/juju/network.SetPreferIPv6函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论