本文整理匯總了Golang中github.com/Juniper/contrail-go-api/types.Project類的典型用法代碼示例。如果您正苦於以下問題:Golang Project類的具體用法?Golang Project怎麽用?Golang Project使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Project類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: 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)
}
示例3: 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())
}
示例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: getNetworkUuidByName
func getNetworkUuidByName(
client *contrail.Client, project_name, project_id, name string) (
string, error) {
var fqn []string
if len(project_id) > 0 {
uuid := strings.ToLower(project_id)
if !config.IsUuid(uuid) {
fmt.Fprintf(os.Stderr,
"Invalid project-id value: %s\n", uuid)
os.Exit(2)
}
obj, err := client.FindByUuid("project", project_id)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(2)
}
fqn = obj.GetFQName()
} else {
fqn = strings.Split(project_name, ":")
if len(fqn) == 1 {
obj := new(types.Project)
fqn = append(obj.GetDefaultParent(), project_name)
}
}
fqn = append(fqn, name)
return client.UuidByName("virtual-network", strings.Join(fqn, ":"))
}
示例6: TestClient
func TestClient(t *testing.T) {
client := contrail.NewClient("localhost", 8082)
elements, err := client.List("project")
if err != nil {
t.Fatal(err)
}
if len(elements) < 1 {
t.Error("Empty project list")
}
for _, element := range elements {
obj, err := client.ReadListResult("project", &element)
if obj == nil {
t.Fatal(err)
}
var project *types.Project = obj.(*types.Project)
networks, err := project.GetVirtualNetworks()
if len(networks) < 1 {
t.Error("Empty virtual-network list")
}
for _, network := range networks {
iObj, err := client.ReadReference(
"virtual-network", &network)
if iObj == nil {
t.Fatal(err)
}
net := iObj.(*types.VirtualNetwork)
fmt.Println(net.GetName())
}
}
}
示例7: 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())
}
}
示例8: 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())
}
示例9: 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)
}
示例10: 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)
})
}
示例11: 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)
}
示例12: 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
}
示例13: 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)
}
示例14: GetProjectFQN
func GetProjectFQN(
client *contrail.Client, projectName string, projectId string) (
[]string, error) {
if len(projectId) > 0 {
uuid := strings.ToLower(projectId)
if !IsUuid(uuid) {
return nil,
fmt.Errorf("Invalid uuid value: %s\n", uuid)
}
return client.FQNameByUuid(uuid)
}
if strings.ContainsRune(projectName, ':') {
return strings.Split(projectName, ":"), nil
}
obj := new(types.Project)
return append(obj.GetDefaultParent(), projectName), nil
}
示例15: 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)
}