Skip to content

Commit

Permalink
Merge pull request #52 from plumgrid/demo-branch
Browse files Browse the repository at this point in the history
remove attached LB along with network delete
  • Loading branch information
Fawad Khaliq authored Aug 20, 2016
2 parents 768781c + 56c246f commit 8ebd9aa
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
3 changes: 2 additions & 1 deletion plugin/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (driver *driver) createNetwork(w http.ResponseWriter, r *http.Request) {
neName := create.Options[netlabel.GenericData].(map[string]interface{})["bridge"]

if neName != nil {
AddNetworkInfo(create.NetworkID, neName.(string), domainid.(string))
AddNetworkInfo(create.NetworkID, neName.(string), domainid.(string))
AddGatewayInfo(create.NetworkID, domainid.(string), gatewayip)
emptyResponse(w)

Expand Down Expand Up @@ -177,6 +177,7 @@ func (driver *driver) deleteNetwork(w http.ResponseWriter, r *http.Request) {
domainid = default_vd
}
DeleteNetworkLinks(domainid, delete.NetworkID)
DeleteAttachedLB(domainid, delete.NetworkID)
BridgeDelete(delete.NetworkID, domainid)
DomainDelete(domainid)

Expand Down
87 changes: 56 additions & 31 deletions plugin/driver/pg_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ func BridgeDelete(ID string, domainid string) {
}

func AddNetworkInfo(dNetwork string, neName string, domain string) {
id := GetNeId(neName, domain)
var neId string
if id == "" {
neId = neName
} else {
neId = id
}
url := "/0/connectivity/domain/" + domain + "/ne/" + neId
body, _ := RestCall("GET", url+"?configonly=true", nil)
var netData map[string]interface{}
err := json.Unmarshal([]byte(body), &netData)
if err != nil {
panic(err)
}
netData["metadata"] = dNetwork
finalData, _ := json.Marshal(netData)
RestCall("PUT", url, finalData)
id := GetNeId(neName, domain)
var neId string
if id == "" {
neId = neName
} else {
neId = id
}
url := "/0/connectivity/domain/" + domain + "/ne/" + neId
body, _ := RestCall("GET", url+"?configonly=true", nil)
var netData map[string]interface{}
err := json.Unmarshal([]byte(body), &netData)
if err != nil {
panic(err)
}
netData["metadata"] = dNetwork
finalData, _ := json.Marshal(netData)
RestCall("PUT", url, finalData)
}

func FindDomainFromNetwork(ID string) (domainid string, netid string) {
Expand Down Expand Up @@ -222,20 +222,20 @@ func DomainDelete(domainID string) {

func GetNeId(NeName string, DomainID string) (NeID string) {

url := "/0/connectivity/domain/" + DomainID + "/ne?configonly=true&level=1"
body, _ := RestCall("GET", url, nil)
var ne_data map[string]interface{}
err := json.Unmarshal([]byte(body), &ne_data)
if err != nil {
panic(err)
}
for nes, ne_val := range ne_data {
if ne_val.(map[string]interface{})["ne_dname"] == NeName {
NeID = nes
return NeID
}
}
return ""
url := "/0/connectivity/domain/" + DomainID + "/ne?configonly=true&level=1"
body, _ := RestCall("GET", url, nil)
var ne_data map[string]interface{}
err := json.Unmarshal([]byte(body), &ne_data)
if err != nil {
panic(err)
}
for nes, ne_val := range ne_data {
if ne_val.(map[string]interface{})["ne_dname"] == NeName {
NeID = nes
return NeID
}
}
return ""
}

func CreateNetworkLink(NeName string, DomainID string, NetworkID string, IP string, Netmask string) {
Expand Down Expand Up @@ -384,3 +384,28 @@ func RemoveMetaconfig(domainID string, netID string, endpointID string) {
}
}
}

func DeleteAttachedLB(DomainID string, NetworkID string) {

url := "/0/connectivity/domain_prop/" + DomainID + "/ne"
body, _ := RestCall("GET", url+"?configonly=true", nil)
var domain_data map[string]interface{}
err := json.Unmarshal([]byte(body), &domain_data)
if err != nil {
panic(err)
}
for a, b := range domain_data {
if b.(map[string]interface{})["ne_metadata"] == "lbaas" {
x := b.(map[string]interface{})["prop"].(map[string]interface{})["vip"].(map[string]interface{})["hint"]
y := strings.Split(x.(string), ",")
for _, z := range y {
if strings.HasPrefix(z, "attachment") {
if strings.HasSuffix(z, NetworkID) {
url = "/v0/vd/" + DomainID + "/lbaas/" + a
RestCall("DELETE", url, nil)
}
}
}
}
}
}

0 comments on commit 8ebd9aa

Please sign in to comment.