本文整理汇总了Golang中github.com/Juniper/contrail-go-api/types.VirtualNetwork类的典型用法代码示例。如果您正苦于以下问题:Golang VirtualNetwork类的具体用法?Golang VirtualNetwork怎么用?Golang VirtualNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualNetwork类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: locatePolicyRule
func (m *ServiceManagerImpl) locatePolicyRule(policy *types.NetworkPolicy, lhs, rhs *types.VirtualNetwork) error {
lhsName := strings.Join(lhs.GetFQName(), ":")
rhsName := strings.Join(rhs.GetFQName(), ":")
entries := policy.GetNetworkPolicyEntries()
for _, rule := range entries.PolicyRule {
if rule.SrcAddresses[0].VirtualNetwork == lhsName &&
rule.DstAddresses[0].VirtualNetwork == rhsName {
return nil
}
}
rule := new(types.PolicyRuleType)
rule.Protocol = "any"
rule.Direction = "<>"
rule.SrcAddresses = []types.AddressType{types.AddressType{
VirtualNetwork: lhsName,
}}
rule.DstAddresses = []types.AddressType{types.AddressType{
VirtualNetwork: rhsName,
}}
rule.SrcPorts = []types.PortType{types.PortType{-1, -1}}
rule.DstPorts = []types.PortType{types.PortType{-1, -1}}
rule.ActionList = &types.ActionListType{
SimpleAction: "pass",
}
entries.AddPolicyRule(rule)
policy.SetNetworkPolicyEntries(&entries)
err := m.client.Update(policy)
if err != nil {
glog.Errorf("policy-rule: %v", err)
return err
}
return nil
}
开发者ID:ZJU-SEL,项目名称:contrail-kubernetes,代码行数:35,代码来源:service.go
示例2: DeleteConnections
func (m *NetworkManagerImpl) DeleteConnections(network *types.VirtualNetwork, policies map[string]string) error {
for policyID, _ := range policies {
network.DeleteNetworkPolicy(policyID)
}
err := m.client.Update(network)
for policyID, targetName := range policies {
policy, policyErr := types.NetworkPolicyByUuid(m.client, policyID)
if policyErr != nil {
glog.Error(policyErr)
continue
}
networkRefs, policyErr := policy.GetVirtualNetworkBackRefs()
if len(networkRefs) > 1 {
continue
}
if len(networkRefs) == 1 {
if strings.Join(networkRefs[0].To, ":") == targetName {
policyErr = m.disconnectNetworkFromPolicy(policy, targetName)
if policyErr != nil {
glog.Error(policyErr)
continue
}
} else {
continue
}
}
policyErr = m.client.Delete(policy)
if policyErr != nil {
glog.Error(policyErr)
}
}
return err
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:35,代码来源:network.go
示例3: DeleteConnections
func (m *ServiceManagerImpl) DeleteConnections(network *types.VirtualNetwork, purgeList []string) error {
if len(purgeList) == 0 {
return nil
}
for _, policyId := range purgeList {
network.DeleteNetworkPolicy(policyId)
}
err := m.client.Update(network)
if err != nil {
return err
}
for _, policyId := range purgeList {
policy, err := types.NetworkPolicyByUuid(m.client, policyId)
if err != nil {
glog.Error(err)
continue
}
refs, err := policy.GetVirtualNetworkBackRefs()
if err != nil {
glog.Error(err)
continue
}
if len(refs) == 0 {
err = m.client.Delete(policy)
if err != nil {
glog.Error(err)
}
}
}
return nil
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:31,代码来源:service.go
示例4: TestReadChildren
func TestReadChildren(t *testing.T) {
client := new(ApiClient)
client.Init()
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "p1"})
assert.NoError(t, client.Create(project))
net := new(types.VirtualNetwork)
net.SetFQName("project", []string{"default-domain", "p1", "n1"})
assert.NoError(t, client.Create(net))
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetFQName("project", []string{"default-domain", "p1", "port1"})
vmi1.AddVirtualNetwork(net)
assert.NoError(t, client.Create(vmi1))
vmi2 := new(types.VirtualMachineInterface)
vmi2.SetFQName("project", []string{"default-domain", "p1", "port2"})
vmi2.AddVirtualNetwork(net)
assert.NoError(t, client.Create(vmi2))
refs, err := project.GetVirtualMachineInterfaces()
assert.NoError(t, err)
assert.Len(t, refs, 2)
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:26,代码来源:updater_test.go
示例5: 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
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:28,代码来源:consistency.go
示例6: LocateInterface
func (m *InstanceManager) LocateInterface(
network *types.VirtualNetwork, instance *types.VirtualMachine) *types.VirtualMachineInterface {
tenant := network.GetFQName()[len(network.GetFQName())-2]
fqn := interfaceFQName(m.config.DefaultDomain, tenant, instance.GetName())
obj, err := m.client.FindByName(
"virtual-machine-interface", strings.Join(fqn, ":"))
if err == nil {
nic := obj.(*types.VirtualMachineInterface)
// TODO(prm): ensure network is as expected, else update.
return nic
}
nic := new(types.VirtualMachineInterface)
nic.SetFQName("project", fqn)
nic.AddVirtualMachine(instance)
if network != nil {
nic.AddVirtualNetwork(network)
}
err = m.client.Create(nic)
if err != nil {
glog.Errorf("Create interface %s: %v", instance.GetName(), err)
return nil
}
obj, err = m.client.FindByUuid(nic.GetType(), nic.GetUuid())
if err != nil {
glog.Errorf("Get vmi %s: %v", nic.GetUuid(), err)
return nil
}
return obj.(*types.VirtualMachineInterface)
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:32,代码来源:instance.go
示例7: TestPropertyUpdate
func TestPropertyUpdate(t *testing.T) {
client := contrail.NewClient("localhost", 8082)
net := types.VirtualNetwork{}
net.SetName("test")
err := client.Create(&net)
if err != nil {
t.Error(err)
}
defer client.Delete(&net)
props := net.GetVirtualNetworkProperties()
if len(props.ForwardingMode) > 0 {
t.Error(props.ForwardingMode)
}
props.ForwardingMode = "l2_l3"
net.SetVirtualNetworkProperties(&props)
err = client.Update(&net)
if err != nil {
t.Error(err)
}
obj, err := client.FindByUuid("virtual-network", net.GetUuid())
if err != nil {
t.Fatal(err)
}
netPtr := obj.(*types.VirtualNetwork)
p2 := netPtr.GetVirtualNetworkProperties()
if p2.ForwardingMode != "l2_l3" {
t.Errorf("Expected: l2_l3 got: %s", p2.ForwardingMode)
}
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:33,代码来源:client_test.go
示例8: 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
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:13,代码来源:network.go
示例9: globalNetworkConnectionUpdate
func (c *Controller) globalNetworkConnectionUpdate(network *types.VirtualNetwork) {
if !networkAccessGlobalNetworks(c.config, network.GetFQName()) {
return
}
// connect to each of the global-networks
for _, gbl := range c.config.GlobalNetworks {
err := c.networkMgr.Connect(network, gbl)
if err != nil {
glog.Error(err)
continue
}
glog.V(2).Infof("Connected %s to %s", strings.Join(network.GetFQName(), ":"), gbl)
}
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:14,代码来源:controller.go
示例10: TestPodCreate
func TestPodCreate(t *testing.T) {
kube := mocks.NewKubeClient()
client := new(contrail_mocks.ApiClient)
client.Init()
client.AddInterceptor("virtual-machine-interface", &VmiInterceptor{})
allocator := new(mocks.AddressAllocator)
networkMgr := new(mocks.NetworkManager)
controller := NewTestController(kube, client, allocator, networkMgr)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "test",
Namespace: "testns",
UID: kubetypes.UID(uuid.New()),
Labels: map[string]string{
"name": "testnet",
},
},
}
netnsProject := new(types.Project)
netnsProject.SetUuid(uuid.New())
netnsProject.SetFQName("", []string{"default-domain", "testns"})
client.Create(netnsProject)
testnet := new(types.VirtualNetwork)
testnet.SetFQName("project", []string{"default-domain", "testns", "testnet"})
client.Create(testnet)
allocator.On("LocateIpAddress", string(pod.ObjectMeta.UID)).Return("10.0.0.42", nil)
networkMgr.On("LocateNetwork", "testns", "testnet",
controller.config.PrivateSubnet).Return(testnet, nil)
networkMgr.On("GetGatewayAddress", testnet).Return("10.0.255.254", nil)
kube.PodInterface.On("Update", pod).Return(pod, nil)
shutdown := make(chan struct{})
go controller.Run(shutdown)
controller.AddPod(pod)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
kube.PodInterface.AssertExpectations(t)
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:50,代码来源:controller_test.go
示例11: CreateNetworkWithSubnet
func CreateNetworkWithSubnet(
client contrail.ApiClient, project_id, name, prefix string) (
string, error) {
expr := regexp.MustCompile(`(([0-9]{1,3}\.){3}[0-9]{1,3})/([0-9]{1,2})`)
match := expr.FindStringSubmatch(prefix)
if match == nil {
return "", fmt.Errorf("Invalid subnet prefix %s", prefix)
}
address := match[1]
prefixlen, _ := strconv.Atoi(match[3])
obj, err := client.FindByUuid("project", project_id)
if err != nil {
return "", err
}
project := obj.(*types.Project)
refList, err := project.GetNetworkIpams()
if err != nil {
return "", err
}
var ipam *types.NetworkIpam
if len(refList) > 0 {
obj, err := client.FindByUuid("network-ipam", refList[0].Uuid)
if err != nil {
return "", err
}
ipam = obj.(*types.NetworkIpam)
} else {
obj, err := client.FindByName("network-ipam",
"default-domain:default-project:default-network-ipam")
if err != nil {
return "", err
}
ipam = obj.(*types.NetworkIpam)
}
net := new(types.VirtualNetwork)
net.SetParent(project)
net.SetName(name)
subnets := types.VnSubnetsType{}
subnets.AddIpamSubnets(
&types.IpamSubnetType{
Subnet: &types.SubnetType{address, prefixlen}})
net.AddNetworkIpam(ipam, subnets)
err = client.Create(net)
if err != nil {
return "", err
}
return net.GetUuid(), nil
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:54,代码来源:network.go
示例12: TestCreate
func TestCreate(t *testing.T) {
client := contrail.NewClient("localhost", 8082)
net := types.VirtualNetwork{}
net.SetName("test")
ipam, err := client.FindByName("network-ipam",
"default-domain:default-project:default-network-ipam")
if err != nil {
t.Fatal(err)
}
subnets := types.VnSubnetsType{}
subnets.AddIpamSubnets(
&types.IpamSubnetType{
Subnet: &types.SubnetType{"10.0.0.0", 8}})
net.AddNetworkIpam(ipam.(*types.NetworkIpam), subnets)
err = client.Create(&net)
if err != nil {
t.Error(err)
}
if len(net.GetUuid()) == 0 {
t.Error("No uuid assigned")
}
netPtr, err := client.FindByUuid("virtual-network", net.GetUuid())
if err != nil {
t.Error(err)
} else {
xnet := netPtr.(*types.VirtualNetwork)
refs, err := xnet.GetNetworkIpamRefs()
if err != nil {
t.Error(err)
} else if len(refs) > 0 {
xattr := refs[0].Attr.(types.VnSubnetsType)
if len(xattr.IpamSubnets) == 1 {
isubnet := xattr.IpamSubnets[0]
if isubnet.Subnet.IpPrefix != "10.0.0.0" ||
isubnet.Subnet.IpPrefixLen != 8 {
t.Errorf("Bad subnet %s/%d",
isubnet.Subnet.IpPrefix,
isubnet.Subnet.IpPrefixLen)
}
} else {
t.Errorf("%d subnets", len(xattr.IpamSubnets))
}
} else {
t.Error("Empty network-ipam reference list")
}
}
err = client.Delete(&net)
if err != nil {
t.Error(err)
}
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:53,代码来源:client_test.go
示例13: 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
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:16,代码来源:network.go
示例14: PurgeStalePolicyRefs
func (m *ServiceManagerImpl) PurgeStalePolicyRefs(network *types.VirtualNetwork, services ServiceIdList,
doDelete func(string, string) bool) error {
purgeList := make([]string, 0)
refs, err := network.GetNetworkPolicyRefs()
if err != nil {
return err
}
for _, ref := range refs {
if len(ref.To) < 3 {
glog.Errorf("unexpected policy id %+v", ref.To)
continue
}
namespace := ref.To[1]
serviceName := ref.To[len(ref.To)-1]
if !services.Contains(namespace, serviceName) && doDelete(namespace, serviceName) {
purgeList = append(purgeList, ref.Uuid)
}
}
if len(purgeList) == 0 {
return nil
}
for _, policyId := range purgeList {
network.DeleteNetworkPolicy(policyId)
}
err = m.client.Update(network)
if err != nil {
return err
}
for _, policyId := range purgeList {
policy, err := types.NetworkPolicyByUuid(m.client, policyId)
if err != nil {
glog.Error(err)
continue
}
refs, err := policy.GetVirtualNetworkBackRefs()
if err != nil {
glog.Error(err)
}
if len(refs) == 0 {
err = m.client.Delete(policy)
if err != nil {
glog.Error(err)
}
}
}
return nil
}
开发者ID:michaelkuty,项目名称:contrail-kubernetes,代码行数:47,代码来源:service.go
示例15: NetworkIPPrefixList
//
// Retrieve the list of IP prefixes associated with this network.
//
func (m *NetworkManagerImpl) NetworkIPPrefixList(network *types.VirtualNetwork) ([]string, error) {
prefixList := make([]string, 0)
refList, err := network.GetNetworkIpamRefs()
if err != nil {
return nil, err
}
for _, ref := range refList {
attr := ref.Attr.(types.VnSubnetsType)
for _, ipamSubnet := range attr.IpamSubnets {
prefixList = append(prefixList,
fmt.Sprintf("%s/%d", ipamSubnet.Subnet.IpPrefix, ipamSubnet.Subnet.IpPrefixLen))
}
}
return prefixList, nil
}
开发者ID:pupapaik,项目名称:contrail-kubernetes,代码行数:20,代码来源:network.go
示例16: TestReadModifiedPolicy
func TestReadModifiedPolicy(t *testing.T) {
client := new(ApiClient)
client.Init()
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "p1"})
assert.NoError(t, client.Create(project))
policy := new(types.NetworkPolicy)
policy.SetFQName("project", []string{"default-domain", "p1", "x"})
assert.NoError(t, client.Create(policy))
net1 := new(types.VirtualNetwork)
net1.SetFQName("project", []string{"default-domain", "p1", "n1"})
net1.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
assert.NoError(t, client.Create(net1))
net2 := new(types.VirtualNetwork)
net2.SetFQName("project", []string{"default-domain", "p1", "n2"})
net2.AddNetworkPolicy(policy,
types.VirtualNetworkPolicyType{
Sequence: &types.SequenceType{10, 0},
})
assert.NoError(t, client.Create(net2))
refs, err := policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 2)
assert.NoError(t, client.Delete(net1))
refs, err = policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 1)
assert.NoError(t, client.Delete(net2))
refs, err = policy.GetVirtualNetworkBackRefs()
assert.NoError(t, err)
assert.Len(t, refs, 0)
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:43,代码来源:updater_test.go
示例17: TestChildrenRefs
func TestChildrenRefs(t *testing.T) {
db := NewInMemDatabase()
project := new(types.Project)
project.SetUuid(uuid.New())
project.SetName("p1")
assert.NoError(t, db.Put(project, nil, GetReferenceList(project)))
net := new(types.VirtualNetwork)
net.SetUuid(uuid.New())
net.SetFQName("project", []string{"p1", "n1"})
assert.NoError(t, db.Put(net, project, UIDList{}))
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetUuid(uuid.New())
vmi1.SetName("port1")
vmi1.AddVirtualNetwork(net)
assert.NoError(t, db.Put(vmi1, project, GetReferenceList(vmi1)))
vmi2 := new(types.VirtualMachineInterface)
vmi2.SetUuid(uuid.New())
vmi2.SetName("port2")
vmi2.AddVirtualNetwork(net)
assert.NoError(t, db.Put(vmi2, project, GetReferenceList(vmi2)))
result, err := db.GetChildren(parseUID(project.GetUuid()), "virtual_network")
assert.NoError(t, err)
assert.Len(t, result, 1)
result, err = db.GetChildren(parseUID(project.GetUuid()), "virtual_machine_interface")
assert.NoError(t, err)
assert.Len(t, result, 2)
assert.Contains(t, result, parseUID(vmi1.GetUuid()))
assert.Contains(t, result, parseUID(vmi2.GetUuid()))
assert.Error(t, db.Delete(project))
assert.NoError(t, db.Delete(vmi1))
assert.Error(t, db.Delete(net))
assert.NoError(t, db.Delete(vmi2))
assert.NoError(t, db.Delete(net))
assert.NoError(t, db.Delete(project))
}
开发者ID:netturpin,项目名称:contrail-go-api,代码行数:43,代码来源:database_test.go
示例18: connectionShouldDelete
// connectionShouldDelete returns true when a connection should be deleted.
// When a connection is first considered to be stale it is added to a GC list; if it is considered to be stale
// in two consistency runs, it is deleted.
func (c *consistencyChecker) connectionShouldDelete(network *types.VirtualNetwork, lastIterationMap networkConnectionMap, policyName []string) bool {
networkName := strings.Join(network.GetFQName(), ":")
policyCSN := strings.Join(policyName, ":")
if entry, ok := lastIterationMap[networkName]; ok {
if _, exists := entry[policyCSN]; exists {
glog.Infof("%s network connection %s delete", networkName, policyCSN)
return true
}
}
gcPolicies, exists := c.staleConnectionMap[networkName]
if !exists {
gcPolicies = make(policySet, 0)
c.staleConnectionMap[networkName] = gcPolicies
}
glog.Infof("%s network connection %s not used by pod specifications", networkName, policyCSN)
gcPolicies[policyCSN] = true
return false
}
开发者ID:sanabby,项目名称:contrail-kubernetes,代码行数:22,代码来源:consistency.go
示例19: 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
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:20,代码来源:network.go
示例20: 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
}
开发者ID:WIZARD-CXY,项目名称:contrail-kubernetes,代码行数:21,代码来源:network.go
注:本文中的github.com/Juniper/contrail-go-api/types.VirtualNetwork类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论