本文整理汇总了Golang中github.com/juju/juju/network.NewScopedAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang NewScopedAddress函数的具体用法?Golang NewScopedAddress怎么用?Golang NewScopedAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewScopedAddress函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Addresses
// Addresses is specified in the Instance interface.
func (inst *azureInstance) Addresses() ([]jujunetwork.Address, error) {
addresses := make([]jujunetwork.Address, 0, len(inst.networkInterfaces)+len(inst.publicIPAddresses))
for _, nic := range inst.networkInterfaces {
if nic.Properties.IPConfigurations == nil {
continue
}
for _, ipConfiguration := range *nic.Properties.IPConfigurations {
privateIpAddress := ipConfiguration.Properties.PrivateIPAddress
if privateIpAddress == nil {
continue
}
addresses = append(addresses, jujunetwork.NewScopedAddress(
to.String(privateIpAddress),
jujunetwork.ScopeCloudLocal,
))
}
}
for _, pip := range inst.publicIPAddresses {
if pip.Properties.IPAddress == nil {
continue
}
addresses = append(addresses, jujunetwork.NewScopedAddress(
to.String(pip.Properties.IPAddress),
jujunetwork.ScopePublic,
))
}
return addresses, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:29,代码来源:instance.go
示例2: convertNovaAddresses
// convertNovaAddresses returns nova addresses in generic format
func convertNovaAddresses(publicIP string, addresses map[string][]nova.IPAddress) []network.Address {
var machineAddresses []network.Address
if publicIP != "" {
publicAddr := network.NewScopedAddress(publicIP, network.ScopePublic)
machineAddresses = append(machineAddresses, publicAddr)
}
// TODO(gz) Network ordering may be significant but is not preserved by
// the map, see lp:1188126 for example. That could potentially be fixed
// in goose, or left to be derived by other means.
for netName, ips := range addresses {
networkScope := network.ScopeUnknown
if netName == "public" {
networkScope = network.ScopePublic
}
for _, address := range ips {
// If this address has already been added as a floating IP, skip it.
if publicIP == address.Address {
continue
}
// Assume IPv4 unless specified otherwise
addrtype := network.IPv4Address
if address.Version == 6 {
addrtype = network.IPv6Address
}
machineAddr := network.NewScopedAddress(address.Address, networkScope)
if machineAddr.Type != addrtype {
logger.Warningf("derived address type %v, nova reports %v", machineAddr.Type, addrtype)
}
machineAddresses = append(machineAddresses, machineAddr)
}
}
return machineAddresses
}
开发者ID:makyo,项目名称:juju,代码行数:34,代码来源:provider.go
示例3: 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
示例4: TestMachineAddresses
func (s *MachinerStateSuite) TestMachineAddresses(c *gc.C) {
s.setupSetMachineAddresses(c, false)
c.Assert(s.machine.MachineAddresses(), jc.DeepEquals, []network.Address{
network.NewAddress("2001:db8::1"),
network.NewScopedAddress("10.0.0.1", network.ScopeCloudLocal),
network.NewScopedAddress("::1", network.ScopeMachineLocal),
network.NewScopedAddress("127.0.0.1", network.ScopeMachineLocal),
})
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:9,代码来源:machiner_test.go
示例5: TestNewScopedAddressHostname
func (s *AddressSuite) TestNewScopedAddressHostname(c *gc.C) {
addr := network.NewScopedAddress("localhost", network.ScopeUnknown)
c.Check(addr.Value, gc.Equals, "localhost")
c.Check(addr.Type, gc.Equals, network.HostName)
c.Check(addr.Scope, gc.Equals, network.ScopeUnknown)
addr = network.NewScopedAddress("example.com", network.ScopeUnknown)
c.Check(addr.Value, gc.Equals, "example.com")
c.Check(addr.Type, gc.Equals, network.HostName)
c.Check(addr.Scope, gc.Equals, network.ScopeUnknown)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:10,代码来源:address_test.go
示例6: setAddresses
func (s *SSHCommonSuite) setAddresses(c *gc.C, m *state.Machine) {
addrPub := network.NewScopedAddress(
fmt.Sprintf("%s.public", m.Id()),
network.ScopePublic,
)
addrPriv := network.NewScopedAddress(
fmt.Sprintf("%s.private", m.Id()),
network.ScopeCloudLocal,
)
err := m.SetProviderAddresses(addrPub, addrPriv)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:ssh_common_test.go
示例7: TestNewAddressIPv6
func (s *AddressSuite) TestNewAddressIPv6(c *gc.C) {
value := "2001:db8::1"
addr1 := network.NewScopedAddress(value, network.ScopeUnknown)
addr2 := network.NewAddress(value)
addr3 := network.NewScopedAddress(value, network.ScopeLinkLocal)
// NewAddress behaves exactly like NewScopedAddress with ScopeUnknown
c.Assert(addr1, jc.DeepEquals, addr2)
c.Assert(addr2.Scope, gc.Equals, network.ScopePublic) // derived from value
c.Assert(addr2.Value, gc.Equals, value)
c.Assert(addr2.Type, gc.Equals, network.IPv6Address)
c.Assert(addr2.Scope, gc.Not(gc.Equals), addr3.Scope) // different scope
c.Assert(addr3.Scope, gc.Equals, network.ScopeLinkLocal)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:13,代码来源:address_test.go
示例8: TestExactScopeMatch
func (*AddressSuite) TestExactScopeMatch(c *gc.C) {
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:bac,项目名称:juju,代码行数:13,代码来源:address_test.go
示例9: TestNetworkInterfacesLegacy
func (suite *environSuite) TestNetworkInterfacesLegacy(c *gc.C) {
testInstance := suite.createSubnets(c, false)
netInfo, err := suite.makeEnviron().NetworkInterfaces(testInstance.Id())
c.Assert(err, jc.ErrorIsNil)
expectedInfo := []network.InterfaceInfo{{
DeviceIndex: 0,
MACAddress: "aa:bb:cc:dd:ee:ff",
CIDR: "192.168.1.2/24",
ProviderSubnetId: "WLAN",
VLANTag: 0,
InterfaceName: "wlan0",
Disabled: true,
NoAutoStart: true,
ConfigType: network.ConfigDHCP,
ExtraConfig: nil,
GatewayAddress: network.Address{},
Address: network.NewScopedAddress("192.168.1.2", network.ScopeCloudLocal),
}, {
DeviceIndex: 1,
MACAddress: "aa:bb:cc:dd:ee:f1",
CIDR: "192.168.2.2/24",
ProviderSubnetId: "LAN",
VLANTag: 42,
InterfaceName: "eth0",
Disabled: false,
NoAutoStart: false,
ConfigType: network.ConfigDHCP,
ExtraConfig: nil,
GatewayAddress: network.NewScopedAddress("192.168.2.1", network.ScopeCloudLocal),
Address: network.NewScopedAddress("192.168.2.2", network.ScopeCloudLocal),
}, {
DeviceIndex: 2,
MACAddress: "aa:bb:cc:dd:ee:f2",
CIDR: "192.168.3.2/24",
ProviderSubnetId: "Virt",
VLANTag: 0,
InterfaceName: "vnet1",
Disabled: false,
NoAutoStart: false,
ConfigType: network.ConfigDHCP,
ExtraConfig: nil,
GatewayAddress: network.Address{},
Address: network.NewScopedAddress("192.168.3.2", network.ScopeCloudLocal),
}}
network.SortInterfaceInfo(netInfo)
c.Assert(netInfo, jc.DeepEquals, expectedInfo)
}
开发者ID:OSBI,项目名称:juju,代码行数:49,代码来源:interfaces_test.go
示例10: GetNetworkInterfaces
func (c *client) GetNetworkInterfaces(inst instance.Id, ecfg *environConfig) ([]network.InterfaceInfo, error) {
vm, err := c.getVm(string(inst))
if err != nil {
return nil, errors.Trace(err)
}
if vm.Guest == nil {
return nil, errors.Errorf("vm guest is not initialized")
}
res := make([]network.InterfaceInfo, 0)
for _, net := range vm.Guest.Net {
ipScope := network.ScopeCloudLocal
if net.Network == ecfg.externalNetwork() {
ipScope = network.ScopePublic
}
res = append(res, network.InterfaceInfo{
DeviceIndex: net.DeviceConfigId,
MACAddress: net.MacAddress,
NetworkName: net.Network,
Disabled: !net.Connected,
ProviderId: network.Id(fmt.Sprintf("net-device%d", net.DeviceConfigId)),
ProviderSubnetId: network.Id(net.Network),
InterfaceName: fmt.Sprintf("unsupported%d", net.DeviceConfigId),
ConfigType: network.ConfigDHCP,
Address: network.NewScopedAddress(net.IpAddress[0], ipScope),
})
}
return res, nil
}
开发者ID:exekias,项目名称:juju,代码行数:28,代码来源:client.go
示例11: TestAllocateTo
func (s *IPAddressSuite) TestAllocateTo(c *gc.C) {
machine := s.createMachine(c)
addr := network.NewScopedAddress("0.1.2.3", network.ScopePublic)
ipAddr, err := s.State.AddIPAddress(addr, "foobar")
c.Assert(err, jc.ErrorIsNil)
c.Assert(ipAddr.State(), gc.Equals, state.AddressStateUnknown)
c.Assert(ipAddr.MachineId(), gc.Equals, "")
c.Assert(ipAddr.InterfaceId(), gc.Equals, "")
c.Assert(ipAddr.InstanceId(), gc.Equals, instance.UnknownId)
err = ipAddr.AllocateTo(machine.Id(), "wobble")
c.Assert(err, jc.ErrorIsNil)
c.Assert(ipAddr.State(), gc.Equals, state.AddressStateAllocated)
c.Assert(ipAddr.MachineId(), gc.Equals, machine.Id())
c.Assert(ipAddr.InterfaceId(), gc.Equals, "wobble")
c.Assert(ipAddr.InstanceId(), gc.Equals, instance.Id("foo"))
freshCopy, err := s.State.IPAddress("0.1.2.3")
c.Assert(err, jc.ErrorIsNil)
c.Assert(freshCopy.State(), gc.Equals, state.AddressStateAllocated)
c.Assert(freshCopy.MachineId(), gc.Equals, machine.Id())
c.Assert(freshCopy.InterfaceId(), gc.Equals, "wobble")
c.Assert(freshCopy.InstanceId(), gc.Equals, instance.Id("foo"))
// allocating twice should fail.
machine2 := s.createMachine(c)
err = ipAddr.AllocateTo(machine2.Id(), "i")
msg := fmt.Sprintf(
`cannot allocate IP address "public:0.1.2.3" to machine %q, interface "i": `+
`already allocated or unavailable`, machine2.Id())
c.Assert(err, gc.ErrorMatches, msg)
}
开发者ID:Pankov404,项目名称:juju,代码行数:34,代码来源:ipaddresses_test.go
示例12: TestEnsureDeadRemove
func (s *IPAddressSuite) TestEnsureDeadRemove(c *gc.C) {
addr := network.NewScopedAddress("0.1.2.3", network.ScopePublic)
ipAddr, err := s.State.AddIPAddress(addr, "foobar")
c.Assert(err, jc.ErrorIsNil)
// Should not be able to remove an Alive IP address.
c.Assert(ipAddr.Life(), gc.Equals, state.Alive)
err = ipAddr.Remove()
msg := fmt.Sprintf("cannot remove IP address %q: IP address is not dead", ipAddr.String())
c.Assert(err, gc.ErrorMatches, msg)
err = ipAddr.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
// EnsureDead twice should not be an error
err = ipAddr.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
err = ipAddr.Remove()
c.Assert(err, jc.ErrorIsNil)
// Remove twice is also fine.
err = ipAddr.Remove()
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.IPAddress("0.1.2.3")
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(err, gc.ErrorMatches, `IP address "0.1.2.3" not found`)
}
开发者ID:Pankov404,项目名称:juju,代码行数:29,代码来源:ipaddresses_test.go
示例13: internalNetworkAddress
// internalNetworkAddress returns the instance's jujunetwork.Address for the
// internal virtual network. This address is used to identify the machine in
// network security rules.
func (inst *azureInstance) internalNetworkAddress() (jujunetwork.Address, error) {
inst.env.mu.Lock()
subscriptionId := inst.env.config.subscriptionId
resourceGroup := inst.env.resourceGroup
controllerResourceGroup := inst.env.controllerResourceGroup
inst.env.mu.Unlock()
internalSubnetId := internalSubnetId(
resourceGroup, controllerResourceGroup, subscriptionId,
)
for _, nic := range inst.networkInterfaces {
if nic.Properties.IPConfigurations == nil {
continue
}
for _, ipConfiguration := range *nic.Properties.IPConfigurations {
if ipConfiguration.Properties.Subnet == nil {
continue
}
if strings.ToLower(to.String(ipConfiguration.Properties.Subnet.ID)) != strings.ToLower(internalSubnetId) {
continue
}
privateIpAddress := ipConfiguration.Properties.PrivateIPAddress
if privateIpAddress == nil {
continue
}
return jujunetwork.NewScopedAddress(
to.String(privateIpAddress),
jujunetwork.ScopeCloudLocal,
), nil
}
}
return jujunetwork.Address{}, errors.NotFoundf("internal network address")
}
开发者ID:imoapps,项目名称:juju,代码行数:36,代码来源:instance.go
示例14: TestUnitCaching
func (s *InterfaceSuite) TestUnitCaching(c *gc.C) {
ctx := s.GetContext(c, -1, "")
pr, err := ctx.PrivateAddress()
c.Assert(err, jc.ErrorIsNil)
c.Assert(pr, gc.Equals, "u-0.testing.invalid")
pa, err := ctx.PublicAddress()
c.Assert(err, jc.ErrorIsNil)
// Initially the public address is the same as the private address since
// the "most public" address is chosen.
c.Assert(pr, gc.Equals, pa)
// Change remote state.
err = s.machine.SetProviderAddresses(
network.NewScopedAddress("blah.testing.invalid", network.ScopePublic),
)
c.Assert(err, jc.ErrorIsNil)
// Local view is unchanged.
pr, err = ctx.PrivateAddress()
c.Assert(err, jc.ErrorIsNil)
c.Assert(pr, gc.Equals, "u-0.testing.invalid")
pa, err = ctx.PublicAddress()
c.Assert(err, jc.ErrorIsNil)
c.Assert(pr, gc.Equals, pa)
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:context_test.go
示例15: AddUnit
func (s *ContextSuite) AddUnit(c *gc.C, svc *state.Service) *state.Unit {
unit, err := svc.AddUnit()
c.Assert(err, jc.ErrorIsNil)
if s.machine != nil {
err = unit.AssignToMachine(s.machine)
c.Assert(err, jc.ErrorIsNil)
return unit
}
err = s.State.AssignUnit(unit, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
machineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
s.machine, err = s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
zone := "a-zone"
hwc := instance.HardwareCharacteristics{
AvailabilityZone: &zone,
}
err = s.machine.SetProvisioned("i-exist", "fake_nonce", &hwc)
c.Assert(err, jc.ErrorIsNil)
name := strings.Replace(unit.Name(), "/", "-", 1)
privateAddr := network.NewScopedAddress(name+".testing.invalid", network.ScopeCloudLocal)
err = s.machine.SetProviderAddresses(privateAddr)
c.Assert(err, jc.ErrorIsNil)
return unit
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:28,代码来源:util_test.go
示例16: TestNetworkInterfaces
func (t *localServerSuite) TestNetworkInterfaces(c *gc.C) {
env, instId := t.setUpInstanceWithDefaultVpc(c)
interfaces, err := env.NetworkInterfaces(instId)
c.Assert(err, jc.ErrorIsNil)
// The CIDR isn't predictable, but it is in the 10.10.x.0/24 format
// The subnet ID is in the form "subnet-x", where x matches the same
// number from the CIDR. The interfaces address is part of the CIDR.
// For these reasons we check that the CIDR is in the expected format
// and derive the expected values for ProviderSubnetId and Address.
c.Assert(interfaces, gc.HasLen, 1)
cidr := interfaces[0].CIDR
re := regexp.MustCompile(`10\.10\.(\d+)\.0/24`)
c.Assert(re.Match([]byte(cidr)), jc.IsTrue)
index := re.FindStringSubmatch(cidr)[1]
addr := fmt.Sprintf("10.10.%s.5", index)
subnetId := network.Id("subnet-" + index)
expectedInterfaces := []network.InterfaceInfo{{
DeviceIndex: 0,
MACAddress: "20:01:60:cb:27:37",
CIDR: cidr,
ProviderId: "eni-0",
ProviderSubnetId: subnetId,
VLANTag: 0,
InterfaceName: "unsupported0",
Disabled: false,
NoAutoStart: false,
ConfigType: network.ConfigDHCP,
Address: network.NewScopedAddress(addr, network.ScopeCloudLocal),
}}
c.Assert(interfaces, jc.DeepEquals, expectedInterfaces)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:33,代码来源:local_test.go
示例17: TestMachineAddresses
func (s *MachinerStateSuite) TestMachineAddresses(c *gc.C) {
lxcFakeNetConfig := filepath.Join(c.MkDir(), "lxc-net")
netConf := []byte(`
# comments ignored
LXC_BR= ignored
LXC_ADDR = "fooo"
LXC_BRIDGE="foobar" # detected
anything else ignored
LXC_BRIDGE="ignored"`[1:])
err := ioutil.WriteFile(lxcFakeNetConfig, netConf, 0644)
c.Assert(err, jc.ErrorIsNil)
s.PatchValue(machiner.InterfaceAddrs, func() ([]net.Addr, error) {
addrs := []net.Addr{
&net.IPAddr{IP: net.IPv4(10, 0, 0, 1)},
&net.IPAddr{IP: net.IPv4(127, 0, 0, 1)},
&net.IPAddr{IP: net.IPv4(10, 0, 3, 1)}, // lxc bridge address ignored
&net.IPAddr{IP: net.IPv6loopback},
&net.UnixAddr{}, // not IP, ignored
&net.IPAddr{IP: net.IPv4(10, 0, 3, 4)}, // lxc bridge address ignored
&net.IPNet{IP: net.ParseIP("2001:db8::1")},
&net.IPAddr{IP: net.IPv4(169, 254, 1, 20)}, // LinkLocal Ignored
&net.IPNet{IP: net.ParseIP("fe80::1")}, // LinkLocal Ignored
}
return addrs, nil
})
s.PatchValue(&network.InterfaceByNameAddrs, func(name string) ([]net.Addr, error) {
c.Assert(name, gc.Equals, "foobar")
return []net.Addr{
&net.IPAddr{IP: net.IPv4(10, 0, 3, 1)},
&net.IPAddr{IP: net.IPv4(10, 0, 3, 4)},
}, nil
})
s.PatchValue(&network.LXCNetDefaultConfig, lxcFakeNetConfig)
mr := s.makeMachiner()
defer worker.Stop(mr)
c.Assert(s.machine.Destroy(), gc.IsNil)
s.State.StartSync()
c.Assert(mr.Wait(), gc.Equals, worker.ErrTerminateAgent)
c.Assert(s.machine.Refresh(), gc.IsNil)
c.Assert(s.machine.MachineAddresses(), jc.DeepEquals, []network.Address{
network.NewAddress("2001:db8::1"),
network.NewScopedAddress("10.0.0.1", network.ScopeCloudLocal),
network.NewScopedAddress("::1", network.ScopeMachineLocal),
network.NewScopedAddress("127.0.0.1", network.ScopeMachineLocal),
})
}
开发者ID:Pankov404,项目名称:juju,代码行数:47,代码来源:machiner_test.go
示例18: AddUnit
func (s *HookContextSuite) AddUnit(c *gc.C, svc *state.Service) *state.Unit {
unit := s.addUnit(c, svc)
name := strings.Replace(unit.Name(), "/", "-", 1)
privateAddr := network.NewScopedAddress(name+".testing.invalid", network.ScopeCloudLocal)
err := s.machine.SetProviderAddresses(privateAddr)
c.Assert(err, jc.ErrorIsNil)
return unit
}
开发者ID:kakamessi99,项目名称:juju,代码行数:8,代码来源:util_test.go
示例19: TestImplicitRelationer
func (s *RelationerImplicitSuite) TestImplicitRelationer(c *gc.C) {
// Create a relationer for an implicit endpoint (mysql:juju-info).
mysql := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
u, err := mysql.AddUnit()
c.Assert(err, jc.ErrorIsNil)
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
err = u.AssignToMachine(machine)
c.Assert(err, jc.ErrorIsNil)
err = machine.SetProviderAddresses(network.NewScopedAddress("blah", network.ScopeCloudLocal))
c.Assert(err, jc.ErrorIsNil)
s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
eps, err := s.State.InferEndpoints("logging", "mysql")
c.Assert(err, jc.ErrorIsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, jc.ErrorIsNil)
relsDir := c.MkDir()
dir, err := relation.ReadStateDir(relsDir, rel.Id())
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = u.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
st := s.OpenAPIAs(c, u.Tag(), password)
uniterState, err := st.Uniter()
c.Assert(err, jc.ErrorIsNil)
c.Assert(uniterState, gc.NotNil)
apiUnit, err := uniterState.Unit(u.Tag().(names.UnitTag))
c.Assert(err, jc.ErrorIsNil)
apiRel, err := uniterState.Relation(rel.Tag().(names.RelationTag))
c.Assert(err, jc.ErrorIsNil)
apiRelUnit, err := apiRel.Unit(apiUnit)
c.Assert(err, jc.ErrorIsNil)
r := relation.NewRelationer(apiRelUnit, dir)
c.Assert(r, jc.Satisfies, (*relation.Relationer).IsImplicit)
// Hooks are not allowed.
f := func() { r.PrepareHook(hook.Info{}) }
c.Assert(f, gc.PanicMatches, "implicit relations must not run hooks")
f = func() { r.CommitHook(hook.Info{}) }
c.Assert(f, gc.PanicMatches, "implicit relations must not run hooks")
// Set it to Dying; check that the dir is removed immediately.
err = r.SetDying()
c.Assert(err, jc.ErrorIsNil)
path := strconv.Itoa(rel.Id())
ft.Removed{path}.Check(c, relsDir)
err = rel.Destroy()
c.Assert(err, jc.ErrorIsNil)
err = rel.Refresh()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:bac,项目名称:juju,代码行数:56,代码来源:relationer_test.go
示例20: TestAddIPAddressAlreadyExists
func (s *IPAddressSuite) TestAddIPAddressAlreadyExists(c *gc.C) {
addr := network.NewScopedAddress("0.1.2.3", network.ScopePublic)
_, err := s.State.AddIPAddress(addr, "foobar")
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.AddIPAddress(addr, "foobar")
c.Assert(err, jc.Satisfies, errors.IsAlreadyExists)
c.Assert(err, gc.ErrorMatches,
`cannot add IP address "public:0.1.2.3": address already exists`,
)
}
开发者ID:Pankov404,项目名称:juju,代码行数:10,代码来源:ipaddresses_test.go
注:本文中的github.com/juju/juju/network.NewScopedAddress函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论