本文整理汇总了Golang中github.com/wallyworld/core/instance.NewAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAddress函数的具体用法?Golang NewAddress怎么用?Golang NewAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSetMachineAddresses
func (s *machinerSuite) TestSetMachineAddresses(c *gc.C) {
c.Assert(s.machine0.Addresses(), gc.HasLen, 0)
c.Assert(s.machine1.Addresses(), gc.HasLen, 0)
addresses := []instance.Address{
instance.NewAddress("127.0.0.1", instance.NetworkUnknown),
instance.NewAddress("8.8.8.8", instance.NetworkUnknown),
}
args := params.SetMachinesAddresses{MachineAddresses: []params.MachineAddresses{
{Tag: "machine-1", Addresses: addresses},
{Tag: "machine-0", Addresses: addresses},
{Tag: "machine-42", Addresses: addresses},
}}
result, err := s.machiner.SetMachineAddresses(args)
c.Assert(err, gc.IsNil)
c.Assert(result, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{nil},
{apiservertesting.ErrUnauthorized},
{apiservertesting.ErrUnauthorized},
},
})
err = s.machine1.Refresh()
c.Assert(err, gc.IsNil)
c.Assert(s.machine1.MachineAddresses(), gc.DeepEquals, addresses)
err = s.machine0.Refresh()
c.Assert(err, gc.IsNil)
c.Assert(s.machine0.MachineAddresses(), gc.HasLen, 0)
}
示例2: TestAllocateAddress
func (s *suite) TestAllocateAddress(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig)
c.Assert(err, gc.IsNil)
e, err := environs.Prepare(cfg, testing.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", s.TestConfig))
c.Assert(e, gc.NotNil)
envtesting.UploadFakeTools(c, e.Storage())
err = bootstrap.EnsureNotBootstrapped(e)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(testing.Context(c), e, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, e, "0")
c.Assert(inst, gc.NotNil)
netId := network.Id("net1")
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
expectAddress := instance.NewAddress("0.1.2.1", instance.NetworkCloudLocal)
address, err := e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
expectAddress = instance.NewAddress("0.1.2.2", instance.NetworkCloudLocal)
address, err = e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
}
示例3: SetUpTest
func (s *lxcProvisionerSuite) SetUpTest(c *gc.C) {
s.CommonProvisionerSuite.SetUpTest(c)
s.lxcSuite.SetUpTest(c)
// The lxc provisioner actually needs the machine it is being created on
// to be in state, in order to get the watcher.
m, err := s.State.AddMachine(coretesting.FakeDefaultSeries, state.JobHostUnits, state.JobManageEnviron)
c.Assert(err, gc.IsNil)
err = m.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown))
c.Assert(err, gc.IsNil)
hostPorts := [][]instance.HostPort{{{
Address: instance.NewAddress("0.1.2.3", instance.NetworkUnknown),
Port: 1234,
}}}
err = s.State.SetAPIHostPorts(hostPorts)
c.Assert(err, gc.IsNil)
c.Assert(err, gc.IsNil)
s.parentMachineId = m.Id()
s.APILogin(c, m)
err = m.SetAgentVersion(version.Current)
c.Assert(err, gc.IsNil)
s.events = make(chan mock.Event, 25)
s.Factory.AddListener(s.events)
}
示例4: APIHostPorts
func (fakeAddresses) APIHostPorts() ([][]instance.HostPort, error) {
return [][]instance.HostPort{{{
Address: instance.NewAddress("apiaddresses", instance.NetworkUnknown),
Port: 1,
}}, {{
Address: instance.NewAddress("apiaddresses", instance.NetworkUnknown),
Port: 2,
}}}, nil
}
示例5: TestAPIEndpointNotMachineLocal
func (s *APIEndpointForEnvSuite) TestAPIEndpointNotMachineLocal(c *gc.C) {
defer coretesting.MakeEmptyFakeHome(c).Restore()
store := newConfigStore("env-name", dummyStoreInfo)
called := 0
hostPorts := [][]instance.HostPort{
instance.AddressesWithPort([]instance.Address{
instance.NewAddress("1.0.0.1", instance.NetworkPublic),
instance.NewAddress("192.0.0.1", instance.NetworkCloudLocal),
instance.NewAddress("127.0.0.1", instance.NetworkMachineLocal),
instance.NewAddress("localhost", instance.NetworkMachineLocal),
}, 1234),
instance.AddressesWithPort([]instance.Address{
instance.NewAddress("1.0.0.2", instance.NetworkUnknown),
instance.NewAddress("2002:0:0:0:0:0:100:2", instance.NetworkUnknown),
instance.NewAddress("::1", instance.NetworkMachineLocal),
instance.NewAddress("127.0.0.1", instance.NetworkMachineLocal),
instance.NewAddress("localhost", instance.NetworkMachineLocal),
}, 1235),
}
expectState := &mockAPIState{apiHostPorts: hostPorts}
apiOpen := func(_ *api.Info, _ api.DialOpts) (juju.APIState, error) {
called++
return expectState, nil
}
endpoint, err := juju.APIEndpointInStore("env-name", true, store, apiOpen)
c.Assert(err, gc.IsNil)
c.Check(called, gc.Equals, 1)
c.Check(endpoint.Addresses, gc.DeepEquals, []string{
"1.0.0.1:1234",
"192.0.0.1:1234",
"1.0.0.2:1235",
})
}
示例6: AddStateServerMachine
// AddStateServerMachine adds a "state server" machine to the state so
// that State.Addresses and State.APIAddresses will work. It returns the
// added machine. The addresses that those methods will return bear no
// relation to the addresses actually used by the state and API servers.
// It returns the addresses that will be returned by the State.Addresses
// and State.APIAddresses methods, which will not bear any relation to
// the be the addresses used by the state servers.
func AddStateServerMachine(c *gc.C, st *state.State) *state.Machine {
machine, err := st.AddMachine("quantal", state.JobManageEnviron)
c.Assert(err, gc.IsNil)
err = machine.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown))
c.Assert(err, gc.IsNil)
hostPorts := [][]instance.HostPort{{{
Address: instance.NewAddress("0.1.2.3", instance.NetworkUnknown),
Port: 1234,
}}}
err = st.SetAPIHostPorts(hostPorts)
c.Assert(err, gc.IsNil)
return machine
}
示例7: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := []instance.Address{instance.NewAddress("1.2.3.4", instance.NetworkUnknown)}
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: addrs,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, gc.IsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, gc.IsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
env, err := environs.New(envConfig)
c.Assert(err, gc.IsNil)
stateInfo, apiInfo, err := env.StateInfo()
c.Assert(err, gc.IsNil)
c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs)
c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "")
}
示例8: setMachineAddresses
// setMachineAddresses sets the addresses for this machine to all of the
// host's non-loopback interface IP addresses.
func setMachineAddresses(m *machiner.Machine) error {
addrs, err := interfaceAddrs()
if err != nil {
return err
}
var hostAddresses []instance.Address
for _, addr := range addrs {
var ip net.IP
switch addr := addr.(type) {
case *net.IPAddr:
ip = addr.IP
case *net.IPNet:
ip = addr.IP
default:
continue
}
address := instance.NewAddress(ip.String(), instance.NetworkUnknown)
hostAddresses = append(hostAddresses, address)
}
if len(hostAddresses) == 0 {
return nil
}
logger.Infof("setting addresses for %v to %q", m.Tag(), hostAddresses)
return m.SetMachineAddresses(hostAddresses)
}
示例9: TestAPIEndpointRefresh
func (s *APIEndpointForEnvSuite) TestAPIEndpointRefresh(c *gc.C) {
defer coretesting.MakeEmptyFakeHome(c).Restore()
store := newConfigStore("env-name", dummyStoreInfo)
called := 0
expectState := &mockAPIState{
apiHostPorts: [][]instance.HostPort{
instance.AddressesWithPort([]instance.Address{instance.NewAddress("0.1.2.3", instance.NetworkUnknown)}, 1234),
},
}
apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) {
c.Check(apiInfo.Tag, gc.Equals, "user-foo")
c.Check(string(apiInfo.CACert), gc.Equals, "certificated")
c.Check(apiInfo.Password, gc.Equals, "foopass")
c.Check(opts, gc.DeepEquals, api.DefaultDialOpts())
called++
return expectState, nil
}
endpoint, err := juju.APIEndpointInStore("env-name", false, store, apiOpen)
c.Assert(err, gc.IsNil)
c.Assert(called, gc.Equals, 0)
c.Check(endpoint.Addresses, gc.DeepEquals, []string{"foo.invalid"})
// However, if we ask to refresh them, we'll connect to the API and get
// the freshest set
endpoint, err = juju.APIEndpointInStore("env-name", true, store, apiOpen)
c.Assert(err, gc.IsNil)
c.Check(called, gc.Equals, 1)
// This refresh now gives us the values return by APIHostPorts
c.Check(endpoint.Addresses, gc.DeepEquals, []string{"0.1.2.3:1234"})
}
示例10: TestWatchAPIHostPorts
func (s *APIAddresserTests) TestWatchAPIHostPorts(c *gc.C) {
expectServerAddrs := [][]instance.HostPort{{{
Address: instance.NewAddress("0.1.2.3", instance.NetworkUnknown),
Port: 1234,
}}}
err := s.state.SetAPIHostPorts(expectServerAddrs)
c.Assert(err, gc.IsNil)
w, err := s.facade.WatchAPIHostPorts()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewNotifyWatcherC(c, s.state, w)
// Initial event.
wc.AssertOneChange()
// Change the state addresses and check that we get a notification
expectServerAddrs[0][0].Value = "0.1.99.99"
err = s.state.SetAPIHostPorts(expectServerAddrs)
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例11: SetUpTest
func (s *deployerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.stateAPI, s.machine = s.OpenAPIAsNewMachine(c, state.JobManageEnviron, state.JobHostUnits)
err := s.machine.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown))
c.Assert(err, gc.IsNil)
// Create the needed services and relate them.
s.service0 = s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
s.service1 = s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
eps, err := s.State.InferEndpoints([]string{"mysql", "logging"})
c.Assert(err, gc.IsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, gc.IsNil)
// Create principal and subordinate units and assign them.
s.principal, err = s.service0.AddUnit()
c.Assert(err, gc.IsNil)
err = s.principal.AssignToMachine(s.machine)
c.Assert(err, gc.IsNil)
relUnit, err := rel.Unit(s.principal)
c.Assert(err, gc.IsNil)
err = relUnit.EnterScope(nil)
c.Assert(err, gc.IsNil)
s.subordinate, err = s.service1.Unit("logging/0")
c.Assert(err, gc.IsNil)
// Create the deployer facade.
s.st = s.stateAPI.Deployer()
c.Assert(s.st, gc.NotNil)
s.APIAddresserTests = apitesting.NewAPIAddresserTests(s.st, s.BackingState)
}
示例12: AllocateAddress
// AllocateAddress requests a new address to be allocated for the
// given instance on the given network.
func (env *environ) AllocateAddress(instId instance.Id, netId network.Id) (instance.Address, error) {
if err := env.checkBroken("AllocateAddress"); err != nil {
return instance.Address{}, err
}
estate, err := env.state()
if err != nil {
return instance.Address{}, err
}
estate.mu.Lock()
defer estate.mu.Unlock()
estate.maxAddr++
// TODO(dimitern) Once we have integrated networks
// and addresses, make sure we return a valid address
// for the given network, and we also have the network
// already registered.
newAddress := instance.NewAddress(
fmt.Sprintf("0.1.2.%d", estate.maxAddr),
instance.NetworkCloudLocal,
)
estate.ops <- OpAllocateAddress{
Env: env.name,
InstanceId: instId,
NetworkId: netId,
Address: newAddress,
}
return newAddress, nil
}
示例13: addAddress
// addAddress appends a new server derived from the given
// address to servers if the address is not already found
// there.
func addAddress(servers [][]instance.HostPort, addr string) ([][]instance.HostPort, error) {
for i, server := range servers {
for j, hostPort := range server {
if hostPort.NetAddr() == addr {
slideAddressToFront(servers, i, j)
return servers, nil
}
}
}
host, portString, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(portString)
if err != nil {
return nil, err
}
hostPort := instance.HostPort{
Address: instance.NewAddress(host, instance.NetworkUnknown),
Port: port,
}
result := make([][]instance.HostPort, 0, len(servers)+1)
result = append(result, []instance.HostPort{hostPort})
result = append(result, servers...)
return result, nil
}
示例14: Addresses
func (ac *addressesChange) Addresses() ([]instance.Address, error) {
var addrs []instance.Address
for _, addr := range ac.addrs[0] {
addrs = append(addrs, instance.NewAddress(addr, instance.NetworkUnknown))
}
return addrs, nil
}
示例15: setupEnvironmentManager
// setupEnvironmentManager adds an environment manager machine and login to the API.
func (s *CommonProvisionerSuite) setupEnvironmentManager(c *gc.C) {
machine, err := s.State.AddMachine("quantal", state.JobManageEnviron)
c.Assert(err, gc.IsNil)
c.Assert(machine.Id(), gc.Equals, "0")
err = machine.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown))
c.Assert(err, gc.IsNil)
s.APILogin(c, machine)
}