Compare commits
2 Commits
5bb473404f
...
efecc60e9c
Author | SHA1 | Date |
---|---|---|
Gibheer | efecc60e9c | |
Gibheer | af625344a5 |
|
@ -20,19 +20,31 @@ create table if not exists pools(
|
||||||
primary key(layer3domain_id, id)
|
primary key(layer3domain_id, id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists containers(
|
create table containers(
|
||||||
layer3domain_id integer not null references layer3domains(id),
|
layer3domain_id integer not null references layer3domains(id),
|
||||||
network cidr not null,
|
subnet cidr not null,
|
||||||
pool_id integer,
|
pool_id integer,
|
||||||
|
attributes jsonb not null default '{}'::jsonb,
|
||||||
created_at timestamptz not null default now(),
|
created_at timestamptz not null default now(),
|
||||||
created_by varchar(128) not null,
|
created_by varchar(128) not null,
|
||||||
modified_at timestamptz not null default now(),
|
modified_at timestamptz not null default now(),
|
||||||
modified_by varchar(128) not null,
|
modified_by varchar(128) not null,
|
||||||
attributes jsonb not null default '{}'::jsonb,
|
unique(layer3domain_id, subnet),
|
||||||
unique(layer3domain_id, network),
|
foreign key (layer3domain_id, pool_id) references pools(layer3domain_id, id)
|
||||||
foreign key (layer3domain_id, pool_id) references pools(layer3domain_id, id)
|
|
||||||
);
|
);
|
||||||
create index if not exists container_reference_key on containers(layer3domain_id, pool_id, network);
|
|
||||||
|
create or replace view containers_tree as
|
||||||
|
select
|
||||||
|
c.layer3domain_id,
|
||||||
|
c.subnet,
|
||||||
|
array_agg(p.subnet order by p.subnet) filter (where p.subnet is not null) as parents
|
||||||
|
from containers c
|
||||||
|
left join containers p
|
||||||
|
on c.subnet << p.subnet
|
||||||
|
and c.layer3domain_id = p.layer3domain_id
|
||||||
|
group by c.layer3domain_id, c.subnet
|
||||||
|
order by c.layer3domain_id, c.subnet;
|
||||||
|
comment on view containers_tree is 'This returns a tree of all containers so that sub trees can be shown.';
|
||||||
|
|
||||||
create table if not exists ips(
|
create table if not exists ips(
|
||||||
layer3domain_id integer not null,
|
layer3domain_id integer not null,
|
||||||
|
|
15
types/ip.go
15
types/ip.go
|
@ -23,10 +23,10 @@ func (s *Subnet) UnmarshalJSON(in []byte) error {
|
||||||
|
|
||||||
ip, ipnet, err := net.ParseCIDR(string(in))
|
ip, ipnet, err := net.ParseCIDR(string(in))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("not a valid subnet")
|
return fmt.Errorf("not a valid subnet: %#v", err)
|
||||||
}
|
}
|
||||||
if !ipnet.IP.Equal(ip) {
|
if !ipnet.IP.Equal(ip) {
|
||||||
return fmt.Errorf("provided IP is not a subnet")
|
return fmt.Errorf("provided IP '%s' is not network address '%s' of declared subnet", ip.String(), ipnet.IP.String())
|
||||||
}
|
}
|
||||||
*s = Subnet(*ipnet)
|
*s = Subnet(*ipnet)
|
||||||
return nil
|
return nil
|
||||||
|
@ -40,6 +40,17 @@ func (s *Subnet) String() string {
|
||||||
return (*net.IPNet)(s).String()
|
return (*net.IPNet)(s).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i IP) Is4() bool {
|
||||||
|
if a := net.IP(i).To4(); a == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i IP) Is6() bool {
|
||||||
|
return !i.Is4()
|
||||||
|
}
|
||||||
|
|
||||||
// Value implements the database Value interface.
|
// Value implements the database Value interface.
|
||||||
//
|
//
|
||||||
// This function is needed so that a subnet can be inserted into
|
// This function is needed so that a subnet can be inserted into
|
||||||
|
|
Loading…
Reference in New Issue