Skip to content

Commit 1c4b365

Browse files
reshmagiliyalVipin Jain
authored and
Vipin Jain
committed
Contivmodel (#31)
* Add netprofile object * merge * netprofile * epg changes * Contains netprofile changes * Contains netprofile changes for contivmodel
1 parent 93b0ee0 commit 1c4b365

8 files changed

+630
-11
lines changed

client/contivModel.js

+65-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ var EndpointGroupSummaryView = React.createClass({
187187
<ModalTrigger modal={<EndpointGroupModalView endpointGroup={ endpointGroup }/>}>
188188
<tr key={ endpointGroup.key } className="info">
189189

190-
190+
191191
</tr>
192192
</ModalTrigger>
193193
);
@@ -199,7 +199,7 @@ var EndpointGroupSummaryView = React.createClass({
199199
<thead>
200200
<tr>
201201

202-
202+
203203
</tr>
204204
</thead>
205205
<tbody>
@@ -223,6 +223,8 @@ var EndpointGroupModalView = React.createClass({
223223

224224
<Input type='text' label='Group name' ref='groupName' defaultValue={obj.groupName} placeholder='Group name' />
225225

226+
<Input type='text' label='Network profile name' ref='netProfile' defaultValue={obj.netProfile} placeholder='Network profile name' />
227+
226228
<Input type='text' label='Network' ref='networkName' defaultValue={obj.networkName} placeholder='Network' />
227229

228230
<Input type='text' label='Policies' ref='policies' defaultValue={obj.policies} placeholder='Policies' />
@@ -362,6 +364,67 @@ var GlobalModalView = React.createClass({
362364

363365
module.exports.GlobalSummaryView = GlobalSummaryView
364366
module.exports.GlobalModalView = GlobalModalView
367+
var NetprofileSummaryView = React.createClass({
368+
render: function() {
369+
var self = this
370+
371+
// Walk thru all objects
372+
var netprofileListView = self.props.netprofiles.map(function(netprofile){
373+
return (
374+
<ModalTrigger modal={<NetprofileModalView netprofile={ netprofile }/>}>
375+
<tr key={ netprofile.key } className="info">
376+
377+
378+
</tr>
379+
</ModalTrigger>
380+
);
381+
});
382+
383+
return (
384+
<div>
385+
<Table hover>
386+
<thead>
387+
<tr>
388+
389+
390+
</tr>
391+
</thead>
392+
<tbody>
393+
{ netprofileListView }
394+
</tbody>
395+
</Table>
396+
</div>
397+
);
398+
}
399+
});
400+
401+
var NetprofileModalView = React.createClass({
402+
render() {
403+
var obj = this.props.netprofile
404+
return (
405+
<Modal {...this.props} bsStyle='primary' bsSize='large' title='Netprofile' animation={false}>
406+
<div className='modal-body' style={ {margin: '5%',} }>
407+
408+
409+
<Input type='text' label='DSCP' ref='DSCP' defaultValue={obj.DSCP} placeholder='DSCP' />
410+
411+
<Input type='text' label='Allocated bandwidth' ref='bandwidth' defaultValue={obj.bandwidth} placeholder='Allocated bandwidth' />
412+
413+
<Input type='text' label='Network profile name' ref='profileName' defaultValue={obj.profileName} placeholder='Network profile name' />
414+
415+
<Input type='text' label='Tenant name' ref='tenantName' defaultValue={obj.tenantName} placeholder='Tenant name' />
416+
417+
</div>
418+
<div className='modal-footer'>
419+
<Button onClick={this.props.onRequestHide}>Close</Button>
420+
</div>
421+
</Modal>
422+
);
423+
}
424+
});
425+
426+
module.exports.NetprofileSummaryView = NetprofileSummaryView
427+
module.exports.NetprofileModalView = NetprofileModalView
365428
var NetworkSummaryView = React.createClass({
366429
render: function() {
367430
var self = this

client/contivModelClient.go

+111
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ type EndpointGroup struct {
214214

215215
ExtContractsGrps []string `json:"extContractsGrps,omitempty"`
216216
GroupName string `json:"groupName,omitempty"` // Group name
217+
NetProfile string `json:"netProfile,omitempty"` // Network profile name
217218
NetworkName string `json:"networkName,omitempty"` // Network
218219
Policies []string `json:"policies,omitempty"`
219220
TenantName string `json:"tenantName,omitempty"` // Tenant
@@ -231,6 +232,7 @@ type EndpointGroupLinkSets struct {
231232

232233
type EndpointGroupLinks struct {
233234
AppProfile Link `json:"AppProfile,omitempty"`
235+
NetProfile Link `json:"NetProfile,omitempty"`
234236
Network Link `json:"Network,omitempty"`
235237
Tenant Link `json:"Tenant,omitempty"`
236238
}
@@ -286,6 +288,32 @@ type GlobalInspect struct {
286288
Oper GlobalOper
287289
}
288290

291+
type Netprofile struct {
292+
// every object has a key
293+
Key string `json:"key,omitempty"`
294+
295+
DSCP int `json:"DSCP,omitempty"` // DSCP
296+
Bandwidth string `json:"bandwidth,omitempty"` // Allocated bandwidth
297+
ProfileName string `json:"profileName,omitempty"` // Network profile name
298+
TenantName string `json:"tenantName,omitempty"` // Tenant name
299+
300+
// add link-sets and links
301+
LinkSets NetprofileLinkSets `json:"link-sets,omitempty"`
302+
Links NetprofileLinks `json:"links,omitempty"`
303+
}
304+
305+
type NetprofileLinkSets struct {
306+
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
307+
}
308+
309+
type NetprofileLinks struct {
310+
Tenant Link `json:"Tenant,omitempty"`
311+
}
312+
313+
type NetprofileInspect struct {
314+
Config Netprofile
315+
}
316+
289317
type Network struct {
290318
// every object has a key
291319
Key string `json:"key,omitempty"`
@@ -435,6 +463,7 @@ type Tenant struct {
435463
type TenantLinkSets struct {
436464
AppProfiles map[string]Link `json:"AppProfiles,omitempty"`
437465
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
466+
NetProfiles map[string]Link `json:"NetProfiles,omitempty"`
438467
Networks map[string]Link `json:"Networks,omitempty"`
439468
Policies map[string]Link `json:"Policies,omitempty"`
440469
Servicelbs map[string]Link `json:"Servicelbs,omitempty"`
@@ -929,6 +958,88 @@ func (c *ContivClient) GlobalInspect(name string) (*GlobalInspect, error) {
929958
return &obj, nil
930959
}
931960

961+
// NetprofilePost posts the netprofile object
962+
func (c *ContivClient) NetprofilePost(obj *Netprofile) error {
963+
// build key and URL
964+
keyStr := obj.TenantName + ":" + obj.ProfileName
965+
url := c.baseURL + "/api/v1/netprofiles/" + keyStr + "/"
966+
967+
// http post the object
968+
err := httpPost(url, obj)
969+
if err != nil {
970+
log.Debugf("Error creating netprofile %+v. Err: %v", obj, err)
971+
return err
972+
}
973+
974+
return nil
975+
}
976+
977+
// NetprofileList lists all netprofile objects
978+
func (c *ContivClient) NetprofileList() (*[]*Netprofile, error) {
979+
// build key and URL
980+
url := c.baseURL + "/api/v1/netprofiles/"
981+
982+
// http get the object
983+
var objList []*Netprofile
984+
err := httpGet(url, &objList)
985+
if err != nil {
986+
log.Debugf("Error getting netprofiles. Err: %v", err)
987+
return nil, err
988+
}
989+
990+
return &objList, nil
991+
}
992+
993+
// NetprofileGet gets the netprofile object
994+
func (c *ContivClient) NetprofileGet(tenantName string, profileName string) (*Netprofile, error) {
995+
// build key and URL
996+
keyStr := tenantName + ":" + profileName
997+
url := c.baseURL + "/api/v1/netprofiles/" + keyStr + "/"
998+
999+
// http get the object
1000+
var obj Netprofile
1001+
err := httpGet(url, &obj)
1002+
if err != nil {
1003+
log.Debugf("Error getting netprofile %+v. Err: %v", keyStr, err)
1004+
return nil, err
1005+
}
1006+
1007+
return &obj, nil
1008+
}
1009+
1010+
// NetprofileDelete deletes the netprofile object
1011+
func (c *ContivClient) NetprofileDelete(tenantName string, profileName string) error {
1012+
// build key and URL
1013+
keyStr := tenantName + ":" + profileName
1014+
url := c.baseURL + "/api/v1/netprofiles/" + keyStr + "/"
1015+
1016+
// http get the object
1017+
err := httpDelete(url)
1018+
if err != nil {
1019+
log.Debugf("Error deleting netprofile %s. Err: %v", keyStr, err)
1020+
return err
1021+
}
1022+
1023+
return nil
1024+
}
1025+
1026+
// NetprofileInspect gets the netprofileInspect object
1027+
func (c *ContivClient) NetprofileInspect(tenantName string, profileName string) (*NetprofileInspect, error) {
1028+
// build key and URL
1029+
keyStr := tenantName + ":" + profileName
1030+
url := c.baseURL + "/api/v1/inspect/netprofiles/" + keyStr + "/"
1031+
1032+
// http get the object
1033+
var obj NetprofileInspect
1034+
err := httpGet(url, &obj)
1035+
if err != nil {
1036+
log.Debugf("Error getting netprofile %+v. Err: %v", keyStr, err)
1037+
return nil, err
1038+
}
1039+
1040+
return &obj, nil
1041+
}
1042+
9321043
// NetworkPost posts the network object
9331044
func (c *ContivClient) NetworkPost(obj *Network) error {
9341045
// build key and URL

client/contivModelClient.py

+39
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def createEndpointGroup(self, obj):
169169
jdata = json.dumps({
170170
"extContractsGrps": obj.extContractsGrps,
171171
"groupName": obj.groupName,
172+
"netProfile": obj.netProfile,
172173
"networkName": obj.networkName,
173174
"policies": obj.policies,
174175
"tenantName": obj.tenantName,
@@ -287,6 +288,44 @@ def createGlobal(self, obj):
287288
return json.loads(retData)
288289

289290

291+
# Create netprofile
292+
def createNetprofile(self, obj):
293+
postUrl = self.baseUrl + '/api/v1/netprofiles/' + obj.tenantName + ":" + obj.profileName + '/'
294+
295+
jdata = json.dumps({
296+
"DSCP": obj.DSCP,
297+
"bandwidth": obj.bandwidth,
298+
"profileName": obj.profileName,
299+
"tenantName": obj.tenantName,
300+
})
301+
302+
# Post the data
303+
response = httpPost(postUrl, jdata)
304+
305+
if response == "Error":
306+
errorExit("Netprofile create failure")
307+
308+
# Delete netprofile
309+
def deleteNetprofile(self, tenantName, profileName):
310+
# Delete Netprofile
311+
deleteUrl = self.baseUrl + '/api/v1/netprofiles/' + tenantName + ":" + profileName + '/'
312+
response = httpDelete(deleteUrl)
313+
314+
if response == "Error":
315+
errorExit("Netprofile create failure")
316+
317+
# List all netprofile objects
318+
def listNetprofile(self):
319+
# Get a list of netprofile objects
320+
retDate = urllib2.urlopen(self.baseUrl + '/api/v1/netprofiles/')
321+
if retData == "Error":
322+
errorExit("list Netprofile failed")
323+
324+
return json.loads(retData)
325+
326+
327+
328+
290329
# Create network
291330
def createNetwork(self, obj):
292331
postUrl = self.baseUrl + '/api/v1/networks/' + obj.tenantName + ":" + obj.networkName + '/'

0 commit comments

Comments
 (0)