本文整理汇总了Golang中github.com/juju/juju/network.SelectPublicAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang SelectPublicAddress函数的具体用法?Golang SelectPublicAddress怎么用?Golang SelectPublicAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SelectPublicAddress函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PublicAddress
// PublicAddress implements the server side of Client.PublicAddress.
func (c *Client) PublicAddress(p params.PublicAddress) (results params.PublicAddressResults, err error) {
switch {
case names.IsValidMachine(p.Target):
machine, err := c.api.state.Machine(p.Target)
if err != nil {
return results, err
}
addr := network.SelectPublicAddress(machine.Addresses())
if addr == "" {
return results, fmt.Errorf("machine %q has no public address", machine)
}
return params.PublicAddressResults{PublicAddress: addr}, nil
case names.IsValidUnit(p.Target):
unit, err := c.api.state.Unit(p.Target)
if err != nil {
return results, err
}
addr, ok := unit.PublicAddress()
if !ok {
return results, fmt.Errorf("unit %q has no public address", unit)
}
return params.PublicAddressResults{PublicAddress: addr}, nil
}
return results, fmt.Errorf("unknown unit or machine %q", p.Target)
}
示例2: makeTestEnv
func (s *BootstrapSuite) makeTestEnv(c *gc.C) {
attrs := dummy.SampleConfig().Merge(
testing.Attrs{
"agent-version": version.Current.Number.String(),
"bootstrap-timeout": "123",
},
).Delete("admin-secret", "ca-private-key")
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
provider, err := environs.Provider(cfg.Type())
c.Assert(err, jc.ErrorIsNil)
env, err := provider.PrepareForBootstrap(nullContext(), cfg)
c.Assert(err, jc.ErrorIsNil)
envtesting.MustUploadFakeTools(s.toolsStorage, cfg.AgentStream(), cfg.AgentStream())
inst, _, _, err := jujutesting.StartInstance(env, "0")
c.Assert(err, jc.ErrorIsNil)
s.instanceId = inst.Id()
addresses, err := inst.Addresses()
c.Assert(err, jc.ErrorIsNil)
s.bootstrapName = network.SelectPublicAddress(addresses)
s.envcfg = env.Config()
s.b64yamlEnvcfg = b64yaml(s.envcfg.AllAttrs()).encode()
}
示例3: machineDocForTemplate
func (st *State) machineDocForTemplate(template MachineTemplate, id string) *machineDoc {
// We ignore the error from Select*Address as an error indicates
// no address is available, in which case the empty address is returned
// and setting the preferred address to an empty one is the correct
// thing to do when none is available.
privateAddr, _ := network.SelectInternalAddress(template.Addresses, false)
publicAddr, _ := network.SelectPublicAddress(template.Addresses)
logger.Infof(
"new machine %q has preferred addresses: private %q, public %q",
id, privateAddr, publicAddr,
)
return &machineDoc{
DocID: st.docID(id),
Id: id,
ModelUUID: st.ModelUUID(),
Series: template.Series,
Jobs: template.Jobs,
Clean: !template.Dirty,
Principals: template.principals,
Life: Alive,
Nonce: template.Nonce,
Addresses: fromNetworkAddresses(template.Addresses, OriginMachine),
PreferredPrivateAddress: fromNetworkAddress(privateAddr, OriginMachine),
PreferredPublicAddress: fromNetworkAddress(publicAddr, OriginMachine),
NoVote: template.NoVote,
Placement: template.Placement,
}
}
示例4: runMachineUpdate
// runMachineUpdate connects via ssh to the machine and runs the update script.
func runMachineUpdate(allAddr []network.Address, sshArg string) error {
addr := network.SelectPublicAddress(allAddr)
if addr == "" {
return errors.Errorf("no appropriate public address found")
}
return runViaSSH(addr, sshArg)
}
示例5: Restore
// Restore implements the server side of Backups.Restore.
func (a *API) Restore(p params.RestoreArgs) error {
// Get hold of a backup file Reader
backup, closer := newBackups(a.st)
defer closer.Close()
// Obtain the address of current machine, where we will be performing restore.
machine, err := a.st.Machine(a.machineID)
if err != nil {
return errors.Trace(err)
}
addr := network.SelectInternalAddress(machine.Addresses(), false)
if addr == "" {
return errors.Errorf("machine %q has no internal address", machine)
}
publicAddress := network.SelectPublicAddress(machine.Addresses())
if publicAddress == "" {
return errors.Errorf("machine %q has no public address", machine)
}
info, err := a.st.RestoreInfoSetter()
if err != nil {
return errors.Trace(err)
}
// Signal to current state and api server that restore will begin
err = info.SetStatus(state.RestoreInProgress)
if err != nil {
return errors.Annotatef(err, "cannot set the server to %q mode", state.RestoreInProgress)
}
// Any abnormal termination of this function will mark restore as failed,
// succesful termination will call Exit and never run this.
defer info.SetStatus(state.RestoreFailed)
instanceId, err := machine.InstanceId()
if err != nil {
return errors.Annotate(err, "cannot obtain instance id for machine to be restored")
}
logger.Infof("beginning server side restore of backup %q", p.BackupId)
// Restore
restoreArgs := backups.RestoreArgs{
PrivateAddress: addr,
PublicAddress: publicAddress,
NewInstId: instanceId,
NewInstTag: machine.Tag(),
NewInstSeries: machine.Series(),
}
if err := backup.Restore(p.BackupId, restoreArgs); err != nil {
return errors.Annotate(err, "restore failed")
}
// After restoring, the api server needs a forced restart, tomb will not work
// this is because we change all of juju configuration files and mongo too.
// Exiting with 0 would prevent upstart to respawn the process
os.Exit(1)
return nil
}
示例6: TestSelectPublicAddress
func (s *AddressSuite) TestSelectPublicAddress(c *gc.C) {
for i, t := range selectPublicTests {
c.Logf("test %d: %s", i, t.about)
expectAddr, expectOK := t.expected()
actualAddr, actualOK := network.SelectPublicAddress(t.addresses)
c.Check(actualOK, gc.Equals, expectOK)
c.Check(actualAddr, gc.Equals, expectAddr)
}
}
示例7: TestSelectPublicAddress
func (s *AddressSuite) TestSelectPublicAddress(c *gc.C) {
oldValue := network.GetPreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t := range selectPublicTests {
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
c.Check(network.SelectPublicAddress(t.addresses), gc.Equals, t.expected())
}
}
示例8: TestSelectPublicAddress
func (s *AddressSuite) TestSelectPublicAddress(c *gc.C) {
oldValue := network.PreferIPv6()
defer func() {
network.SetPreferIPv6(oldValue)
}()
for i, t := range selectPublicTests {
c.Logf("test %d: %s", i, t.about)
network.SetPreferIPv6(t.preferIPv6)
expectAddr, expectOK := t.expected()
actualAddr, actualOK := network.SelectPublicAddress(t.addresses)
c.Check(actualOK, gc.Equals, expectOK)
c.Check(actualAddr, gc.Equals, expectAddr)
}
}
示例9: makeMachineStatus
func makeMachineStatus(machine *state.Machine) (status api.MachineStatus) {
status.Id = machine.Id()
agentStatus, compatStatus := processMachine(machine)
status.Agent = agentStatus
// These legacy status values will be deprecated for Juju 2.0.
status.AgentState = compatStatus.Status
status.AgentStateInfo = compatStatus.Info
status.AgentVersion = compatStatus.Version
status.Life = compatStatus.Life
status.Err = compatStatus.Err
status.Series = machine.Series()
status.Jobs = paramsJobsFromJobs(machine.Jobs())
status.WantsVote = machine.WantsVote()
status.HasVote = machine.HasVote()
instid, err := machine.InstanceId()
if err == nil {
status.InstanceId = instid
status.InstanceState, err = machine.InstanceStatus()
if err != nil {
status.InstanceState = "error"
}
status.DNSName = network.SelectPublicAddress(machine.Addresses())
} else {
if errors.IsNotProvisioned(err) {
status.InstanceId = "pending"
} else {
status.InstanceId = "error"
}
// There's no point in reporting a pending agent state
// if the machine hasn't been provisioned. This
// also makes unprovisioned machines visually distinct
// in the output.
status.AgentState = ""
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
if !errors.IsNotFound(err) {
status.Hardware = "error"
}
} else {
status.Hardware = hc.String()
}
status.Containers = make(map[string]api.MachineStatus)
return
}
示例10: InstanceAddress
func InstanceAddress(publicIP string, addresses map[string][]nova.IPAddress) string {
return network.SelectPublicAddress(convertNovaAddresses(publicIP, addresses))
}