本文整理汇总了Golang中github.com/juju/juju/environs.NetworkingEnviron.Spaces方法的典型用法代码示例。如果您正苦于以下问题:Golang NetworkingEnviron.Spaces方法的具体用法?Golang NetworkingEnviron.Spaces怎么用?Golang NetworkingEnviron.Spaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs.NetworkingEnviron
的用法示例。
在下文中一共展示了NetworkingEnviron.Spaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleSubnets
func (dw *discoverspacesWorker) handleSubnets(env environs.NetworkingEnviron) error {
ok, err := env.SupportsSpaceDiscovery()
if err != nil {
return errors.Trace(err)
}
if !ok {
// Nothing to do.
return nil
}
providerSpaces, err := env.Spaces()
if err != nil {
return errors.Trace(err)
}
listSpacesResult, err := dw.api.ListSpaces()
if err != nil {
return errors.Trace(err)
}
stateSubnets, err := dw.api.ListSubnets(params.SubnetsFilters{})
if err != nil {
return errors.Trace(err)
}
stateSubnetIds := make(set.Strings)
for _, subnet := range stateSubnets.Results {
stateSubnetIds.Add(subnet.ProviderId)
}
stateSpaceMap := make(map[string]params.ProviderSpace)
spaceNames := make(set.Strings)
for _, space := range listSpacesResult.Results {
stateSpaceMap[space.ProviderId] = space
spaceNames.Add(space.Name)
}
// TODO(mfoord): we need to delete spaces and subnets that no longer
// exist, so long as they're not in use.
for _, space := range providerSpaces {
// Check if the space is already in state, in which case we know
// its name.
stateSpace, ok := stateSpaceMap[string(space.ProviderId)]
var spaceTag names.SpaceTag
if ok {
spaceName := stateSpace.Name
if !names.IsValidSpace(spaceName) {
// Can only happen if an invalid name is stored
// in state.
logger.Errorf("space %q has an invalid name, ignoring", spaceName)
continue
}
spaceTag = names.NewSpaceTag(spaceName)
} else {
// The space is new, we need to create a valid name for it
// in state.
spaceName := string(space.ProviderId)
// Convert the name into a valid name that isn't already in
// use.
spaceName = convertSpaceName(spaceName, spaceNames)
spaceNames.Add(spaceName)
spaceTag = names.NewSpaceTag(spaceName)
// We need to create the space.
args := params.CreateSpacesParams{
Spaces: []params.CreateSpaceParams{{
Public: false,
SpaceTag: spaceTag.String(),
ProviderId: string(space.ProviderId),
}}}
result, err := dw.api.CreateSpaces(args)
if err != nil {
logger.Errorf("error creating space %v", err)
return errors.Trace(err)
}
if len(result.Results) != 1 {
return errors.Errorf("unexpected number of results from CreateSpaces, should be 1: %v", result)
}
if result.Results[0].Error != nil {
return errors.Errorf("error from CreateSpaces: %v", result.Results[0].Error)
}
}
// TODO(mfoord): currently no way of removing subnets, or
// changing the space they're in, so we can only add ones we
// don't already know about.
logger.Debugf("Created space %v with %v subnets", spaceTag.String(), len(space.Subnets))
for _, subnet := range space.Subnets {
if stateSubnetIds.Contains(string(subnet.ProviderId)) {
continue
}
zones := subnet.AvailabilityZones
if len(zones) == 0 {
zones = []string{"default"}
}
args := params.AddSubnetsParams{
Subnets: []params.AddSubnetParams{{
SubnetProviderId: string(subnet.ProviderId),
SpaceTag: spaceTag.String(),
Zones: zones,
}}}
logger.Tracef("Adding subnet %v", subnet.CIDR)
result, err := dw.api.AddSubnets(args)
if err != nil {
//.........这里部分代码省略.........