本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.VirtualNetwork.GetName方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualNetwork.GetName方法的具体用法?Golang VirtualNetwork.GetName怎么用?Golang VirtualNetwork.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Juniper/contrail-go-api/types.VirtualNetwork
的用法示例。
在下文中一共展示了VirtualNetwork.GetName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: globalNetworkCheckPolicyAttachment
func (c *consistencyChecker) globalNetworkCheckPolicyAttachment(network *types.VirtualNetwork) bool {
policyName := makeGlobalNetworkPolicyName(c.config, network.GetFQName())
policy, err := types.NetworkPolicyByName(c.client, strings.Join(policyName, ":"))
if err != nil {
glog.V(3).Infof("No network policy for %s", network.GetName())
return true
}
policyRefs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Error(err)
return true
}
for _, ref := range policyRefs {
if ref.Uuid == policy.GetUuid() {
glog.V(5).Infof("Network %s attached to %s", network.GetName(), policy.GetUuid())
return true
}
}
err = policyAttach(c.client, network, policy)
if err != nil {
glog.Error(err)
} else {
glog.Infof("attached global network %s to policy", strings.Join(network.GetFQName(), ":"))
}
return false
}
示例2: updateSubnetConfig
// Subnets can only be deleted if there are no instance-ips or floating-ips associated
// with the subnet.
func (m *NetworkManagerImpl) updateSubnetConfig(network *types.VirtualNetwork, prefix string) error {
prefixList, err := m.NetworkIPPrefixList(network)
if err != nil {
glog.Fatal(err)
}
add := true
for _, pfx := range prefixList {
if pfx == prefix {
add = false
continue
}
ipRefs, err := network.GetInstanceIpBackRefs()
if err != nil {
glog.Error(err)
continue
}
// TODO: filter the IP addresses associated with the subnet that we are
// attempting to delete.
if len(ipRefs) > 0 {
glog.Warningf(
"network %s %s is stale but there are %d instance-ips present",
network.GetName(), pfx, len(ipRefs))
continue
}
pool, err := m.LookupFloatingIpPool(network)
if err == nil {
floatRefs, err := pool.GetFloatingIps()
if err != nil {
glog.Error(err)
continue
}
// TODO: filter the floating-ips associated with the subnet that we
// are attempting to delete.
if len(floatRefs) > 0 {
glog.Warningf(
"network %s %s is stale but there are %d floating-ip addresses present",
network.GetName(), pfx, len(floatRefs))
continue
}
}
err = config.RemoveSubnet(m.client, network, pfx)
if err != nil {
glog.Error(err)
}
}
if add {
_, err := config.AddSubnet(m.client, network, m.config.PublicSubnet)
if err != nil {
glog.Error(err)
}
return err
}
return nil
}
示例3: DeleteFloatingIpPool
func (m *NetworkManagerImpl) DeleteFloatingIpPool(network *types.VirtualNetwork, cascade bool) error {
obj, err := m.client.FindByName("floating-ip-pool", makePoolName(network))
if err != nil {
glog.Errorf("Get floating-ip-pool %s: %v", network.GetName(), err)
return err
}
if cascade {
pool := obj.(*types.FloatingIpPool)
m.floatingIpPoolDeleteChildren(pool)
}
m.client.Delete(obj)
return nil
}
示例4: LocateFloatingIp
func (m *NetworkManagerImpl) LocateFloatingIp(network *types.VirtualNetwork, resourceName, targetAddress string) (*types.FloatingIp, error) {
obj, err := m.client.FindByName("floating-ip-pool", makePoolName(network))
if err != nil {
glog.Errorf("Get floating-ip-pool %s: %v", network.GetName(), err)
return nil, err
}
pool := obj.(*types.FloatingIpPool)
fqn := AppendConst(pool.GetFQName(), resourceName)
obj, err = m.client.FindByName("floating-ip", strings.Join(fqn, ":"))
if err == nil {
fip := obj.(*types.FloatingIp)
if targetAddress != "" && fip.GetFloatingIpAddress() != targetAddress {
fip.SetFloatingIpAddress(targetAddress)
err = m.client.Update(fip)
if err != nil {
glog.Errorf("Update floating-ip %s: %v", resourceName, err)
return nil, err
}
}
return fip, nil
}
projectFQN := network.GetFQName()[0 : len(network.GetFQName())-1]
obj, err = m.client.FindByName("project", strings.Join(projectFQN, ":"))
if err != nil {
glog.Errorf("Get project %s: %v", projectFQN[len(projectFQN)-1], err)
return nil, err
}
project := obj.(*types.Project)
fip := new(types.FloatingIp)
fip.SetParent(pool)
fip.SetName(resourceName)
if targetAddress != "" {
fip.SetFloatingIpAddress(targetAddress)
}
fip.AddProject(project)
err = m.client.Create(fip)
if err != nil {
glog.Errorf("Create floating-ip %s: %v", resourceName, err)
return nil, err
}
if targetAddress == "" {
fip, err = types.FloatingIpByUuid(m.client, fip.GetUuid())
}
return fip, err
}
示例5: LocateFloatingIpPool
func (m *NetworkManagerImpl) LocateFloatingIpPool(network *types.VirtualNetwork) (*types.FloatingIpPool, error) {
obj, err := m.client.FindByName("floating-ip-pool", makePoolName(network))
if err == nil {
return obj.(*types.FloatingIpPool), nil
}
pool := new(types.FloatingIpPool)
pool.SetName(network.GetName())
pool.SetParent(network)
err = m.client.Create(pool)
if err != nil {
glog.Errorf("Create floating-ip-pool %s: %v", network.GetName(), err)
return nil, err
}
return pool, nil
}
示例6: policyDetach
func policyDetach(client contrail.ApiClient, network *types.VirtualNetwork, policyName string) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if strings.Join(ref.To, ":") == policyName {
network.DeleteNetworkPolicy(ref.Uuid)
err := client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
}
return err
}
}
return nil
}
示例7: detachPolicy
func (m *ServiceManagerImpl) detachPolicy(network *types.VirtualNetwork, policyName string) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if strings.Join(ref.To, ":") == policyName {
network.DeleteNetworkPolicy(ref.Uuid)
err := m.client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
}
return err
}
}
return nil
}
示例8: DeleteNetwork
func (m *NetworkManagerImpl) DeleteNetwork(network *types.VirtualNetwork) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("Get %s policy refs: %v", network.GetName(), err)
}
m.client.Delete(network)
for _, ref := range refs {
obj, err := m.client.FindByUuid("network-policy", ref.Uuid)
if err != nil {
glog.Errorf("Get policy %s: %v", ref.Uuid, err)
}
policy := obj.(*types.NetworkPolicy)
npRefs, err := policy.GetVirtualNetworkBackRefs()
if len(npRefs) == 0 {
m.client.Delete(policy)
}
}
return nil
}
示例9: policyAttach
func policyAttach(client contrail.ApiClient, network *types.VirtualNetwork, policy *types.NetworkPolicy) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if ref.Uuid == policy.GetUuid() {
return nil
}
}
network.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{Major: 10, Minor: 0},
})
err = client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
return err
}
return nil
}
示例10: attachPolicy
func (m *ServiceManagerImpl) attachPolicy(network *types.VirtualNetwork, policy *types.NetworkPolicy) error {
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
glog.Errorf("get network policy-refs %s: %v", network.GetName(), err)
return err
}
for _, ref := range refs {
if ref.Uuid == policy.GetUuid() {
return nil
}
}
network.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
err = m.client.Update(network)
if err != nil {
glog.Errorf("Update network %s policies: %v", network.GetName(), err)
return err
}
return nil
}
示例11: buildNetworkInfo
func buildNetworkInfo(net *types.VirtualNetwork, detail bool) (
*NetworkInfo, error) {
var subnets []string
var policies []string
refList, err := net.GetNetworkIpamRefs()
if err != nil {
return nil, err
}
for _, ref := range refList {
attr := ref.Attr.(types.VnSubnetsType)
for _, ipamSubnet := range attr.IpamSubnets {
subnets = append(subnets, fmt.Sprintf("%s/%d",
ipamSubnet.Subnet.IpPrefix,
ipamSubnet.Subnet.IpPrefixLen))
}
}
if detail {
refList, err = net.GetNetworkPolicyRefs()
for _, ref := range refList {
policies = append(policies, strings.Join(ref.To, ":"))
}
}
info := &NetworkInfo{
net.GetUuid(),
net.GetName(),
net.GetIdPerms().Enable,
net.GetVirtualNetworkProperties().NetworkId,
net.GetVirtualNetworkProperties().AllowTransit,
net.GetVirtualNetworkProperties().ForwardingMode,
subnets,
policies,
net.GetRouteTargetList().RouteTarget,
}
return info, err
}
示例12: LocateFloatingIpPool
func (m *NetworkManagerImpl) LocateFloatingIpPool(
network *types.VirtualNetwork, subnet string) (*types.FloatingIpPool, error) {
obj, err := m.client.FindByName(
"floating-ip-pool", makePoolName(network))
if err == nil {
return obj.(*types.FloatingIpPool), nil
}
address, prefixlen := PrefixToAddressLen(subnet)
pool := new(types.FloatingIpPool)
pool.SetName(network.GetName())
pool.SetParent(network)
pool.SetFloatingIpPoolPrefixes(
&types.FloatingIpPoolType{
Subnet: []types.SubnetType{types.SubnetType{address, prefixlen}}})
err = m.client.Create(pool)
if err != nil {
glog.Errorf("Create floating-ip-pool %s: %v", network.GetName(), err)
return nil, err
}
return pool, nil
}
示例13: GetGatewayAddress
func (m *NetworkManagerImpl) GetGatewayAddress(network *types.VirtualNetwork) (string, error) {
refs, err := network.GetNetworkIpamRefs()
if err != nil {
glog.Errorf("Get network %s network-ipam refs: %v", network.GetName(), err)
return "", err
}
attr := refs[0].Attr.(types.VnSubnetsType)
if len(attr.IpamSubnets) == 0 {
glog.Errorf("Network %s has no subnets configured", network.GetName())
return "", fmt.Errorf("Network %s: empty subnet list", network.GetName())
}
gateway := attr.IpamSubnets[0].DefaultGateway
if gateway == "" {
glog.Errorf("Gateway for %s is empty", network.GetName())
return "", fmt.Errorf("Gateway is empty: %+v", attr.IpamSubnets)
}
return gateway, nil
}