github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/fwaas/policies/doc.go (about)

     1  /*
     2  Package policies allows management and retrieval of Firewall Policies in the
     3  OpenStack Networking Service.
     4  
     5  Example to List Policies
     6  
     7  	listOpts := policies.ListOpts{
     8  		TenantID: "966b3c7d36a24facaf20b7e458bf2192",
     9  	}
    10  
    11  	allPages, err := policies.List(networkClient, listOpts).AllPages()
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	allPolicies, err := policies.ExtractPolicies(allPages)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	for _, policy := range allPolicies {
    22  		fmt.Printf("%+v\n", policy)
    23  	}
    24  
    25  Example to Create a Policy
    26  
    27  	createOpts := policies.CreateOpts{
    28  		Name:        "policy_1",
    29  		Description: "A policy",
    30  		Rules: []string{
    31  			"98a58c87-76be-ae7c-a74e-b77fffb88d95",
    32  			"7c4f087a-ed46-4ea8-8040-11ca460a61c0",
    33  		}
    34  	}
    35  
    36  	policy, err := policies.Create(networkClient, createOpts).Extract()
    37  	if err != nil {
    38  		panic(err)
    39  	}
    40  
    41  Example to Update a Policy
    42  
    43  	policyID := "38aee955-6283-4279-b091-8b9c828000ec"
    44  
    45  	updateOpts := policies.UpdateOpts{
    46  		Description: "New Description",
    47  	}
    48  
    49  	policy, err := policies.Update(networkClient, policyID, updateOpts).Extract()
    50  	if err != nil {
    51  		panic(err)
    52  	}
    53  
    54  Example to Delete a Policy
    55  
    56  	policyID := "38aee955-6283-4279-b091-8b9c828000ec"
    57  	err := policies.Delete(networkClient, policyID).ExtractErr()
    58  	if err != nil {
    59  		panic(err)
    60  	}
    61  
    62  Example to Add a Rule to a Policy
    63  
    64  	policyID := "38aee955-6283-4279-b091-8b9c828000ec"
    65  	ruleOpts := policies.InsertRuleOpts{
    66  		ID: "98a58c87-76be-ae7c-a74e-b77fffb88d95",
    67  	}
    68  
    69  	policy, err := policies.AddRule(networkClient, policyID, ruleOpts).Extract()
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  Example to Delete a Rule from a Policy
    75  
    76  	policyID := "38aee955-6283-4279-b091-8b9c828000ec"
    77  	ruleID := "98a58c87-76be-ae7c-a74e-b77fffb88d95",
    78  
    79  	policy, err := policies.RemoveRule(networkClient, policyID, ruleID).Extract()
    80  	if err != nil {
    81  		panic(err)
    82  	}
    83  */
    84  package policies