github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas_v2/l7policies/doc.go (about) 1 /* 2 Package l7policies provides information and interaction with L7Policies and 3 Rules of the LBaaS v2 extension for the OpenStack Networking service. 4 5 Example to Create a L7Policy 6 7 createOpts := l7policies.CreateOpts{ 8 Name: "redirect-example.com", 9 ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d", 10 Action: l7policies.ActionRedirectToURL, 11 RedirectURL: "http://www.example.com", 12 } 13 l7policy, err := l7policies.Create(lbClient, createOpts).Extract() 14 if err != nil { 15 panic(err) 16 } 17 18 Example to List L7Policies 19 20 listOpts := l7policies.ListOpts{ 21 ListenerID: "c79a4468-d788-410c-bf79-9a8ef6354852", 22 } 23 allPages, err := l7policies.List(lbClient, listOpts).AllPages() 24 if err != nil { 25 panic(err) 26 } 27 allL7Policies, err := l7policies.ExtractL7Policies(allPages) 28 if err != nil { 29 panic(err) 30 } 31 for _, l7policy := range allL7Policies { 32 fmt.Printf("%+v\n", l7policy) 33 } 34 35 Example to Get a L7Policy 36 37 l7policy, err := l7policies.Get(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d").Extract() 38 if err != nil { 39 panic(err) 40 } 41 42 Example to Delete a L7Policy 43 44 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 45 err := l7policies.Delete(lbClient, l7policyID).ExtractErr() 46 if err != nil { 47 panic(err) 48 } 49 50 Example to Update a L7Policy 51 52 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 53 name := "new-name" 54 updateOpts := l7policies.UpdateOpts{ 55 Name: &name, 56 } 57 l7policy, err := l7policies.Update(lbClient, l7policyID, updateOpts).Extract() 58 if err != nil { 59 panic(err) 60 } 61 62 Example to Create a Rule 63 64 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 65 createOpts := l7policies.CreateRuleOpts{ 66 RuleType: l7policies.TypePath, 67 CompareType: l7policies.CompareTypeRegex, 68 Value: "/images*", 69 } 70 rule, err := l7policies.CreateRule(lbClient, l7policyID, createOpts).Extract() 71 if err != nil { 72 panic(err) 73 } 74 75 Example to List L7 Rules 76 77 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 78 listOpts := l7policies.ListRulesOpts{ 79 RuleType: l7policies.TypePath, 80 } 81 allPages, err := l7policies.ListRules(lbClient, l7policyID, listOpts).AllPages() 82 if err != nil { 83 panic(err) 84 } 85 allRules, err := l7policies.ExtractRules(allPages) 86 if err != nil { 87 panic(err) 88 } 89 for _, rule := allRules { 90 fmt.Printf("%+v\n", rule) 91 } 92 93 Example to Get a l7 rule 94 95 l7rule, err := l7policies.GetRule(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d", "53ad8ab8-40fa-11e8-a508-00224d6b7bc1").Extract() 96 if err != nil { 97 panic(err) 98 } 99 100 Example to Delete a l7 rule 101 102 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 103 ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e" 104 err := l7policies.DeleteRule(lbClient, l7policyID, ruleID).ExtractErr() 105 if err != nil { 106 panic(err) 107 } 108 109 Example to Update a Rule 110 111 l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64" 112 ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e" 113 updateOpts := l7policies.UpdateRuleOpts{ 114 RuleType: l7policies.TypePath, 115 CompareType: l7policies.CompareTypeRegex, 116 Value: "/images/special*", 117 } 118 rule, err := l7policies.UpdateRule(lbClient, l7policyID, ruleID, updateOpts).Extract() 119 if err != nil { 120 panic(err) 121 } 122 */ 123 package l7policies