• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang instance.NewAddress函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/wallyworld/core/instance.NewAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAddress函数的具体用法?Golang NewAddress怎么用?Golang NewAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewAddress函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:jameinel,项目名称:core,代码行数:32,代码来源:machiner_test.go


示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:33,代码来源:environs_test.go


示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:lxc-broker_test.go


示例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
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:addresses_test.go


示例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",
	})
}
开发者ID:jameinel,项目名称:core,代码行数:34,代码来源:apiconn_test.go


示例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
}
开发者ID:jameinel,项目名称:core,代码行数:22,代码来源:utils.go


示例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), "")
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:machineconfig_test.go


示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:machiner.go


示例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"})
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:apiconn_test.go


示例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()
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:apiaddresser.go


示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:32,代码来源:deployer_test.go


示例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
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:environs.go


示例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
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:state.go


示例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
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:bootstrap_test.go


示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:provisioner_test.go


示例16: expectedAPIHostPorts

// expectedAPIHostPorts returns the expected addresses
// of the machines as created by initState.
func expectedAPIHostPorts(n int) [][]instance.HostPort {
	servers := make([][]instance.HostPort, n)
	for i := range servers {
		servers[i] = []instance.HostPort{{
			Address: instance.NewAddress(fmt.Sprintf("0.1.2.%d", i+10), instance.NetworkUnknown),
			Port:    apiPort,
		}}
	}
	return servers
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:worker_test.go


示例17: TestSetMachineAddresses

func (s *machinerSuite) TestSetMachineAddresses(c *gc.C) {
	machine, err := s.machiner.Machine("machine-1")
	c.Assert(err, gc.IsNil)

	addr := s.machine.Addresses()
	c.Assert(addr, gc.HasLen, 0)

	addresses := []instance.Address{
		instance.NewAddress("127.0.0.1", instance.NetworkUnknown),
		instance.NewAddress("10.0.0.1", instance.NetworkUnknown),
		instance.NewAddress("8.8.8.8", instance.NetworkUnknown),
	}
	err = machine.SetMachineAddresses(addresses)
	c.Assert(err, gc.IsNil)

	err = s.machine.Refresh()
	c.Assert(err, gc.IsNil)
	c.Assert(s.machine.MachineAddresses(), gc.DeepEquals, addresses)
}
开发者ID:jameinel,项目名称:core,代码行数:19,代码来源:machiner_test.go


示例18: TestPrivateAddress

func (s *UnitSuite) TestPrivateAddress(c *gc.C) {
	machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
	c.Assert(err, gc.IsNil)
	err = s.unit.AssignToMachine(machine)
	c.Assert(err, gc.IsNil)

	address, ok := s.unit.PrivateAddress()
	c.Check(address, gc.Equals, "")
	c.Assert(ok, gc.Equals, false)

	public := instance.NewAddress("8.8.8.8", instance.NetworkPublic)
	private := instance.NewAddress("127.0.0.1", instance.NetworkCloudLocal)

	err = machine.SetAddresses(public, private)
	c.Assert(err, gc.IsNil)

	address, ok = s.unit.PrivateAddress()
	c.Check(address, gc.Equals, "127.0.0.1")
	c.Assert(ok, gc.Equals, true)
}
开发者ID:jameinel,项目名称:core,代码行数:20,代码来源:unit_test.go


示例19: TestPrivateAddress

func (s *unitSuite) TestPrivateAddress(c *gc.C) {
	address, err := s.apiUnit.PrivateAddress()
	c.Assert(err, gc.ErrorMatches, `"unit-wordpress-0" has no private address set`)

	err = s.wordpressMachine.SetAddresses(instance.NewAddress("1.2.3.4", instance.NetworkCloudLocal))
	c.Assert(err, gc.IsNil)

	address, err = s.apiUnit.PrivateAddress()
	c.Assert(err, gc.IsNil)
	c.Assert(address, gc.Equals, "1.2.3.4")
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:unit_test.go


示例20: TestStateAddresses

func (s *provisionerSuite) TestStateAddresses(c *gc.C) {
	err := s.machine.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown))
	c.Assert(err, gc.IsNil)

	stateAddresses, err := s.State.Addresses()
	c.Assert(err, gc.IsNil)

	addresses, err := s.provisioner.StateAddresses()
	c.Assert(err, gc.IsNil)
	c.Assert(addresses, gc.DeepEquals, stateAddresses)
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:provisioner_test.go



注:本文中的github.com/wallyworld/core/instance.NewAddress函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang instance.Instance类代码示例发布时间:2022-05-28
下一篇:
Golang instance.Id函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap