Split directories
Problem
Currently all code is contained in one single body but we are maintaining 3 different processes. Vnmgr will use code that Vna never touches and vise versa. The same goes for WebApi. This poses 2 problem:
- Code readability
It makes the code much harder to read for new developers. There is no clear distinction to show which code is running where.
- Unnecessary gem installation
The openvnet-common RPM which is currently required openvnet-vnmgr, openvnet-vna and openvnet-webapicurrently contains all source code and all gems. The other packages just install config files, upstart jobs and executables in the openvnet/bin bin directory.
This means that each package installs a bunch of gems that are not required. Separating these could severely reduce the package size.
Solution
Directory structure
Split the source directory into the following tree.
.
├── common
│ └── lib
│ └── vnet.rb
├── vna
│ └── lib
│ └── vna.rb
├── vnctl
├── vnmgr
│ └── lib
│ └── vnmgr.rb
└── vnwebapi
└── lib
└── vnwebapi.rb
Modules
Here's an example of what the module structure will look like. Of course the real files will have much more contents. This is just to get an idea.
- common/lib/vnet.rb
module VNet
module Constants
autoload :Interface, 'vnet/constants/interface'
autoload :LeasePolicy, 'vnet/constants/lease_policy'
autoload :MacAddressPrefix, 'vnet/constants/mac_address_prefix'
autoload :Network, 'vnet/constants/network'
autoload :NetworkService, 'vnet/constants/network_service'
autoload :Openflow, 'vnet/constants/openflow'
autoload :OpenflowFlows, 'vnet/constants/openflow_flows'
autoload :Translation, 'vnet/constants/translation'
autoload :VnetAPI, 'vnet/constants/vnet_api'
end
module Configurations
autoload :Base, 'vnet/configurations/base'
autoload :Common, 'vnet/configurations/common'
end
end
- vna/lib/vna.rb
require_relative '../../common/lib/vnet.rb'
module VNet::Vna
module Configurations
autoload :Vna, 'vnet/configurations/vna'
end
end
- vnwebapi/lib/vnwebapi.rb
require_relative '../../common/lib/vnet.rb'
module VNet
module Configurations
autoload :Webapi, 'vnet/configurations/webapi'
end
module Endpoints
autoload :Errors, 'vnet/endpoints/errors'
autoload :ResponseGenerator, 'vnet/endpoints/response_generator'
autoload :CollectionResponseGenerator, 'vnet/endpoints/response_generator'
module V10
autoload :Helpers, 'vnet/endpoints/1.0/helpers'
autoload :VnetAPI, 'vnet/endpoints/1.0/vnet_api'
...
end
end
end
And a similar one for vnmgr.
Gemfile
Each directory will have its own Gemfile. vnmgr, vnwebapi and vna will all require the Gemfile from common. You can do so with the following line.
eval_gemfile File.join(File.dirname(__FILE__), "/../common/Gemfile")