Skip to content
This repository was archived by the owner on Nov 29, 2017. It is now read-only.

Commit 026e161

Browse files
committed
service load balancer
1 parent 1d248ed commit 026e161

5 files changed

+545
-95
lines changed

client/contivModel.js

+65
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,71 @@ var ServiceInstanceModalView = React.createClass({
676676

677677
module.exports.ServiceInstanceSummaryView = ServiceInstanceSummaryView
678678
module.exports.ServiceInstanceModalView = ServiceInstanceModalView
679+
var ServiceLBSummaryView = React.createClass({
680+
render: function() {
681+
var self = this
682+
683+
// Walk thru all objects
684+
var ServiceLBListView = self.props.ServiceLBs.map(function(ServiceLB){
685+
return (
686+
<ModalTrigger modal={<ServiceLBModalView ServiceLB={ ServiceLB }/>}>
687+
<tr key={ ServiceLB.key } className="info">
688+
689+
690+
</tr>
691+
</ModalTrigger>
692+
);
693+
});
694+
695+
return (
696+
<div>
697+
<Table hover>
698+
<thead>
699+
<tr>
700+
701+
702+
</tr>
703+
</thead>
704+
<tbody>
705+
{ ServiceLBListView }
706+
</tbody>
707+
</Table>
708+
</div>
709+
);
710+
}
711+
});
712+
713+
var ServiceLBModalView = React.createClass({
714+
render() {
715+
var obj = this.props.ServiceLB
716+
return (
717+
<Modal {...this.props} bsStyle='primary' bsSize='large' title='ServiceLB' animation={false}>
718+
<div className='modal-body' style={ {margin: '5%',} }>
719+
720+
721+
<Input type='text' label='Service ip' ref='ipAddress' defaultValue={obj.ipAddress} placeholder='Service ip' />
722+
723+
<Input type='text' label='labels key value pair' ref='labels' defaultValue={obj.labels} placeholder='labels key value pair' />
724+
725+
<Input type='text' label='Service subnet' ref='network' defaultValue={obj.network} placeholder='Service subnet' />
726+
727+
<Input type='text' label='service provider port' ref='ports' defaultValue={obj.ports} placeholder='service provider port' />
728+
729+
<Input type='text' label='service name' ref='serviceName' defaultValue={obj.serviceName} placeholder='service name' />
730+
731+
<Input type='text' label='Tenant Name' ref='tenantName' defaultValue={obj.tenantName} placeholder='Tenant Name' />
732+
733+
</div>
734+
<div className='modal-footer'>
735+
<Button onClick={this.props.onRequestHide}>Close</Button>
736+
</div>
737+
</Modal>
738+
);
739+
}
740+
});
741+
742+
module.exports.ServiceLBSummaryView = ServiceLBSummaryView
743+
module.exports.ServiceLBModalView = ServiceLBModalView
679744
var TenantSummaryView = React.createClass({
680745
render: function() {
681746
var self = this

client/contivModelClient.go

+78
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ type ServiceInstanceLinks struct {
349349
Service Link `json:"Service,omitempty"`
350350
}
351351

352+
type ServiceLB struct {
353+
// every object has a key
354+
Key string `json:"key,omitempty"`
355+
356+
IpAddress string `json:"ipAddress,omitempty"` // Service ip
357+
Labels []string `json:"labels,omitempty"`
358+
Network string `json:"network,omitempty"` // Service subnet
359+
Ports []string `json:"ports,omitempty"`
360+
ServiceName string `json:"serviceName,omitempty"` // service name
361+
TenantName string `json:"tenantName,omitempty"` // Tenant Name
362+
363+
}
364+
352365
type Tenant struct {
353366
// every object has a key
354367
Key string `json:"key,omitempty"`
@@ -1002,6 +1015,71 @@ func (c *ContivClient) ServiceInstanceDelete(tenantName string, appName string,
10021015
return nil
10031016
}
10041017

1018+
// ServiceLBPost posts the ServiceLB object
1019+
func (c *ContivClient) ServiceLBPost(obj *ServiceLB) error {
1020+
// build key and URL
1021+
keyStr := obj.ServiceName + ":" + obj.TenantName
1022+
url := c.baseURL + "/api/ServiceLBs/" + keyStr + "/"
1023+
1024+
// http post the object
1025+
err := httpPost(url, obj)
1026+
if err != nil {
1027+
log.Debugf("Error creating ServiceLB %+v. Err: %v", obj, err)
1028+
return err
1029+
}
1030+
1031+
return nil
1032+
}
1033+
1034+
// ServiceLBList lists all ServiceLB objects
1035+
func (c *ContivClient) ServiceLBList() (*[]*ServiceLB, error) {
1036+
// build key and URL
1037+
url := c.baseURL + "/api/ServiceLBs/"
1038+
1039+
// http get the object
1040+
var objList []*ServiceLB
1041+
err := httpGet(url, &objList)
1042+
if err != nil {
1043+
log.Debugf("Error getting ServiceLBs. Err: %v", err)
1044+
return nil, err
1045+
}
1046+
1047+
return &objList, nil
1048+
}
1049+
1050+
// ServiceLBGet gets the ServiceLB object
1051+
func (c *ContivClient) ServiceLBGet(serviceName string, tenantName string) (*ServiceLB, error) {
1052+
// build key and URL
1053+
keyStr := serviceName + ":" + tenantName
1054+
url := c.baseURL + "/api/ServiceLBs/" + keyStr + "/"
1055+
1056+
// http get the object
1057+
var obj ServiceLB
1058+
err := httpGet(url, &obj)
1059+
if err != nil {
1060+
log.Debugf("Error getting ServiceLB %+v. Err: %v", keyStr, err)
1061+
return nil, err
1062+
}
1063+
1064+
return &obj, nil
1065+
}
1066+
1067+
// ServiceLBDelete deletes the ServiceLB object
1068+
func (c *ContivClient) ServiceLBDelete(serviceName string, tenantName string) error {
1069+
// build key and URL
1070+
keyStr := serviceName + ":" + tenantName
1071+
url := c.baseURL + "/api/ServiceLBs/" + keyStr + "/"
1072+
1073+
// http get the object
1074+
err := httpDelete(url)
1075+
if err != nil {
1076+
log.Debugf("Error deleting ServiceLB %s. Err: %v", keyStr, err)
1077+
return err
1078+
}
1079+
1080+
return nil
1081+
}
1082+
10051083
// TenantPost posts the tenant object
10061084
func (c *ContivClient) TenantPost(obj *Tenant) error {
10071085
// build key and URL

client/contivModelClient.py

+47-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, baseUrl):
7474
self.baseUrl = baseUrl
7575
# Create appProfile
7676
def createAppProfile(self, obj):
77-
postUrl = self.baseUrl + '/api/appProfiles/' + obj.tenantName + ":" + obj.networkName + ":" + obj.appProfileName + '/'
77+
postUrl = self.baseUrl + '/api/AppProfiles/' + obj.tenantName + ":" + obj.networkName + ":" + obj.appProfileName + '/'
7878

7979
jdata = json.dumps({
8080
"appProfileName": obj.appProfileName,
@@ -108,7 +108,7 @@ def listAppProfile(self):
108108
return json.loads(retData)
109109
# Create endpointGroup
110110
def createEndpointGroup(self, obj):
111-
postUrl = self.baseUrl + '/api/endpointGroups/' + obj.tenantName + ":" + obj.networkName + ":" + obj.groupName + '/'
111+
postUrl = self.baseUrl + '/api/EndpointGroups/' + obj.tenantName + ":" + obj.networkName + ":" + obj.groupName + '/'
112112

113113
jdata = json.dumps({
114114
"endpointGroupId": obj.endpointGroupId,
@@ -143,7 +143,7 @@ def listEndpointGroup(self):
143143
return json.loads(retData)
144144
# Create global
145145
def createGlobal(self, obj):
146-
postUrl = self.baseUrl + '/api/globals/' + obj.name + '/'
146+
postUrl = self.baseUrl + '/api/Globals/' + obj.name + '/'
147147

148148
jdata = json.dumps({
149149
"name": obj.name,
@@ -212,7 +212,7 @@ def listBgp(self):
212212
return json.loads(retData)
213213
# Create network
214214
def createNetwork(self, obj):
215-
postUrl = self.baseUrl + '/api/networks/' + obj.tenantName + ":" + obj.networkName + '/'
215+
postUrl = self.baseUrl + '/api/Networks/' + obj.tenantName + ":" + obj.networkName + '/'
216216

217217
jdata = json.dumps({
218218
"encap": obj.encap,
@@ -248,7 +248,7 @@ def listNetwork(self):
248248
return json.loads(retData)
249249
# Create policy
250250
def createPolicy(self, obj):
251-
postUrl = self.baseUrl + '/api/policys/' + obj.tenantName + ":" + obj.policyName + '/'
251+
postUrl = self.baseUrl + '/api/Policys/' + obj.tenantName + ":" + obj.policyName + '/'
252252

253253
jdata = json.dumps({
254254
"policyName": obj.policyName,
@@ -280,7 +280,7 @@ def listPolicy(self):
280280
return json.loads(retData)
281281
# Create rule
282282
def createRule(self, obj):
283-
postUrl = self.baseUrl + '/api/rules/' + obj.tenantName + ":" + obj.policyName + ":" + obj.ruleId + '/'
283+
postUrl = self.baseUrl + '/api/Rules/' + obj.tenantName + ":" + obj.policyName + ":" + obj.ruleId + '/'
284284

285285
jdata = json.dumps({
286286
"action": obj.action,
@@ -324,7 +324,7 @@ def listRule(self):
324324
return json.loads(retData)
325325
# Create service
326326
def createService(self, obj):
327-
postUrl = self.baseUrl + '/api/services/' + obj.tenantName + ":" + obj.appName + ":" + obj.serviceName + '/'
327+
postUrl = self.baseUrl + '/api/Services/' + obj.tenantName + ":" + obj.appName + ":" + obj.serviceName + '/'
328328

329329
jdata = json.dumps({
330330
"appName": obj.appName,
@@ -366,7 +366,7 @@ def listService(self):
366366
return json.loads(retData)
367367
# Create serviceInstance
368368
def createServiceInstance(self, obj):
369-
postUrl = self.baseUrl + '/api/serviceInstances/' + obj.tenantName + ":" + obj.appName + ":" + obj.serviceName + ":" + obj.instanceId + '/'
369+
postUrl = self.baseUrl + '/api/ServiceInstances/' + obj.tenantName + ":" + obj.appName + ":" + obj.serviceName + ":" + obj.instanceId + '/'
370370

371371
jdata = json.dumps({
372372
"appName": obj.appName,
@@ -398,10 +398,46 @@ def listServiceInstance(self):
398398
if retData == "Error":
399399
errorExit("list ServiceInstance failed")
400400

401+
return json.loads(retData)
402+
# Create ServiceLB
403+
def createServiceLB(self, obj):
404+
postUrl = self.baseUrl + '/api/ServiceLBs/' + obj.serviceName + ":" + obj.tenantName + '/'
405+
406+
jdata = json.dumps({
407+
"ipAddress": obj.ipAddress,
408+
"labels": obj.labels,
409+
"network": obj.network,
410+
"ports": obj.ports,
411+
"serviceName": obj.serviceName,
412+
"tenantName": obj.tenantName,
413+
})
414+
415+
# Post the data
416+
response = httpPost(postUrl, jdata)
417+
418+
if response == "Error":
419+
errorExit("ServiceLB create failure")
420+
421+
# Delete ServiceLB
422+
def deleteServiceLB(self, serviceName, tenantName):
423+
# Delete ServiceLB
424+
deleteUrl = self.baseUrl + '/api/ServiceLBs/' + serviceName + ":" + tenantName + '/'
425+
response = httpDelete(deleteUrl)
426+
427+
if response == "Error":
428+
errorExit("ServiceLB create failure")
429+
430+
# List all ServiceLB objects
431+
def listServiceLB(self):
432+
# Get a list of ServiceLB objects
433+
retDate = urllib2.urlopen(self.baseUrl + '/api/ServiceLBs/')
434+
if retData == "Error":
435+
errorExit("list ServiceLB failed")
436+
401437
return json.loads(retData)
402438
# Create tenant
403439
def createTenant(self, obj):
404-
postUrl = self.baseUrl + '/api/tenants/' + obj.tenantName + '/'
440+
postUrl = self.baseUrl + '/api/Tenants/' + obj.tenantName + '/'
405441

406442
jdata = json.dumps({
407443
"defaultNetwork": obj.defaultNetwork,
@@ -433,7 +469,7 @@ def listTenant(self):
433469
return json.loads(retData)
434470
# Create volume
435471
def createVolume(self, obj):
436-
postUrl = self.baseUrl + '/api/volumes/' + obj.tenantName + ":" + obj.volumeName + '/'
472+
postUrl = self.baseUrl + '/api/Volumes/' + obj.tenantName + ":" + obj.volumeName + '/'
437473

438474
jdata = json.dumps({
439475
"datastoreType": obj.datastoreType,
@@ -469,7 +505,7 @@ def listVolume(self):
469505
return json.loads(retData)
470506
# Create volumeProfile
471507
def createVolumeProfile(self, obj):
472-
postUrl = self.baseUrl + '/api/volumeProfiles/' + obj.tenantName + ":" + obj.volumeProfileName + '/'
508+
postUrl = self.baseUrl + '/api/VolumeProfiles/' + obj.tenantName + ":" + obj.volumeProfileName + '/'
473509

474510
jdata = json.dumps({
475511
"datastoreType": obj.datastoreType,

0 commit comments

Comments
 (0)