-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdoc.go
139 lines (110 loc) · 4.12 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Package libvrsdk enables interaction of userspace applications with Nuage VRS.
Concepts
The package introduces the concepts of virtual entity (which represents a VM or a container) and a port
which represent the network endpoint for the virtual entity. A userspace application first establishes a connection
to the VRS and gets a handle for it. Using the connection handle the app can call methods to notify
the VRS about the virtual entities and their associated network ports that need to be managed by Nuage VSP.
The Nuage VRS SDK is event driven. The application needs to first create ports, followed by creation of the entity
object. The application then needs to manage the lifecycle of the virtual entity and it's associated ports by
sending VRS different events. The following unit test examples show how to handle the life cycle of VM ports using the
SDK.
Examples
const UnixSocketFile = "/var/run/openvswitch/db.sock"
// TestAddition tests that a VM and an associated port is added to VRS successfully
func TestAddition(t *testing.T) {
var vrsConnection VRSConnection
var err error
if vrsConnection, err = NewUnixSocketConnection(UnixSocketFile); err != nil {
t.Fatal("Unable to connect to the VRS")
}
// Create Port Attributes
portAttributes := port.Attributes{
Platform: port.PlatformDocker,
MAC: MAC,
Bridge: Bridge,
}
// Create Port Metadata
portMetadata := make(map[port.MetadataKey]string)
portMetadata[port.MetadataKeyDomain] = Domain
portMetadata[port.MetadataKeyNetwork] = Network
portMetadata[port.MetadataKeyZone] = Zone
portMetadata[port.MetadataKeyPg] = "pg"
portMetadata[port.MetadataKeyStaticIP] = "192.168.100.101"
// Add port to VRS
err = vrsConnection.CreatePort(PortName, portAttributes, portMetadata)
if err != nil {
t.Fatal("Unable to add port the VRS")
}
// Create VM metadata
vmMetadata := make(map[entity.MetadataKey]string)
vmMetadata[entity.MetadataKeyUser] = User
vmMetadata[entity.MetadataKeyUser] = Enterprise
// Define ports associated with the VM
ports := []string{PortName}
// Add entity to the VRS
entityInfo := EntityInfo{
UUID: VMUUID,
Name: "TestVM",
Type: entity.NuageEntityTypeLXC,
Ports: ports,
Metadata: vmMetadata,
}
err = vrsConnection.AddEntity(entityInfo)
if err != nil {
t.Fatal("Unable to add entity to VRS")
}
// Notify VRS that VM has completed booted
err = vrsConnection.PostEntityEvent(VMUUID, entity.EventCategoryStarted,
entity.EventStartedBooted)
if err != nil {
t.Fatal("Problem sending VRS notification")
}
err = vrsConnection.Disconnect()
if err != nil {
t.Fatal("Problem disconnecting from VRS")
}
}
// TestStopped tests that a VM is stopped for migration
func TestStopped(t *testing.T) {
var vrsConnection VRSConnection
var err error
if vrsConnection, err = NewConnection(VrsHost, VrsPort); err != nil {
t.Fatal("Unable to connect to the VRS")
}
// Notify VRS about an existing entity being stopped for migration
err = vrsConnection.PostEntityEvent(VMUUID, entity.EventCategoryStopped,
entity.EventStoppedMigrated)
if err != nil {
t.Fatal("VRS notification failed")
}
}
// TestStartedForMigration tests VM migration on the destination
func TestStartedForMigration(t *testing.T) {
var vrsConnection VRSConnection
var err error
if vrsConnection, err = NewConnection(VrsHost, VrsPort); err != nil {
t.Fatal("Unable to connect to the VRS")
}
// Notify VRS about a migrated VM. Note the entity needs to be added before sending the started event
err = vrsConnection.PostEntityEvent(VMUUID, entity.EventCategoryStarted,
entity.EventStartedMigrated)
if err != nil {
t.Fatal("VRS Notification failed")
}
}
// TestRemoval Tests successful removal of an entity from VRS
func TestRemoval(t *testing.T) {
var vrsConnection VRSConnection
var err error
if vrsConnection, err = NewConnection(VrsHost, VrsPort); err != nil {
t.Fatal("Unable to connect to the VRS")
}
// Remove the entity
err = vrsConnection.RemoveEntity(VMUUID)
if err != nil {
t.Fatal("Unable to remove the entity")
}
}
*/
package libvrsdk