Skip to content

Commit

Permalink
Merge pull request #65 from plumgrid/sagheer-dev
Browse files Browse the repository at this point in the history
restrict network creation in transit domain
  • Loading branch information
Fawad Khaliq authored Sep 20, 2016
2 parents 03c21a2 + f710646 commit b283012
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions plugin/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (driver *driver) createNetwork(w http.ResponseWriter, r *http.Request) {
}
DomainCreate(domainid.(string))

if CheckExternalConnectivity(domainid.(string)) {
errorResponse(w, fmt.Sprintf("Non-external network cannot be created in transit domain."))
return
}

gatewayip := create.IPv4Data[0].Gateway.IP.String()
neName := create.Options[netlabel.GenericData].(map[string]interface{})["bridge"]

Expand Down
22 changes: 21 additions & 1 deletion plugin/driver/pg_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func CheckNeExists(ne_name, domain string) bool {

url := "/0/connectivity/domain/" + domain + "/ne?configonly=true"

body, _ := RestCall("GET", url+"?configonly=true", nil)
body, _ := RestCall("GET", url, nil)
var domain_data map[string]interface{}
err := json.Unmarshal([]byte(body), &domain_data)
if err != nil {
Expand All @@ -443,3 +443,23 @@ func CheckNeExists(ne_name, domain string) bool {

return false
}

func CheckExternalConnectivity(domain string) bool {

url := "/0/connectivity/domain_prop/" + domain + "/ne?configonly=true"

body, _ := RestCall("GET", url, nil)
var domain_data map[string]interface{}
err := json.Unmarshal([]byte(body), &domain_data)
if err != nil {
panic(err)
}

for key, _ := range domain_data {
if key == "external_connectivity_enable" {
return true
}
}

return false
}
2 changes: 0 additions & 2 deletions plugin/driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

// Response Functions

func notFound(w http.ResponseWriter, r *http.Request) {
Log.Warningf("[plugin] Not found: %+v", r)
http.NotFound(w, r)
Expand Down Expand Up @@ -54,7 +53,6 @@ func emptyResponse(w http.ResponseWriter) {
}

// Helper Functions

func vethPair(suffix string) *netlink.Veth {
return &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{Name: "tap" + suffix},
Expand Down

0 comments on commit b283012

Please sign in to comment.