// DisassociateNetwork disassociates a network from the given tenant, returning
// an error in case of any failure.
DisassociateNetwork disassociates a network from the given tenant, returning
an error in case of any failure.
// DisassociateNetwork disassociates a network from the given tenant returning // an error in case of any failure .
func (c *Client) DisassociateNetwork(tenantId string) error {
	if c.KeystoneClient == nil {
		return errors.New("KeystoneClient is nil.")
	}
	endpoint := c.KeystoneClient.Endpoint("compute", "admin")
	req, err := http.NewRequest("GET", endpoint+"/os-networks", nil)
	if err != nil {
		return err
	}
	body, status, err := c.do(req)
	if err != nil {
		return errors.New("Failed to get the list of all networks: " + err.Error())
	}
	if status != http.StatusOK {
		return fmt.Errorf("Failed to get the list of all networks, status: %d.\nBody: %s.", status, body)
	}
	var result map[string][]network
	err = json.Unmarshal(body, &result)
	if err != nil {
		return errors.New("Failed to get the list of all networks, the server did not respond a valid JSON.")
	}
	var netId string
	for _, net := range result["networks"] {
		if net.TenantId == tenantId {
			netId = net.Id
			break
		}
	}
	if netId == "" {
		return ErrNoNetwork
	}
	reqBody := strings.NewReader(`{"disassociate":null}`)
	req, err = http.NewRequest("POST", endpoint+"/os-networks/"+netId+"/action", reqBody)
	req.Header.Set("Accept", "application/json")
	if err != nil {
		return err
	}
	body, status, err = c.do(req)
	if err != nil {
		return fmt.Errorf("Failed to disassociate the network %s from the tenant %s: %s", netId, tenantId, err)
	}
	if status != http.StatusAccepted {
		return fmt.Errorf("Failed to disassociate the network %s from the tenant %s, status: %d.\nBody: %s", netId, tenantId, status, body)
	}
	return nil
}
func ( c * Client ) DisassociateNetwork ( tenantId string ) error { if c . KeystoneClient == nil { return errors . New ( " " ) } endpoint := c . KeystoneClient . Endpoint ( " " , " " ) req , err := http . NewRequest ( " " , endpoint + " " , nil ) if err != nil { return err } body , status , err := c . do ( req ) if err != nil { return errors . New ( " " + err . Error ( ) ) } if status != http . StatusOK { return fmt . Errorf ( " \n " , status , body ) } var result map [ string ] [ ] network err = json . Unmarshal ( body , & result ) if err != nil { return errors . New ( " " ) } var netId string for _ , net := range result [ " " ] { if net . TenantId == tenantId { netId = net . Id break } } if netId == " " { return ErrNoNetwork } reqBody := strings . NewReader ( `{"disassociate":null}` ) req , err = http . NewRequest ( " " , endpoint + " " + netId + " " , reqBody ) req . Header . Set ( " " , " " ) if err != nil { return err } body , status , err = c . do ( req ) if err != nil { return fmt . Errorf ( " " , netId , tenantId , err ) } if status != http . StatusAccepted { return fmt . Errorf ( " \n " , netId , tenantId , status , body ) } return nil }
DisassociateNetwork disassociates a network from the given tenant, returning
an error in case of any failure.
DisassociateNetwork disassociates a network from the given tenant returning an error in case of any failure .