本文整理汇总了Golang中github.com/juju/juju/state.Subnet类的典型用法代码示例。如果您正苦于以下问题:Golang Subnet类的具体用法?Golang Subnet怎么用?Golang Subnet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subnet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: allocateAddress
// allocateAddress tries to pick an address out of the given subnet and
// allocates it to the container.
func (p *ProvisionerAPI) allocateAddress(
environ environs.NetworkingEnviron,
subnet *state.Subnet,
host, container *state.Machine,
instId instance.Id,
macAddress string,
) (*state.IPAddress, error) {
subnetId := network.Id(subnet.ProviderId())
name := names.NewMachineTag(container.Id()).String()
for {
addr, err := subnet.PickNewAddress()
if err != nil {
return nil, err
}
logger.Tracef("picked new address %q on subnet %q", addr.String(), subnetId)
// Attempt to allocate with environ.
err = environ.AllocateAddress(instId, subnetId, addr.Address(), macAddress, name)
if err != nil {
logger.Warningf(
"allocating address %q on instance %q and subnet %q failed: %v (retrying)",
addr.String(), instId, subnetId, err,
)
// It's as good as unavailable for us, so mark it as
// such.
err = setAddrState(addr, state.AddressStateUnavailable)
if err != nil {
logger.Warningf(
"cannot set address %q to %q: %v (ignoring and retrying)",
addr.String(), state.AddressStateUnavailable, err,
)
continue
}
logger.Tracef(
"setting address %q to %q and retrying",
addr.String(), state.AddressStateUnavailable,
)
continue
}
logger.Infof(
"allocated address %q on instance %q and subnet %q",
addr.String(), instId, subnetId,
)
err = p.setAllocatedOrRelease(addr, environ, instId, container, subnetId, macAddress)
if err != nil {
// Something went wrong - retry.
continue
}
return addr, nil
}
}
示例2: allocateAddress
// allocateAddress tries to pick an address out of the given subnet and
// allocates it to the container.
func (p *ProvisionerAPI) allocateAddress(
environ environs.NetworkingEnviron,
subnet *state.Subnet,
host, container *state.Machine,
instId instance.Id,
macAddress string,
) (*state.IPAddress, error) {
hostname := containerHostname(container.Tag())
if !environs.AddressAllocationEnabled() {
// Even if the address allocation feature flag is not enabled, we might
// be running on MAAS 1.8+ with devices support, which we can use to
// register containers getting IPs via DHCP. However, most of the usual
// allocation code can be bypassed, we just need the parent instance ID
// and a MAC address (no subnet or IP address).
allocatedAddress := network.Address{}
err := environ.AllocateAddress(instId, network.AnySubnet, &allocatedAddress, macAddress, hostname)
if err != nil {
// Not using MAAS 1.8+ or some other error.
return nil, errors.Trace(err)
}
logger.Infof(
"allocated address %q on instance %q for container %q",
allocatedAddress.String(), instId, hostname,
)
// Add the address to state, so we can look it up later by MAC address.
stateAddr, err := p.st.AddIPAddress(allocatedAddress, string(network.AnySubnet))
if err != nil {
return nil, errors.Annotatef(err, "failed to save address %q", allocatedAddress)
}
err = p.setAllocatedOrRelease(stateAddr, environ, instId, container, network.AnySubnet, macAddress)
if err != nil {
return nil, errors.Trace(err)
}
return stateAddr, nil
}
subnetId := network.Id(subnet.ProviderId())
for {
addr, err := subnet.PickNewAddress()
if err != nil {
return nil, err
}
netAddr := addr.Address()
logger.Tracef("picked new address %q on subnet %q", addr.String(), subnetId)
// Attempt to allocate with environ.
err = environ.AllocateAddress(instId, subnetId, &netAddr, macAddress, hostname)
if err != nil {
logger.Warningf(
"allocating address %q on instance %q and subnet %q failed: %v (retrying)",
addr.String(), instId, subnetId, err,
)
// It's as good as unavailable for us, so mark it as
// such.
err = setAddrState(addr, state.AddressStateUnavailable)
if err != nil {
logger.Warningf(
"cannot set address %q to %q: %v (ignoring and retrying)",
addr.String(), state.AddressStateUnavailable, err,
)
continue
}
logger.Tracef(
"setting address %q to %q and retrying",
addr.String(), state.AddressStateUnavailable,
)
continue
}
logger.Infof(
"allocated address %q on instance %q and subnet %q",
addr.String(), instId, subnetId,
)
err = p.setAllocatedOrRelease(addr, environ, instId, container, subnetId, macAddress)
if err != nil {
// Something went wrong - retry.
continue
}
return addr, nil
}
}
示例3: assertSubnetMatchesInfo
func (s *SubnetSuite) assertSubnetMatchesInfo(c *gc.C, subnet *state.Subnet, info state.SubnetInfo) {
c.Assert(subnet.ProviderId(), gc.Equals, info.ProviderId)
c.Assert(subnet.CIDR(), gc.Equals, info.CIDR)
c.Assert(subnet.VLANTag(), gc.Equals, info.VLANTag)
c.Assert(subnet.AllocatableIPLow(), gc.Equals, info.AllocatableIPLow)
c.Assert(subnet.AllocatableIPHigh(), gc.Equals, info.AllocatableIPHigh)
c.Assert(subnet.AvailabilityZone(), gc.Equals, info.AvailabilityZone)
c.Assert(subnet.String(), gc.Equals, info.CIDR)
c.Assert(subnet.GoString(), gc.Equals, info.CIDR)
c.Assert(subnet.SpaceName(), gc.Equals, info.SpaceName)
}
示例4: addIPAddressForSubnet
func (s *SubnetSuite) addIPAddressForSubnet(c *gc.C, ipAddress string, subnet *state.Subnet) {
_, err := s.State.AddIPAddress(network.NewAddress(ipAddress), subnet.ID())
c.Assert(err, jc.ErrorIsNil)
}
示例5: removeSubnetAndAssertNotFound
func (s *SubnetSuite) removeSubnetAndAssertNotFound(c *gc.C, subnet *state.Subnet) {
err := subnet.Remove()
c.Assert(err, jc.ErrorIsNil)
s.assertSubnetWithCIDRNotFound(c, subnet.CIDR())
}
示例6: refreshAndAssertSubnetLifeIs
func (s *SubnetSuite) refreshAndAssertSubnetLifeIs(c *gc.C, subnet *state.Subnet, expectedLife state.Life) {
err := subnet.Refresh()
c.Assert(err, jc.ErrorIsNil)
c.Assert(subnet.Life(), gc.Equals, expectedLife)
}
示例7: ensureDeadAndAssertLifeIsDead
func (s *SubnetSuite) ensureDeadAndAssertLifeIsDead(c *gc.C, subnet *state.Subnet) {
err := subnet.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
c.Assert(subnet.Life(), gc.Equals, state.Dead)
}