# Discover
Discover is a set of logic to perform network and CMDB discovery of a list of devices and 
perform environment creation and/or addition to a environment configuration utility (Environment Manager)

## What Does This Thing Do?!
This is meant to provide a way to source port assignment and device info from a CMDB (MyDatapipe) and discover
data on the network so that we can piece together network environment in Rackspace tooling. 

## How Does This Thing Work?
It starts with a device id that is recognized in the source CMDB. Since the first implementation of this is written for 
a source CMDB of admin.mydatapipe.com, we will use that as an example. 

When a list of device IDs are sent in, discover will send each device through the following steps, some of which it
will consider the devices to be grouped together. 


#### Package discover/cmdb
  * This portion is responsible for gathering all device information that can be populated in the device model. The main 
  interface implementation here is `Get(uniqueID string) (Model, error)` which will fetch information from the source CMDB
  then map the data to the cmdb.Model. 
  * There is also a `Map(r *Model) error` interface, that will generate port-maps. This also reaches out to DCX 
  to fetch the migration ports for a device. This would have to be changed if we ever go into something other than
  RXT tooling. The "Map" interface gets called inside the "Get" interface, but can be called independently to 
  get just port-maps.
  * Final note, during the gather process, we do reach out to the firewalls to gather NAT statements and ARPs. This
  helps correct device information collected from the source CMDB. 


#### Package discover/network
  * The next step is to take the port assignment info we gathered from the source CMDB and gather network details.
  This process is fairly straightforward and it uses Unipede as its connection medium to the network infrastructure. 
  The details of what is gather is in [this unipedeConfig(switchName string) method](https://github.rackspace.com/DCM/discover/blob/default/network/network.go#L147-L227).


#### Package discover/ecm
  * The final piece is the ECM package, where we combine an Environment Configuration with DCXs Environment Manager, and
  attempt to build out the environments. 
  * There are two main functions that happen here. 
    1. config_builder.go: It takes a list of device models and switch configs, and builds out what it thinks are 
    environments by grouping together devices in the same vlans and virtual devices that route to the gateway devices. 
    2. dcx_updater.go: Which takes the device groupings (NetEnv struct) and attempts to create the environment in DCXs
    environment manager. This process will use some of the methods in the dcx_updater.go file to get data about existing
    environments prior to making changes. 
  
## Contributing
#### Interface Implementations 
This package is implemented in three different parts.
 1. CMDB System: System of record that is used to document metadata about devices. Contains a device+port relationship.
 2. ECM System:  System used to document environment data about a set of devices. Almost always DCX Environment Manager
 3. Network:  The logic used to discover data on the network about a device. 
 
The CMDB and ECM systems are implemented as an interface. To define a new system, you would need to only create the 
methods required to satisfy the interface. Each system has an example implementation that can be used as a template when
creating a new implementation.   

#### To Run Locally
Discover is dependent on the following external systems, which it will need to have access to if you are developing
locally:
  1. MigrationDB: Used for storing device port-maps and environment translations. If this access doesn't exist, we 
  will not be able to post the discovered data to mongo, or pull existing translations/port-maps. (tunnel via NSI Env)
  2. DCX API: Used to gathering and updating environment manager and IP commander. 
  3. Unipede API: Used to gather network information for switches and shared infrastructure.
  4. SSH API: Used to gather firewall details around NATs/ARPs for environments. (tunnel via NSI Env)
  5. MyAdmin: Used as the source CMDB for the /datapipe system. 
  
   

## More help
> Send emails to: [NetSec DC Migrations](mailto:netsec_dc_migrations@RACKSPACE.COM)
