-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor_change] Add support for dhcp_option_policy_option, dhcp_option…
…_policy, dhcp_relay_policy_provider, dhcp_relay_policy, schema_site_anp_epg_useg_attr, schema_site_l3_out, schema_site_vrf_region_hub_network, schema_template_bd_dhcp_policy and schema_validate model and client files (#103)
- Loading branch information
Showing
35 changed files
with
1,574 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/ciscoecosystem/mso-go-client/models" | ||
) | ||
|
||
func (client *Client) CreateDHCPOptionPolicyOption(obj *models.DHCPOptionPolicyOption) error { | ||
optionPolicyID, err := client.GetDHCPOptionPolicyID(obj.PolicyName) | ||
if err != nil { | ||
return err | ||
} | ||
optionPolicyCont, err := client.ReadDHCPOptionPolicy(optionPolicyID) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPOptionPolicy, err := models.DHCPOptionPolicyFromContainer(optionPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
option := models.DHCPOption{ | ||
Data: obj.Data, | ||
ID: obj.ID, | ||
Name: obj.Name, | ||
} | ||
DHCPOptionPolicy.DHCPOption = append(DHCPOptionPolicy.DHCPOption, option) | ||
_, err = client.UpdateDHCPOptionPolicy(optionPolicyID, DHCPOptionPolicy) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) ReadDHCPOptionPolicyOption(id string) (*models.DHCPOptionPolicyOption, error) { | ||
idSplit := strings.Split(id, "/") | ||
optionPolicyID, err := client.GetDHCPOptionPolicyID(idSplit[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
optionPolicyCont, err := client.ReadDHCPOptionPolicy(optionPolicyID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
DHCPOptionPolicy, err := models.DHCPOptionPolicyFromContainer(optionPolicyCont) | ||
if err != nil { | ||
return nil, err | ||
} | ||
flag := false | ||
dhcpOption := models.DHCPOptionPolicyOption{} | ||
for _, option := range DHCPOptionPolicy.DHCPOption { | ||
if option.Name == idSplit[1] { | ||
flag = true | ||
dhcpOption.Name = option.Name | ||
dhcpOption.ID = option.ID | ||
dhcpOption.Data = option.Data | ||
dhcpOption.PolicyName = DHCPOptionPolicy.Name | ||
break | ||
} | ||
} | ||
if flag { | ||
return &dhcpOption, nil | ||
} | ||
|
||
return nil, fmt.Errorf("No DHCP Option Policy found") | ||
} | ||
|
||
func (client *Client) UpdateDHCPOptionPolicyOption(obj *models.DHCPOptionPolicyOption) error { | ||
optionPolicyID, err := client.GetDHCPOptionPolicyID(obj.PolicyName) | ||
if err != nil { | ||
return err | ||
} | ||
optionPolicyCont, err := client.ReadDHCPOptionPolicy(optionPolicyID) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPOptionPolicy, err := models.DHCPOptionPolicyFromContainer(optionPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
NewOptions := make([]models.DHCPOption, 0, 1) | ||
NewOption := models.DHCPOption{ | ||
Data: obj.Data, | ||
ID: obj.ID, | ||
Name: obj.Name, | ||
} | ||
|
||
for _, option := range DHCPOptionPolicy.DHCPOption { | ||
if option.Name != obj.Name { | ||
NewOptions = append(NewOptions, option) | ||
} else { | ||
NewOptions = append(NewOptions, NewOption) | ||
} | ||
} | ||
DHCPOptionPolicy.DHCPOption = NewOptions | ||
_, err = client.UpdateDHCPOptionPolicy(optionPolicyID, DHCPOptionPolicy) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) DeleteDHCPOptionPolicyOption(id string) error { | ||
idSplit := strings.Split(id, "/") | ||
optionPolicyID, err := client.GetDHCPOptionPolicyID(idSplit[0]) | ||
if err != nil { | ||
return err | ||
} | ||
optionPolicyCont, err := client.ReadDHCPOptionPolicy(optionPolicyID) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPOptionPolicy, err := models.DHCPOptionPolicyFromContainer(optionPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
NewOptions := make([]models.DHCPOption, 0, 1) | ||
for _, option := range DHCPOptionPolicy.DHCPOption { | ||
if option.Name == idSplit[1] { | ||
option.ID = "remove" | ||
} | ||
NewOptions = append(NewOptions, option) | ||
} | ||
DHCPOptionPolicy.DHCPOption = NewOptions | ||
_, err = client.UpdateDHCPOptionPolicy(optionPolicyID, DHCPOptionPolicy) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/mso-go-client/container" | ||
"github.com/ciscoecosystem/mso-go-client/models" | ||
) | ||
|
||
func (client *Client) GetDHCPOptionPolicyID(name string) (string, error) { | ||
path := "api/v1/policies/dhcp/option" | ||
cont, err := client.GetViaURL(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, policy := range cont.S("DhcpRelayPolicies").Data().([]interface{}) { | ||
if optionPol, ok := policy.(map[string]interface{}); ok { | ||
if name == optionPol["name"].(string) { | ||
return optionPol["id"].(string), nil | ||
} | ||
} | ||
} | ||
return "", fmt.Errorf("DHCP Option Policy with name: %s not found", name) | ||
} | ||
|
||
func (client *Client) CreateDHCPOptionPolicy(obj *models.DHCPOptionPolicy) (*container.Container, error) { | ||
path := "api/v1/policies/dhcp/option" | ||
cont, err := client.Save(path, obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cont, nil | ||
} | ||
|
||
func (client *Client) ReadDHCPOptionPolicy(id string) (*container.Container, error) { | ||
path := "api/v1/policies/dhcp/option/" + id | ||
cont, err := client.GetViaURL(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cont, nil | ||
} | ||
|
||
func (client *Client) UpdateDHCPOptionPolicy(id string, obj *models.DHCPOptionPolicy) (*container.Container, error) { | ||
remotePolicy, err := client.ReadDHCPOptionPolicy(id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
payloadModel, err := models.PrepareDHCPOptionPolicyModelForUpdate(remotePolicy, obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
path := "api/v1/policies/dhcp/option/" + id | ||
cont, err := client.Put(path, payloadModel) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cont, nil | ||
} | ||
|
||
func (client *Client) DeleteDHCPOptionPolicy(id string) error { | ||
path := "api/v1/policies/dhcp/option/" + id | ||
err := client.DeletebyId(path) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/mso-go-client/models" | ||
) | ||
|
||
func (client *Client) CreateDHCPRelayPolicyProvider(obj *models.DHCPRelayPolicyProvider) error { | ||
relayPolicyId, err := client.GetDHCPRelayPolicyID(obj.PolicyName) | ||
if err != nil { | ||
return err | ||
} | ||
relayPolicyCont, err := client.ReadDHCPRelayPolicy(relayPolicyId) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPRelay, err := models.DHCPRelayPolicyFromContainer(relayPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
provider := models.DHCPProvider{ | ||
ExternalEPG: obj.ExternalEpgRef, | ||
EPG: obj.EpgRef, | ||
DHCPServerAddress: obj.Addr, | ||
TenantID: DHCPRelay.TenantID, | ||
} | ||
DHCPRelay.DHCPProvider = append(DHCPRelay.DHCPProvider, provider) | ||
_, err = client.UpdateDHCPRelayPolicy(relayPolicyId, DHCPRelay) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) UpdateDHCPRelayPolicyProvider(new *models.DHCPRelayPolicyProvider, old *models.DHCPRelayPolicyProvider) error { | ||
relayPolicyId, err := client.GetDHCPRelayPolicyID(old.PolicyName) | ||
if err != nil { | ||
return err | ||
} | ||
relayPolicyCont, err := client.ReadDHCPRelayPolicy(relayPolicyId) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPRelay, err := models.DHCPRelayPolicyFromContainer(relayPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
NewProviders := make([]models.DHCPProvider, 0, 1) | ||
NewProvider := models.DHCPProvider{ | ||
ExternalEPG: new.ExternalEpgRef, | ||
EPG: new.EpgRef, | ||
DHCPServerAddress: new.Addr, | ||
TenantID: DHCPRelay.TenantID, | ||
} | ||
for _, provider := range DHCPRelay.DHCPProvider { | ||
if provider.DHCPServerAddress != old.Addr && provider.EPG != old.EpgRef && old.ExternalEpgRef != new.ExternalEpgRef { | ||
NewProviders = append(NewProviders, provider) | ||
} else { | ||
NewProviders = append(NewProviders, NewProvider) | ||
} | ||
} | ||
DHCPRelay.DHCPProvider = NewProviders | ||
_, err = client.UpdateDHCPRelayPolicy(relayPolicyId, DHCPRelay) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) DeleteDHCPRelayPolicyProvider(obj *models.DHCPRelayPolicyProvider) error { | ||
relayPolicyId, err := client.GetDHCPRelayPolicyID(obj.PolicyName) | ||
if err != nil { | ||
return err | ||
} | ||
relayPolicyCont, err := client.ReadDHCPRelayPolicy(relayPolicyId) | ||
if err != nil { | ||
return err | ||
} | ||
DHCPRelay, err := models.DHCPRelayPolicyFromContainer(relayPolicyCont) | ||
if err != nil { | ||
return err | ||
} | ||
NewProviders := make([]models.DHCPProvider, 0, 1) | ||
for _, provider := range DHCPRelay.DHCPProvider { | ||
if provider.DHCPServerAddress == obj.Addr && provider.EPG == obj.EpgRef && provider.ExternalEPG == obj.ExternalEpgRef { | ||
provider.Operation = "remove" | ||
} | ||
NewProviders = append(NewProviders, provider) | ||
} | ||
DHCPRelay.DHCPProvider = NewProviders | ||
_, err = client.UpdateDHCPRelayPolicy(relayPolicyId, DHCPRelay) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) ReadDHCPRelayPolicyProvider(obj *models.DHCPRelayPolicyProvider) (*models.DHCPRelayPolicyProvider, error) { | ||
relayPolicyId, err := client.GetDHCPRelayPolicyID(obj.PolicyName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
relayPolicyCont, err := client.ReadDHCPRelayPolicy(relayPolicyId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
DHCPRelay, err := models.DHCPRelayPolicyFromContainer(relayPolicyCont) | ||
if err != nil { | ||
return nil, err | ||
} | ||
flag := false | ||
for _, provider := range DHCPRelay.DHCPProvider { | ||
if provider.DHCPServerAddress == obj.Addr && provider.EPG == obj.EpgRef && provider.ExternalEPG == obj.ExternalEpgRef { | ||
flag = true | ||
break | ||
} | ||
} | ||
if flag { | ||
return obj, nil | ||
} | ||
return nil, fmt.Errorf("no DHCP Relay Policy found") | ||
} |
Oops, something went wrong.