Skip to content

Commit

Permalink
OperProperties added to bgphost (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
melanietom authored and shaleman committed Aug 11, 2016
1 parent 92c679a commit 86366e2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
25 changes: 22 additions & 3 deletions bgphost.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,41 @@
"length": 15,
"format": "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?/(3[0-1]|2[0-9]|1[0-9]|[1-9])$"
},
"as": {
"as": {
"type": "string",
"title": "AS id",
"length": 64
},
"neighbor-as": {
"neighbor-as": {
"type": "string",
"title": "AS id",
"length": 64
},
"neighbor":{
"neighbor": {
"type": "string",
"title": "Bgp neighbor",
"length": 15,
"format": "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})?$"
}
},
"operProperties": {
"numRoutes": {
"type": "int",
"title": "number of routes"
},
"neighborStatus": {
"type": "string",
"title": "neighbor status"
},
"adminStatus": {
"type": "string",
"title": "admin status"
},
"routes": {
"type": "array",
"items": "string",
"title": "routes"
}
}
}]
}
9 changes: 9 additions & 0 deletions client/contivModelClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,17 @@ type Bgp struct {

}

type BgpOper struct {
AdminStatus string `json:"adminStatus,omitempty"` // admin status
NeighborStatus string `json:"neighborStatus,omitempty"` // neighbor status
NumRoutes int `json:"numRoutes,omitempty"` // number of routes
Routes []string `json:"routes,omitempty"`
}

type BgpInspect struct {
Config Bgp

Oper BgpOper
}

type EndpointOper struct {
Expand Down
10 changes: 10 additions & 0 deletions client/contivModelClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ def listBgp(self):



# Inspect Bgp
def createBgp(self, obj):
postUrl = self.baseUrl + '/api/v1/inspect/Bgp/' + obj.hostname + '/'

retDate = urllib2.urlopen(postUrl)
if retData == "Error":
errorExit("list Bgp failed")

return json.loads(retData)




Expand Down
34 changes: 34 additions & 0 deletions contivModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ type Bgp struct {

}

type BgpOper struct {
AdminStatus string `json:"adminStatus,omitempty"` // admin status
NeighborStatus string `json:"neighborStatus,omitempty"` // neighbor status
NumRoutes int `json:"numRoutes,omitempty"` // number of routes
Routes []string `json:"routes,omitempty"`
}

type BgpInspect struct {
Config Bgp

Oper BgpOper
}

type EndpointOper struct {
Expand Down Expand Up @@ -442,6 +451,8 @@ type AppProfileCallbacks interface {
}

type BgpCallbacks interface {
BgpGetOper(Bgp *BgpInspect) error

BgpCreate(Bgp *Bgp) error
BgpUpdate(Bgp, params *Bgp) error
BgpDelete(Bgp *Bgp) error
Expand Down Expand Up @@ -1135,10 +1146,33 @@ func httpInspectBgp(w http.ResponseWriter, r *http.Request, vars map[string]stri
}
obj.Config = *objConfig

if err := GetOperBgp(&obj); err != nil {
log.Errorf("GetBgp error for: %+v. Err: %v", obj, err)
return nil, err
}

// Return the obj
return &obj, nil
}

// Get a BgpOper object
func GetOperBgp(obj *BgpInspect) error {
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}

// Perform callback
err := objCallbackHandler.BgpCb.BgpGetOper(obj)
if err != nil {
log.Errorf("BgpDelete retruned error for: %+v. Err: %v", obj, err)
return err
}

return nil
}

// LIST REST call
func httpListBgps(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
log.Debugf("Received httpListBgps: %+v", vars)
Expand Down

0 comments on commit 86366e2

Please sign in to comment.