// 2020 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package tools import ( "github.rackspace.com/DCM/netparse" "github.rackspace.com/gorax/clients/dcxAutohost" "github.rackspace.com/gorax/clients/mydp" ) type ( // Device type is the representation of a migration device within the // migration database. // swagger:model mongoDevice Device struct { // Core device ID ID int `json:"_id" bson:"_id"` // in: body Account struct { Number int `json:"number" bson:"number"` Name string `json:"name" bson:"name"` Type string `json:"type,omitempty" bson:"type,omitempty"` LeadTech string `json:"lead_tech,omitempty" bson:"lead_tech,omitempty"` Status string `json:"status,omitempty" bson:"status,omitempty"` TeamName string `json:"team_name,omitempty" bson:"team_name,omitempty"` GeographicLocation string `json:"geographic_location,omitempty" bson:"geographic_location,omitempty"` MRR string `json:"mrr,omitempty" bson:"mrr,omitempty"` AM string `json:"manager,omitempty" bson:"manager,omitempty"` BDC string `json:"bdc,omitempty" bson:"bdc,omitempty"` PrimaryContact string `json:"primary_contact,omitempty" bson:"primary_contact,omitempty"` } `json:"account" bson:"account"` // in: body Device struct { OS string `json:"os,omitempty" bson:"os,omitempty"` HostName string `json:"hostname,omitempty" bson:"hostname,omitempty"` DataCenter string `json:"datacenter,omitempty" bson:"datacenter,omitempty"` PrimaryIP string `json:"primary_ip,omitempty" bson:"primary_ip,omitempty"` Type string `json:"type,omitempty" bson:"type,omitempty"` OnlineStatus string `json:"online_status,omitempty" bson:"online_status,omitempty"` Status string `json:"status,omitempty" bson:"status,omitempty"` CMRR string `json:"cmrr,omitempty" bson:"cmrr,omitempty"` MakeModel string `json:"make_model,omitempty" bson:"make_model,omitempty"` OSName string `json:"os_name,omitempty" bson:"os_name,omitempty"` ComponentConfigType string `json:"container_component_configuration_type_name,omitempty" bson:"container_component_configuration_type_name,omitempty"` SLA string `json:"sla,omitempty" bson:"sla,omitempty"` CustomerManaged bool `json:"customer_managed" bson:"customer_managed"` UHeight string `json:"u_height" bson:"u_height"` } `json:"device" bson:"device"` // in: body Environment EnvironmentData `json:"environment,omitempty" bson:"environment,omitempty"` // in: body IconURL string `json:"icon_url" bson:"icon_url"` // in: body Linked struct { ID int `json:"_id,omitempty" bson:"_id,omitempty"` SpecificID int `json:"specific_id" bson:"specific_id"` FailoverID int `json:"failover_device_id" bson:"failover_device_id"` AccountNumber int `json:"account_number,omitempty" bson:"account_number,omitempty"` AccountName string `json:"account_name,omitempty" bson:"account_name,omitempty"` Backups bool `json:"has_backups,omitempty" bson:"has_backups,omitempty"` Type string `json:"type,omitempty" bson:"type,omitempty"` } `json:"linked,omitempty" bson:"linked,omitempty"` // in: body Network struct { Backup []IPNetDetails `json:"backup,omitempty" bson:"backup,omitempty"` BackupServer string `json:"backup_server" bson:"backup_server"` Address struct { IPv6 []IPv6AddressDetails `json:"ipv6_addresses,omitempty" bson:"ipv6_addresses,omitempty"` DracIPs IPMapping `json:"drac_ips" bson:"drac_ips"` MBUIPs IPMapping `json:"mbu_ips" bson:"mbu_ips"` ServiceNetIPs IPMapping `json:"service_net_ips" bson:"service_net_ips"` VMNetMgmt IPMapping `json:"vmnet_management" bson:"vmnet_management"` VMNetVMotion IPMapping `json:"vmnet_vmotion" bson:"vmnet_vmotion"` } `json:"address" bson:"address"` Public struct { // in: body Aggr string `json:"aggr,omitempty" bson:"aggr,omitempty"` Vlan int `json:"vlan,omitempty" bson:"vlan,omitempty"` Zone string `json:"zone,omitempty" bson:"zone,omitempty"` ZoneCount string `json:"zone_count,omitempty" bson:"zone_count,omitempty"` } `json:"public" bson:"public"` Vlans []VlanTranslation `json:"vlans" bson:"vlans"` } `json:"network,omitempty" bson:"network,omitempty"` // in: body Trolley DeviceTrolley `json:"trolley,omitempty" bson:"trolley,omitempty"` Process struct { OSType string `json:"os_type,omitempty" bson:"os_type,omitempty"` } `json:"process,omitempty" bson:"process,omitempty"` AutomationOptOut bool `json:"automation_opt_out" bson:"automation_opt_out"` MigrationDracManuallySet bool `json:"migration_drac_manually_set,omitempty" bson:"migration_drac_manually_set,omitempty"` MoveGroup string `json:"move_group" bson:"move_group"` SAN bool `json:"has_san,omitempty" bson:"has_san,omitempty"` DAS bool `json:"has_das,omitempty" bson:"has_das,omitempty"` MBU bool `json:"has_mbu,omitempty" bson:"has_mbu,omitempty"` SharePoint bool `json:"has_sharepoint,omitempty" bson:"has_sharepoint,omitempty"` DEX bool `json:"has_dex,omitempty" bson:"has_dex,omitempty"` MSSQL bool `json:"has_mssql,omitempty" bson:"has_mssql,omitempty"` MySQL bool `json:"has_mysql,omitempty" bson:"has_mysql,omitempty"` Skype bool `json:"has_skype,omitempty" bson:"has_skype,omitempty"` Oracle bool `json:"has_oracle,omitempty" bson:"has_oracle,omitempty"` RackConnect bool `json:"has_rackconnect,omitempty" bson:"has_rackconnect,omitempty"` Waf bool `json:"has_waf,omitempty" bson:"has_waf,omitempty"` RCv2 bool `json:"rcv2,omitempty" bson:"rcv2,omitempty"` RCv3 bool `json:"rcv3,omitempty" bson:"rcv3,omitempty"` Deleted bool `json:"deleted" bson:"deleted"` MSSQLSupport bool `json:"has_mssql_support,omitempty" bson:"has_mssql_support,omitempty"` MySQLSupport bool `json:"has_mysql_support,omitempty" bson:"has_mysql_support,omitempty"` OracleSupport bool `json:"has_oracle_support,omitempty" bson:"has_oracle_support,omitempty"` DoubleTake bool `json:"has_doubletake,omitempty" bson:"has_doubletake,omitempty"` Vormetric bool `json:"has_vormetric,omitempty" bson:"has_vormetric,omitempty"` VMR bool `json:"has_vmr,omitempty" bson:"has_vmr,omitempty"` DNPO bool `json:"do_not_power_on" bson:"do_not_power_on"` Tags []string `json:"tag,omitempty" bson:"tag,omitempty"` } // DeviceTrolley is the sub-document that the device model uses to // define the details about the trolley assignment. DeviceTrolley struct { ID string `json:"_id" bson:"_id"` Number string `json:"number" bson:"number"` Slot int `json:"slot" bson:"slot"` } // IPMapping type is a representation of the IP assignments as they // are reported by environment manager. IPMapping struct { Source []IPAddressDetails `json:"source" bson:"source"` Migration []IPAddressDetails `json:"migration" bson:"migration"` } // IPAddressDetails is a representation of the information about an // IP address as it pertains to the migrationDB. IPAddressDetails struct { IPAddress string `json:"ip_address" bson:"ip_address"` Netmask string `json:"netmask" bson:"netmask"` Gateway string `json:"gateway" bson:"gateway"` Vlan int `json:"vlan" bson:"vlan"` Zone string `json:"zone" bson:"zone"` } // IPNetDetails defines the entries in the network.backup array IPNetDetails struct { Network string `json:"network" bson:"network"` Netmask string `json:"netmask" bson:"netmask"` } // IPv6AddressDetails type represents the details for an IPv6 address IPv6AddressDetails struct { IPBlockCIDR string `json:"ip_block_cidr" bson:"ip_block_cidr"` NetworkName string `json:"network_name" bson:"network_name"` VLANNumber int `json:"vlan_number" bson:"vlan_number"` Address string `json:"ip_address" bson:"ip_address"` Zone string `json:"zone" bson:"zone"` } // EnvironmentData respresents the EM data for a device EnvironmentData struct { Current Location `json:"current,omitempty" bson:"current,omitempty"` GatewayDevices []int `json:"gateway_devices" bson:"gateway_devices"` Migration Location `json:"migration,omitempty" bson:"migration,omitempty"` Number string `json:"number,omitempty" bson:"number,omitempty"` Name string `json:"name,omitempty" bson:"name,omitempty"` } // Location type is a representation of the physical assignment of // a device in the datacenter. Location struct { Cabinet string `json:"cabinet,omitempty" bson:"cabinet,omitempty"` Location string `json:"location,omitempty" bson:"location,omitempty"` DataCenter string `json:"data_center,omitempty" bson:"data_center,omitempty"` Container string `json:"container,omitempty" bson:"container,omitempty"` StartingSpace float32 `json:"starting_space,omitempty" bson:"starting_space,omitempty"` SwitchPorts []string `json:"switch_ports,omitempty" bson:"switch_ports,omitempty"` SwitchPortsMyDP []mydp.EtherPort `json:"switch_ports_mydp,omitempty" bson:"switch_ports_mydp,omitempty"` SwitchPortConfigs []SwitchPortConfig `json:"switch_port_configs,omitempty" bson:"switch_port_configs,omitempty"` DirectPorts DirectPorts `json:"direct_ports_parsed" bson:"direct_ports_parsed"` PortsParsed PortsParsed `json:"switch_ports_parsed" bson:"switch_ports_parsed"` } // Devices type is used for sorting []Device Devices []Device // PortsParsed type is used for sorting []PortParsed PortsParsed []PortParsed // PortParsed type is a break down of the switchport configuration PortParsed struct { Cab int `json:"cab" bson:"cab"` DataCenter string `json:"data_center" bson:"data_center"` MigrationPort bool `json:"migration_port" bson:"migration_port"` MockPort bool `json:"mock_port" bson:"mock_port"` PortNumber int `json:"port_number" bson:"port_number"` PortName string `json:"port_name" bson:"port_name"` PortType string `json:"port_type" bson:"port_type"` DevicePort string `json:"device_port" bson:"device_port"` SwitchName string `json:"switch_name" bson:"switch_name"` SwitchNum int `json:"switch_num" bson:"switch_num"` Config *netparse.IfcConfig `json:"config" bson:"config"` ZoneName string `json:"zone_name" bson:"zone_name"` ZoneNumber string `json:"zone_number" bson:"zone_number"` Vlans []int `json:"vlans,omitempty" bson:"vlans,omitempty"` } // DirectPorts type is an abstracted parsed ports for sorting DirectPorts []DirectPort // DirectPort type is a break down of the device-to-device configuration DirectPort struct { DataCenter string `json:"data_center" bson:"data_center"` MigrationPort bool `json:"migration_port" bson:"migration_port"` DevicePort string `json:"device_port" bson:"device_port"` OtherDevice OtherDevice `json:"other_device" bson:"other_device"` Vlans []int `json:"vlans,omitempty" bson:"vlans,omitempty"` } // OtherDevice is the other device, DUH OtherDevice struct { DevicePort string `json:"device_port" bson:"device_port"` ID int `json:"id" bson:"id"` Type string `json:"type" bson:"type"` LinkedID string `json:"linked_id" bson:"linked_id"` } // SwitchPortConfig is a model to represent the MyAdmin configuration // for a given switch+port SwitchPortConfig struct { Name string `json:"switch_name"` Interface string `json:"interface"` RawConfig string `json:"raw_config"` } // VlanTranslation defines a vlan translation structure VlanTranslation struct { Migration struct { VlanNumber int `json:"vlan_number,omitempty" bson:"vlan_number,omitempty"` NetworkSegments string `json:"network_segments,omitempty" bson:"network_segments,omitempty"` ZoneName string `json:"zone_name,omitempty" bson:"zone_name,omitempty"` } `json:"migration,omitempty" bson:"migration,omitempty"` Source struct { VlanNumber int `json:"vlan_number,omitempty" bson:"vlan_number,omitempty"` NetworkSegments string `json:"network_segments,omitempty" bson:"network_segments,omitempty"` ZoneName string `json:"zone_name,omitempty" bson:"zone_name,omitempty"` } `json:"source,omitempty" bson:"source,omitempty"` } ) // Len implements Len() for sorting interface func (d Devices) Len() int { return len(d) } // Swap implements Swap() for sorting interface func (d Devices) Swap(i, j int) { d[i], d[j] = d[j], d[i] } // Less implements Less() for sorting interface // sort by _id func (d Devices) Less(i, j int) bool { return d[i].ID < d[j].ID } // Len implements Len() for sorting interface func (p PortsParsed) Len() int { return len(p) } // Swap implements Swap() for sorting interface func (p PortsParsed) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Less implements Less() for sorting interface // sort by: // - first by portType // - then by switchName // - then by switchNumber (-1, -2, etc.) // - then by portNumber func (p PortsParsed) Less(i, j int) bool { if p[i].PortType != p[j].PortType { return p[i].PortType < p[j].PortType } if p[i].SwitchName != p[j].SwitchName { // prefer unique -1 to -2 for HA cabling with >= 4 ports if p[i].SwitchNum != p[j].SwitchNum { return p[i].SwitchNum < p[j].SwitchNum } return p[i].SwitchName < p[j].SwitchName } return p[i].PortNumber < p[j].PortNumber } // PortMapPairs is defined for sorting the list of port maps from dcx type PortMapPairs []*dcxAutohost.PortMapPair // Len implements Len() for sorting interface func (p PortMapPairs) Len() int { return len(p) } // Swap implements Swap() for sorting interface func (p PortMapPairs) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Less implements Less() for sorting interface // sort by: // - first by portType // - then by switchName // - then by portNumber func (p PortMapPairs) Less(i, j int) bool { if p[i].Source.SwitchPortType != p[j].Source.SwitchPortType { return p[i].Source.SwitchPortType < p[j].Source.SwitchPortType } if p[i].Source.Switch.Number != p[j].Source.Switch.Number { return p[i].Source.Switch.Number < p[j].Source.Switch.Number } return p[i].Source.PortNumber < p[j].Source.PortNumber }