Samuel A. Falvo II | 0262e97 | 2014-01-24 16:06:56 -0800 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/rackspace/gophercloud/openstack/identity" |
| 6 | "github.com/rackspace/gophercloud/openstack/utils" |
| 7 | "github.com/rackspace/gophercloud/rackspace/monitoring" |
| 8 | "github.com/rackspace/gophercloud/rackspace/monitoring/notificationPlans" |
| 9 | ) |
| 10 | |
| 11 | func main() { |
| 12 | ao, err := utils.AuthOptions() |
| 13 | if err != nil { |
| 14 | panic(err) |
| 15 | } |
| 16 | |
| 17 | ao.AllowReauth = true |
| 18 | r, err := identity.Authenticate(ao) |
| 19 | if err != nil { |
| 20 | panic(err) |
| 21 | } |
| 22 | |
| 23 | // Find the cloud monitoring API |
| 24 | |
| 25 | sc, err := identity.ServiceCatalog(r) |
| 26 | if err != nil { |
| 27 | panic(err) |
| 28 | } |
| 29 | |
| 30 | ces, err := sc.CatalogEntries() |
| 31 | if err != nil { |
| 32 | panic(err) |
| 33 | } |
| 34 | |
| 35 | monUrl, err := findMonitoringEndpoint(ces) |
| 36 | if err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | |
| 40 | // Build ourselves an interface to cloud monitoring! |
| 41 | |
| 42 | np := notificationPlans.NewClient(monitoring.Options{ |
| 43 | Endpoint: monUrl, |
| 44 | AuthOptions: ao, |
| 45 | Authentication: r, |
| 46 | }) |
| 47 | |
| 48 | // Try to delete a bogus notification plan |
| 49 | |
| 50 | dr, err := np.Delete("ajkhdlkajhdflkajshdf") |
| 51 | if err != nil { |
Samuel A. Falvo II | a1a95cc | 2014-01-24 16:31:40 -0800 | [diff] [blame] | 52 | fmt.Printf("%#v\n", err) |
Samuel A. Falvo II | 0262e97 | 2014-01-24 16:06:56 -0800 | [diff] [blame] | 53 | } |
| 54 | fmt.Printf("%#v\n", dr) |
| 55 | } |
| 56 | |
| 57 | func findMonitoringEndpoint(ces []identity.CatalogEntry) (string, error) { |
| 58 | for _, ce := range ces { |
| 59 | if ce.Type == "rax:monitor" { |
| 60 | return ce.Endpoints[0].PublicURL, nil |
| 61 | } |
| 62 | } |
| 63 | return "", fmt.Errorf("No monitoring API in the service catalog") |
| 64 | } |