//nolint:golint package dcxAutohost import ( "encoding/json" "fmt" "net/url" ) // the /infrastructure/.. endpoints return DCX Network Architect data type ( InfraEnvironment struct { AccountNumber int `json:"account_number" bson:"account_number"` Devices []InfraDevice `json:"devices" bson:"devices"` Name string `json:"name" bson:"name"` NetworkSegments []InfraNetworkSegmentStub `json:"network_segments" bson:"network_segments"` Number string `json:"number" bson:"number"` SubEnvironments []InfrastructureStub `json:"sub_environments" bson:"sub_environments"` Zones []InfrastructureStub `json:"zones" bson:"zones"` } InfraDevice struct { ConfigurationNumber string `json:"configuration_number" bson:"configuration_number"` DeviceNumber int `json:"device_number" bson:"device_number"` HardwareName string `json:"hardware_name,omitempty" bson:"hardware_name,omitempty"` IsEthernetSwitch bool `json:"is_ethernet_switch,omitempty" bson:"is_ethernet_switch,omitempty"` Name string `json:"name" bson:"name"` ZoneName string `json:"zone_name,omitempty" bson:"zone_name,omitempty"` ZoneNumber string `json:"zone_number,omitempty" bson:"zone_number,omitempty"` } InfraNetworkSegment struct { Account int `json:"account" bson:"account"` ConfiguredVlanID int `json:"configured_vlan" bson:"configured_vlan"` Environment string `json:"environment" bson:"environment"` IPBlocks []string `json:"ip_blocks" bson:"ip_blocks"` Leasable bool `json:"leasable" bson:"leasable"` Leased bool `json:"leased" bson:"leased"` Name string `json:"name" bson:"name"` NetworkSegmentService string `json:"network_segment_service" bson:"network_segment_service"` Owner string `json:"owner" bson:"owner"` VlanNumber int `json:"vlan_number" bson:"vlan_number"` } // network segment stub record found in /environments or /zones response InfraNetworkSegmentStub struct { Name string `json:"name" bson:"name"` Number string `json:"number" bson:"number"` VlanNumber int `json:"vlan_number" bson:"vlan_number"` } // InfrastructureStub is a generic stub record found in environment "zones" field // and found in an environment's "sub_environments" field InfrastructureStub struct { Name string `json:"name" bson:"name"` Number string `json:"number" bson:"number"` } InfraZone struct { Name string `json:"name" bson:"name"` Number string `json:"number" bson:"number"` Type string `json:"type" bson:"type"` Description string `json:"description" bson:"description"` NetworkEnvironmentNumber string `json:"network_environment_number" bson:"network_environment_number"` VlanPolicyNumber string `json:"vlan_policy_number" bson:"vlan_policy_number"` AllowDuplicateVlans bool `json:"allow_duplicate_vlans" bson:"allow_duplicate_vlans"` Devices []InfraDevice `json:"devices" bson:"devices"` ConfiguredVlans []InfraVlan `json:"configured_vlans" bson:"configured_vlans"` } InfraVlan struct { VlanNumber int `json:"vlan_number" bson:"vlan_number"` PrimaryVMNetNS string `json:"primary_vmnet_nameserver" bson:"primary_vmnet_nameserver"` SecondaryVMnetNS string `json:"secondary_vmnet_nameserver" bson:"secondary_vmnet_nameserver"` BridgeContainerID int `json:"bridge_container_id" bson:"bridge_container_id"` ReservationOwnerNumber string `json:"reservation_owner_number" bson:"reservation_owner_number"` MigrationDestination *InfraMigrationVlan `json:"migration_destination" bson:"migration_destination"` NetworkSegments []InfrastructureStub `json:"network_segments" bson:"network_segments"` } InfraMigrationVlan struct { ZoneNumber string `json:"zone_number" bson:"zone_number"` VlanNumber int `json:"vlan_number" bson:"vlan_number"` DisplayName string `json:"display_name" bson:"display_name"` } ) // InfrastructureDevice will return infrastructure details of a (typically switch) device // // see: https://pages.github.rackspace.com/dcx/gateway/#/infrastructure/infrastructureDeviceData func (a *Client) InfrastructureDevice(device string) (*InfraDevice, error) { body, err := a.get(fmt.Sprintf("/infrastructure/devices/%s", device), nil) if err != nil { return nil, err } d := new(InfraDevice) err = json.Unmarshal(body, d) return d, err } // InfrastructureEnvironment will return infrastructure details of an environment // // see: https://pages.github.rackspace.com/dcx/gateway/#/infrastructure/infrastructureEnvironmentData func (a *Client) InfrastructureEnvironment(env string) (*InfraEnvironment, error) { body, err := a.get(fmt.Sprintf("/infrastructure/environments/%s", env), nil) if err != nil { return nil, err } e := new(InfraEnvironment) err = json.Unmarshal(body, e) return e, err } // InfrastructureEnvironments will return infrastructure details of environments // call currently only returns environment roots, so the param `"roots": "true"` is hard-set // // see: https://pages.github.rackspace.com/dcx/gateway/#/infrastructure/infrastructureEnvironmentsData func (a *Client) InfrastructureEnvironments() ([]InfraEnvironment, error) { body, err := a.get("/infrastructure/environments", url.Values{"roots": []string{"true"}}) if err != nil { return nil, err } e := make([]InfraEnvironment, 0) err = json.Unmarshal(body, &e) return e, err } // InfrastructureZone will return infrastructure details of zone // // see: https://pages.github.rackspace.com/dcx/gateway/#/infrastructure/infrastructureZoneData func (a *Client) InfrastructureZone(zone string) (*InfraZone, error) { body, err := a.get(fmt.Sprintf("/infrastructure/zones/%s", zone), nil) if err != nil { return nil, err } e := new(InfraZone) err = json.Unmarshal(body, e) return e, err }