File: doc.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (140 lines) | stat: -rw-r--r-- 3,489 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
Package loadbalancers provides information and interaction with Load Balancers
of the LBaaS v2 extension for the OpenStack Networking service.

Example to List Load Balancers

	listOpts := loadbalancers.ListOpts{
		Provider: "haproxy",
	}

	allPages, err := loadbalancers.List(networkClient, listOpts).AllPages()
	if err != nil {
		panic(err)
	}

	allLoadbalancers, err := loadbalancers.ExtractLoadBalancers(allPages)
	if err != nil {
		panic(err)
	}

	for _, lb := range allLoadbalancers {
		fmt.Printf("%+v\n", lb)
	}

Example to Create a Load Balancer

	createOpts := loadbalancers.CreateOpts{
		Name:         "db_lb",
		AdminStateUp: gophercloud.Enabled,
		VipSubnetID:  "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
		VipAddress:   "10.30.176.48",
		FlavorID:     "60df399a-ee85-11e9-81b4-2a2ae2dbcce4",
		Provider:     "haproxy",
		Tags:         []string{"test", "stage"},
	}

	lb, err := loadbalancers.Create(networkClient, createOpts).Extract()
	if err != nil {
		panic(err)
	}

Example to Create a fully populated Load Balancer

	createOpts := loadbalancers.CreateOpts{
		Name:         "db_lb",
		AdminStateUp: gophercloud.Enabled,
		VipSubnetID:  "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
		VipAddress:   "10.30.176.48",
		FlavorID:     "60df399a-ee85-11e9-81b4-2a2ae2dbcce4",
		Provider:     "haproxy",
		Tags:         []string{"test", "stage"},
		Listeners: []listeners.CreateOpts{{
			Protocol:     "HTTP",
			ProtocolPort: 8080,
			Name:         "redirect_listener",
			L7Policies: []l7policies.CreateOpts{{
				Name:        "redirect-example.com",
				Action:      l7policies.ActionRedirectToURL,
				RedirectURL: "http://www.example.com",
				Rules: []l7policies.CreateRuleOpts{{
					RuleType:    l7policies.TypePath,
					CompareType: l7policies.CompareTypeRegex,
					Value:       "/images*",
				}},
			}},
			DefaultPool: &pools.CreateOpts{
				LBMethod: pools.LBMethodRoundRobin,
				Protocol: "HTTP",
				Name:     "example pool",
				Members: []pools.BatchUpdateMemberOpts{{
					Address:      "192.0.2.51",
					ProtocolPort: 80,
				},},
				Monitor: &monitors.CreateOpts{
					Name:           "db",
					Type:           "HTTP",
					Delay:          3,
					MaxRetries:     2,
					Timeout:        1,
				},
			},
		}},
	}

	lb, err := loadbalancers.Create(networkClient, createOpts).Extract()
	if err != nil {
		panic(err)
	}

Example to Update a Load Balancer

	lbID := "d67d56a6-4a86-4688-a282-f46444705c64"
	name := "new-name"
	updateOpts := loadbalancers.UpdateOpts{
		Name: &name,
	}
	lb, err := loadbalancers.Update(networkClient, lbID, updateOpts).Extract()
	if err != nil {
		panic(err)
	}

Example to Delete a Load Balancers

	deleteOpts := loadbalancers.DeleteOpts{
		Cascade: true,
	}

	lbID := "d67d56a6-4a86-4688-a282-f46444705c64"

	err := loadbalancers.Delete(networkClient, lbID, deleteOpts).ExtractErr()
	if err != nil {
		panic(err)
	}

Example to Get the Status of a Load Balancer

	lbID := "d67d56a6-4a86-4688-a282-f46444705c64"
	status, err := loadbalancers.GetStatuses(networkClient, LBID).Extract()
	if err != nil {
		panic(err)
	}

Example to Get the Statistics of a Load Balancer

	lbID := "d67d56a6-4a86-4688-a282-f46444705c64"
	stats, err := loadbalancers.GetStats(networkClient, LBID).Extract()
	if err != nil {
		panic(err)
	}

Example to Failover a Load Balancers

	lbID := "d67d56a6-4a86-4688-a282-f46444705c64"

	err := loadbalancers.Failover(networkClient, lbID).ExtractErr()
	if err != nil {
		panic(err)
	}
*/
package loadbalancers