Skip to content

Commit

Permalink
Inform Rails that SecurityGroup now belongs to Router/Subnet
Browse files Browse the repository at this point in the history
With this commit we inform Rails about two new foreign keys
on :security_groups table:

```ruby
security_group.cloud_subnet
security_group.network_router

cloud_subnet.security_groups
network_router.security_groups
```

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
  • Loading branch information
miha-plesko committed Aug 24, 2018
1 parent c08b60e commit 3ee0e5b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/cloud_subnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CloudSubnet < ApplicationRecord
has_many :network_ports, :through => :cloud_subnet_network_ports, :dependent => :destroy
has_many :vms, -> { distinct }, :through => :network_ports, :source => :device, :source_type => 'VmOrTemplate'
has_many :cloud_subnets, :foreign_key => :parent_cloud_subnet_id
has_many :security_groups

has_one :public_network, :through => :network_router, :source => :cloud_network

Expand Down
1 change: 1 addition & 0 deletions app/models/network_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NetworkRouter < ApplicationRecord

has_many :floating_ips, :through => :cloud_network
has_many :cloud_networks, -> { distinct }, :through => :cloud_subnets
has_many :security_groups

alias private_networks cloud_networks
alias public_network cloud_network
Expand Down
2 changes: 2 additions & 0 deletions app/models/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class SecurityGroup < ApplicationRecord
belongs_to :cloud_tenant
belongs_to :orchestration_stack
belongs_to :network_group
belongs_to :cloud_subnet
belongs_to :network_router
has_many :firewall_rules, :as => :resource, :dependent => :destroy

has_many :network_port_security_groups, :dependent => :destroy
Expand Down

0 comments on commit 3ee0e5b

Please sign in to comment.