-
Notifications
You must be signed in to change notification settings - Fork 5
/
virtualserver.go
73 lines (63 loc) · 2.87 KB
/
virtualserver.go
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
package illumioapi
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
// VirtualServer represents a VirtualServer in the PCE
type VirtualServer struct {
Href string `json:"href,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DeletedAt string `json:"deleted_at,omitempty"`
CreatedBy *CreatedBy `json:"created_by,omitempty"`
UpdatedBy *UpdatedBy `json:"updated_by,omitempty"`
DeletedBy *DeletedBy `json:"deleted_by,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
DiscoveredVirtualServer *DiscoveredVirtualServer `json:"discovered_virtual_server,omitempty"`
DvsName string `json:"dvs_name,omitempty"`
DvsIdentifier string `json:"dvs_identifier,omitempty"`
Labels []*Label `json:"labels,omitempty"`
Service *Service `json:"service,omitempty"`
Providers []interface{} `json:"providers,omitempty"`
Mode string `json:"mode,omitempty"`
}
// DiscoveredVirtualServer is part of a Virtual Server
type DiscoveredVirtualServer struct {
Href string `json:"href"`
}
// GetAllVirtualServers returns a slice of virtual servers in the Illumio PCE.
// provisionStatus must be "draft" or "active"
// The first API call to the PCE does not use the async option.
// If the array length is >=500, it re-runs with async.
func (p *PCE) GetAllVirtualServers(provisionStatus string) ([]VirtualServer, APIResponse, error) {
var api APIResponse
// Build the API URL
apiURL, err := url.Parse("https://" + pceSanitization(p.FQDN) + ":" + strconv.Itoa(p.Port) + "/api/v2/orgs/" + strconv.Itoa(p.Org) + "/sec_policy/" + provisionStatus + "/virtual_servers")
if err != nil {
return nil, api, fmt.Errorf("get all workloads - %s", err)
}
// Call the API
api, err = apicall("GET", apiURL.String(), *p, nil, false)
if err != nil {
return nil, api, fmt.Errorf("get all virtualservers - %s", err)
}
var virtualServers []VirtualServer
json.Unmarshal([]byte(api.RespBody), &virtualServers)
// If length is 500, re-run with async
if len(virtualServers) >= 500 {
// Call async
api, err = apicall("GET", apiURL.String(), *p, nil, true)
if err != nil {
return nil, api, fmt.Errorf("get all virtualservers - %s", err)
}
// Unmarshal response to asyncWklds and return
var asyncVS []VirtualServer
json.Unmarshal([]byte(api.RespBody), &asyncVS)
return asyncVS, api, nil
}
// Return if less than 500
return virtualServers, api, nil
}