本文整理匯總了Golang中github.com/Juniper/contrail-go-api/types.Project.SetFQName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Project.SetFQName方法的具體用法?Golang Project.SetFQName怎麽用?Golang Project.SetFQName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Juniper/contrail-go-api/types.Project
的用法示例。
在下文中一共展示了Project.SetFQName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: Init
func (m *ApiClient) Init() {
m.db = NewInMemDatabase()
m.updater = NewObjectUpdater(m.db)
domain := new(types.Domain)
domain.SetName("default-domain")
err := m.Create(domain)
if err != nil {
panic(err.Error())
}
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "default-project"})
err = m.Create(project)
if err != nil {
panic(err.Error())
}
ipam := new(types.NetworkIpam)
ipam.SetFQName("project", []string{"default-domain", "default-project", "default-network-ipam"})
err = m.Create(ipam)
if err != nil {
panic(err.Error())
}
}
示例3: TestConsistencyStaleVM
func TestConsistencyStaleVM(t *testing.T) {
env := new(TestFramework)
env.SetUp("192.0.2.0/24")
client := env.client
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
env.Start()
installPods(env, "testns", 3)
env.SyncBarrier()
env.Shutdown()
assert.True(t, env.checker.Check())
p2 := new(types.Project)
p2.SetFQName("domain", []string{"default-domain", "p2"})
assert.NoError(t, client.Create(p2))
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "p2", "x"})
assert.NoError(t, client.Create(vm))
assert.False(t, env.checker.Check())
assert.NoError(t, client.Delete(vm))
assert.True(t, env.checker.Check())
vm = new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "testns", "pod03"})
assert.NoError(t, client.Create(vm))
assert.False(t, env.checker.Check())
}
示例4: TestListByParent
func TestListByParent(t *testing.T) {
client := new(ApiClient)
client.Init()
projectNames := []string{"p1", "p2", "p3"}
vmNames := []string{"a", "b", "c", "d"}
for _, projectName := range projectNames {
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", projectName})
assert.NoError(t, client.Create(project))
for _, vmName := range vmNames {
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", projectName, vmName})
assert.NoError(t, client.Create(vm))
}
}
elements, err := client.ListByParent("virtual-machine", "default-domain:p2")
assert.NoError(t, err)
for _, element := range elements {
assert.Equal(t, "p2", element.Fq_name[1])
}
}
示例5: TestNamespaceDelete
func TestNamespaceDelete(t *testing.T) {
client := new(contrail_mocks.ApiClient)
client.Init()
allocator := new(mocks.AddressAllocator)
networkMgr := new(mocks.NetworkManager)
controller := NewTestController(nil, client, allocator, networkMgr)
namespace := &api.Namespace{
ObjectMeta: api.ObjectMeta{
Name: "netns",
UID: kubetypes.UID(uuid.New()),
},
}
project := new(types.Project)
project.SetFQName("domain", []string{DefaultDomain, "netns"})
project.SetUuid(string(namespace.ObjectMeta.UID))
client.Create(project)
shutdown := make(chan struct{})
go controller.Run(shutdown)
controller.DeleteNamespace(namespace)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
_, err := client.FindByUuid("project", string(namespace.ObjectMeta.UID))
assert.NotNil(t, err)
}
示例6: TestConsistencyStaleInterface
func TestConsistencyStaleInterface(t *testing.T) {
client := createTestClient()
podStore := new(mocks.Store)
serviceStore := new(mocks.Store)
checker := NewConsistencyChecker(client, NewConfig(), podStore, serviceStore, nil)
kube := mocks.NewKubeClient()
controller := NewTestController(kube, client, nil, nil)
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
installPods(controller, &kube.PodInterface.Mock, &podStore.Mock, "testns", 3)
shutdown := make(chan struct{})
go controller.Run(shutdown)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
time.Sleep(100 * time.Millisecond)
serviceStore.On("List").Return([]interface{}{})
assert.True(t, checker.Check())
vmi := new(types.VirtualMachineInterface)
vmi.SetFQName("project", []string{"default-domain", "testns", "pod03"})
assert.NoError(t, client.Create(vmi))
assert.False(t, checker.Check())
}
示例7: TestConsistencyMissingInterface
func TestConsistencyMissingInterface(t *testing.T) {
env := new(TestFramework)
env.SetUp("192.0.2.0/24")
client := env.client
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
env.Start()
installPods(env, "testns", 3)
env.SyncBarrier()
env.Shutdown()
assert.True(t, env.checker.Check())
vmi, err := types.VirtualMachineInterfaceByName(client, "default-domain:testns:pod01")
assert.NoError(t, err)
refs, err := vmi.GetInstanceIpBackRefs()
for _, ref := range refs {
ip, err := types.InstanceIpByUuid(client, ref.Uuid)
assert.NoError(t, err)
ip.ClearVirtualMachineInterface()
assert.NoError(t, client.Update(ip))
}
assert.NoError(t, client.Delete(vmi))
assert.False(t, env.checker.Check())
}
示例8: TestPodUsesNonExistingService
func TestPodUsesNonExistingService(t *testing.T) {
kube := mocks.NewKubeClient()
client := new(contrail_mocks.ApiClient)
client.Init()
client.AddInterceptor("virtual-machine-interface", &VmiInterceptor{})
client.AddInterceptor("virtual-network", &NetworkInterceptor{})
allocator := new(mocks.AddressAllocator)
controller := NewTestController(kube, client, allocator, nil)
pod1 := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "test-xz1",
Namespace: "testns",
UID: kubetypes.UID(uuid.New()),
Labels: map[string]string{
"name": "testpod",
"uses": "nonexisting",
},
},
}
netnsProject := new(types.Project)
netnsProject.SetFQName("", []string{"default-domain", "testns"})
client.Create(netnsProject)
allocator.On("LocateIpAddress", string(pod1.ObjectMeta.UID)).Return("10.0.0.1", nil)
allocator.On("ReleaseIpAddress", string(pod1.ObjectMeta.UID)).Return()
kube.PodInterface.On("Update", pod1).Return(pod1, nil)
shutdown := make(chan struct{})
go controller.Run(shutdown)
controller.AddPod(pod1)
time.Sleep(100 * time.Millisecond)
_, err := types.NetworkPolicyByName(client, "default-domain:testns:nonexisting")
assert.NoError(t, err)
_, err = types.VirtualNetworkByName(client, "default-domain:testns:testpod")
assert.NoError(t, err)
controller.DeletePod(pod1)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
_, err = types.VirtualNetworkByName(client, "default-domain:testns:testpod")
assert.Error(t, err)
_, err = types.NetworkPolicyByName(client, "default-domain:testns:nonexisting")
assert.Error(t, err)
allocator.AssertExpectations(t)
}
示例9: SetUp
func (t *TestFramework) SetUp(publicSubnet string) {
t.client = new(contrail_mocks.ApiClient)
t.client.Init()
t.client.AddInterceptor("virtual-machine-interface", &VmiInterceptor{})
t.client.AddInterceptor("virtual-network", &NetworkInterceptor{})
t.client.AddInterceptor("instance-ip", &IpInterceptor{})
t.client.AddInterceptor("floating-ip", &FloatingIpInterceptor{})
t.podStore = new(mocks.Store)
t.serviceStore = new(mocks.Store)
t.kubeMock = mocks.NewKubeClient()
t.config = NewConfig()
t.config.PublicSubnet = publicSubnet
t.controller = makeSyncController(t.kubeMock, t.config)
t.controller.SetPodStore(t.podStore)
t.controller.SetServiceStore(t.serviceStore)
t.controller.initComponents(t.client)
t.checker = t.controller.newConsistencyChecker()
for _, projectName := range testProjects {
project := new(types.Project)
project.SetFQName("domain", []string{t.config.DefaultDomain, projectName})
t.client.Create(project)
}
t.state = make(map[string]*TestGroupState, 0)
t.clusterIPs = make(map[int]string, 0)
t.keyList = make([]string, 0)
t.shutdown = make(chan struct{})
keysCall := t.podStore.On("ListKeys").Return()
keysCall.Run(func(arg mock.Arguments) {
keysCall.Return(t.keyList)
})
listCall := t.serviceStore.On("List").Return()
listCall.Run(func(arg mock.Arguments) {
serviceList := make([]interface{}, 0)
for _, v := range t.state {
for _, svc := range v.Services {
serviceList = append(serviceList, svc)
}
}
listCall.Return(serviceList)
})
}
示例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)
}
示例11: LocateNamespace
func (m *NamespaceManager) LocateNamespace(name, uid string) *types.Project {
fqn := []string{DefaultDomain, name}
obj, err := m.client.FindByName("project", strings.Join(fqn, ":"))
if err == nil {
return obj.(*types.Project)
}
project := new(types.Project)
project.SetFQName("domain", fqn)
project.SetUuid(uid)
err = m.client.Create(project)
if err != nil {
glog.Errorf("Create project %s: %v", name, err)
}
return project
}
示例12: 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)
}
示例13: TestNetworkLocate
func TestNetworkLocate(t *testing.T) {
client := new(contrail_mocks.ApiClient)
client.Init()
config := new(Config)
config.PublicNetwork = "default-domain:default-project:Public"
netman := NewNetworkManager(client, config)
project := new(types.Project)
project.SetUuid(uuid.New())
project.SetFQName("", []string{config.DefaultDomain, "p1"})
client.Create(project)
network, err := netman.LocateNetwork("p1", "n1", "10.0.1.0/24")
assert.NoError(t, err, "LocateNetwork")
n2, err := netman.LocateNetwork("p1", "n1", "10.0.1.0/24")
assert.NoError(t, err, "LocateNetwork -- exists")
assert.Equal(t, network, n2)
}
示例14: TestConsistencyMissingInterface
func TestConsistencyMissingInterface(t *testing.T) {
client := createTestClient()
podStore := new(mocks.Store)
serviceStore := new(mocks.Store)
checker := NewConsistencyChecker(client, NewConfig(), podStore, serviceStore, nil)
kube := mocks.NewKubeClient()
controller := NewTestController(kube, client, nil, nil)
netnsProject := new(types.Project)
netnsProject.SetFQName("domain", []string{"default-domain", "testns"})
client.Create(netnsProject)
installPods(controller, &kube.PodInterface.Mock, &podStore.Mock, "testns", 3)
shutdown := make(chan struct{})
go controller.Run(shutdown)
time.Sleep(100 * time.Millisecond)
type shutdownMsg struct {
}
shutdown <- shutdownMsg{}
time.Sleep(100 * time.Millisecond)
serviceStore.On("List").Return([]interface{}{})
assert.True(t, checker.Check())
vmi, err := types.VirtualMachineInterfaceByName(client, "default-domain:testns:pod01")
assert.NoError(t, err)
refs, err := vmi.GetInstanceIpBackRefs()
for _, ref := range refs {
ip, err := types.InstanceIpByUuid(client, ref.Uuid)
assert.NoError(t, err)
ip.ClearVirtualMachineInterface()
assert.NoError(t, client.Update(ip))
}
assert.NoError(t, client.Delete(vmi))
assert.False(t, checker.Check())
}
示例15: TestUpdateClearVM
func TestUpdateClearVM(t *testing.T) {
client := new(ApiClient)
client.Init()
project := new(types.Project)
project.SetFQName("domain", []string{"default-domain", "tenant"})
assert.NoError(t, client.Create(project))
vm := new(types.VirtualMachine)
vm.SetFQName("project", []string{"default-domain", "tenant", "instance"})
assert.NoError(t, client.Create(vm))
vmi := new(types.VirtualMachineInterface)
vmi.SetFQName("project", []string{"default-domain", "tenant", "instance"})
vmi.AddVirtualMachine(vm)
assert.NoError(t, client.Create(vmi))
vmi.ClearVirtualMachine()
assert.NoError(t, client.Update(vmi))
assert.NoError(t, client.Delete(vm))
}