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

Service load balancer contivmodel changes #19

Merged
merged 4 commits into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions client/contivModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,71 @@ var ServiceInstanceModalView = React.createClass({

module.exports.ServiceInstanceSummaryView = ServiceInstanceSummaryView
module.exports.ServiceInstanceModalView = ServiceInstanceModalView
var ServiceLBSummaryView = React.createClass({
render: function() {
var self = this

// Walk thru all objects
var serviceLBListView = self.props.serviceLBs.map(function(serviceLB){
return (
<ModalTrigger modal={<ServiceLBModalView serviceLB={ serviceLB }/>}>
<tr key={ serviceLB.key } className="info">


</tr>
</ModalTrigger>
);
});

return (
<div>
<Table hover>
<thead>
<tr>


</tr>
</thead>
<tbody>
{ serviceLBListView }
</tbody>
</Table>
</div>
);
}
});

var ServiceLBModalView = React.createClass({
render() {
var obj = this.props.serviceLB
return (
<Modal {...this.props} bsStyle='primary' bsSize='large' title='ServiceLB' animation={false}>
<div className='modal-body' style={ {margin: '5%',} }>


<Input type='text' label='Service ip' ref='ipAddress' defaultValue={obj.ipAddress} placeholder='Service ip' />

<Input type='text' label='Service network name' ref='network' defaultValue={obj.network} placeholder='Service network name' />

<Input type='text' label='service provider port' ref='ports' defaultValue={obj.ports} placeholder='service provider port' />

<Input type='text' label='labels key value pair' ref='selectors' defaultValue={obj.selectors} placeholder='labels key value pair' />

<Input type='text' label='service name' ref='serviceName' defaultValue={obj.serviceName} placeholder='service name' />

<Input type='text' label='Tenant Name' ref='tenantName' defaultValue={obj.tenantName} placeholder='Tenant Name' />

</div>
<div className='modal-footer'>
<Button onClick={this.props.onRequestHide}>Close</Button>
</div>
</Modal>
);
}
});

module.exports.ServiceLBSummaryView = ServiceLBSummaryView
module.exports.ServiceLBModalView = ServiceLBModalView
var TenantSummaryView = React.createClass({
render: function() {
var self = this
Expand Down
86 changes: 86 additions & 0 deletions client/contivModelClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ type Network struct {
type NetworkLinkSets struct {
AppProfiles map[string]Link `json:"AppProfiles,omitempty"`
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
Servicelbs map[string]Link `json:"Servicelbs,omitempty"`
Services map[string]Link `json:"Services,omitempty"`
}

Expand Down Expand Up @@ -349,6 +350,25 @@ type ServiceInstanceLinks struct {
Service Link `json:"Service,omitempty"`
}

type ServiceLB struct {
// every object has a key
Key string `json:"key,omitempty"`

IpAddress string `json:"ipAddress,omitempty"` // Service ip
Network string `json:"network,omitempty"` // Service network name
Ports []string `json:"ports,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "Ports" encode the protocol as well? Like tcp:80 udp:5550 etc?

Selectors []string `json:"selectors,omitempty"`
ServiceName string `json:"serviceName,omitempty"` // service name
TenantName string `json:"tenantName,omitempty"` // Tenant Name

Links ServiceLBLinks `json:"links,omitempty"`
}

type ServiceLBLinks struct {
Network Link `json:"Network,omitempty"`
Tenant Link `json:"Tenant,omitempty"`
}

type Tenant struct {
// every object has a key
Key string `json:"key,omitempty"`
Expand All @@ -365,6 +385,7 @@ type TenantLinkSets struct {
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
Networks map[string]Link `json:"Networks,omitempty"`
Policies map[string]Link `json:"Policies,omitempty"`
Servicelbs map[string]Link `json:"Servicelbs,omitempty"`
VolumeProfiles map[string]Link `json:"VolumeProfiles,omitempty"`
Volumes map[string]Link `json:"Volumes,omitempty"`
}
Expand Down Expand Up @@ -1002,6 +1023,71 @@ func (c *ContivClient) ServiceInstanceDelete(tenantName string, appName string,
return nil
}

// ServiceLBPost posts the serviceLB object
func (c *ContivClient) ServiceLBPost(obj *ServiceLB) error {
// build key and URL
keyStr := obj.ServiceName + ":" + obj.TenantName
url := c.baseURL + "/api/serviceLBs/" + keyStr + "/"

// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating serviceLB %+v. Err: %v", obj, err)
return err
}

return nil
}

// ServiceLBList lists all serviceLB objects
func (c *ContivClient) ServiceLBList() (*[]*ServiceLB, error) {
// build key and URL
url := c.baseURL + "/api/serviceLBs/"

// http get the object
var objList []*ServiceLB
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting serviceLBs. Err: %v", err)
return nil, err
}

return &objList, nil
}

// ServiceLBGet gets the serviceLB object
func (c *ContivClient) ServiceLBGet(serviceName string, tenantName string) (*ServiceLB, error) {
// build key and URL
keyStr := serviceName + ":" + tenantName
url := c.baseURL + "/api/serviceLBs/" + keyStr + "/"

// http get the object
var obj ServiceLB
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting serviceLB %+v. Err: %v", keyStr, err)
return nil, err
}

return &obj, nil
}

// ServiceLBDelete deletes the serviceLB object
func (c *ContivClient) ServiceLBDelete(serviceName string, tenantName string) error {
// build key and URL
keyStr := serviceName + ":" + tenantName
url := c.baseURL + "/api/serviceLBs/" + keyStr + "/"

// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting serviceLB %s. Err: %v", keyStr, err)
return err
}

return nil
}

// TenantPost posts the tenant object
func (c *ContivClient) TenantPost(obj *Tenant) error {
// build key and URL
Expand Down
37 changes: 37 additions & 0 deletions client/contivModelClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def createNetwork(self, obj):
"encap": obj.encap,
"gateway": obj.gateway,
"networkName": obj.networkName,
"nwType": obj.nwType,
"pktTag": obj.pktTag,
"subnet": obj.subnet,
"tenantName": obj.tenantName,
Expand Down Expand Up @@ -398,6 +399,42 @@ def listServiceInstance(self):
if retData == "Error":
errorExit("list ServiceInstance failed")

return json.loads(retData)
# Create serviceLB
def createServiceLB(self, obj):
postUrl = self.baseUrl + '/api/serviceLBs/' + obj.serviceName + ":" + obj.tenantName + '/'

jdata = json.dumps({
"ipAddress": obj.ipAddress,
"network": obj.network,
"ports": obj.ports,
"selectors": obj.selectors,
"serviceName": obj.serviceName,
"tenantName": obj.tenantName,
})

# Post the data
response = httpPost(postUrl, jdata)

if response == "Error":
errorExit("ServiceLB create failure")

# Delete serviceLB
def deleteServiceLB(self, serviceName, tenantName):
# Delete ServiceLB
deleteUrl = self.baseUrl + '/api/serviceLBs/' + serviceName + ":" + tenantName + '/'
response = httpDelete(deleteUrl)

if response == "Error":
errorExit("ServiceLB create failure")

# List all serviceLB objects
def listServiceLB(self):
# Get a list of serviceLB objects
retDate = urllib2.urlopen(self.baseUrl + '/api/serviceLBs/')
if retData == "Error":
errorExit("list ServiceLB failed")

return json.loads(retData)
# Create tenant
def createTenant(self, obj):
Expand Down
Loading