App-Netdisco

 view release on metacpan or  search on metacpan

lib/App/Netdisco/DB/Result/Device.pm  view on Meta::CPAN

  "snmp_comm",
  { data_type => "text", is_nullable => 1 },
  "snmp_class",
  { data_type => "text", is_nullable => 1 },
  "snmp_engineid",
  { data_type => "text", is_nullable => 1 },
  "vtp_domain",
  { data_type => "text", is_nullable => 1 },
  "vtp_mode",
  { data_type => "text", is_nullable => 1 },
  "last_discover",
  { data_type => "timestamp", is_nullable => 1 },
  "last_macsuck",
  { data_type => "timestamp", is_nullable => 1 },
  "last_arpnip",
  { data_type => "timestamp", is_nullable => 1 },
  "is_pseudo",
  { data_type => "boolean", is_nullable => 0, default_value => \"false" },
  "pae_is_enabled",
  { data_type => "boolean", is_nullable => 1 },
  "custom_fields",
  { data_type => "jsonb", is_nullable => 0, default_value => \"{}" },
  "tags",
  { data_type => "text[]", is_nullable => 0, default_value => \"'{}'::text[]" },
);
__PACKAGE__->set_primary_key("ip");


=head1 RELATIONSHIPS

=head2 device_ips

Returns rows from the C<device_ip> table which relate to this Device. That is,
all the interface IP aliases configured on the Device.

=cut

__PACKAGE__->has_many( device_ips => 'App::Netdisco::DB::Result::DeviceIp', 'ip' );

=head2 device_ips_by_address_or_name

Returns rows from the C<device_ip> table which relate to this Device. That is,
all the interface IP aliases configured on the Device. However you probably
want to use the C<device_ips_with_address_or_name> ResultSet method instead,
so you can pass the MAC address part.

=cut

__PACKAGE__->has_many( device_ips_by_address_or_name => 'App::Netdisco::DB::Result::DeviceIp',
  sub {
    my $args = shift;
    return {
      "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
      -or => [
        "$args->{foreign_alias}.dns" => { 'ilike', \'?' },
        "$args->{foreign_alias}.alias" => { '<<=', \'?' },
        "$args->{foreign_alias}.alias::text" => { 'ilike', \'?' },
      ],
    };
  },
  { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
);

=head2 vlans

Returns the C<device_vlan> entries for this Device. That is, the list of VLANs
configured on or known by this Device.

=cut

__PACKAGE__->has_many( vlans => 'App::Netdisco::DB::Result::DeviceVlan', 'ip' );

=head2 ports

Returns the set of ports on this Device.

=cut

__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePort', 'ip' );

=head2 ports_by_mac

Returns the set of ports on this Device, filtered by MAC. However you probably
want to use the C<ports_with_mac> ResultSet method instead, so you can pass the
MAC address part.

=cut

__PACKAGE__->has_many( ports_by_mac => 'App::Netdisco::DB::Result::DevicePort',
  sub {
    my $args = shift;
    return {
      "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
      "$args->{foreign_alias}.mac::text" => { 'ilike', \'?' },
    };
  },
  { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
);

=head2 module_serials

Returns the set chassis modules on this Device.

=cut

__PACKAGE__->has_many( module_serials => 'App::Netdisco::DB::Result::DeviceModule',
  sub {
    my $args = shift;
    return {
      "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
      "$args->{foreign_alias}.class" => 'chassis',
      -and => [
        "$args->{foreign_alias}.serial" => { '!=' => undef },
        "$args->{foreign_alias}.serial" => { '!=' => '' },
      ],
    };
  },
  { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
);

=head2 modules

Returns the set chassis modules on this Device.

=cut

__PACKAGE__->has_many( modules => 'App::Netdisco::DB::Result::DeviceModule', 'ip' );

=head2 power_modules

Returns the set of power modules on this Device.

=cut

__PACKAGE__->has_many( power_modules => 'App::Netdisco::DB::Result::DevicePower', 'ip' );

=head2 oids

Returns the oids walked on this Device.

=cut

__PACKAGE__->has_many( oids => 'App::Netdisco::DB::Result::DeviceBrowser', 'ip' );

=head2 port_vlans

Returns the set of VLANs known to be configured on Ports on this Device,
either tagged or untagged.

The JOIN is of type "RIGHT" meaning that the results are constrained to VLANs
only on Ports on this Device.

=cut

__PACKAGE__->has_many(
    port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
    'ip', { join_type => 'RIGHT' }
);

=head2 port_vlans_filter

A JOIN condition which can be used to filter a set of Devices to those known
carrying a given VLAN on its ports. Uses an INNER JOIN to achieve this.

=cut

__PACKAGE__->has_many(
    port_vlans_filter => 'App::Netdisco::DB::Result::DevicePortVlan',
    'ip', { join_type => 'INNER' }
);

# helper which assumes we've just RIGHT JOINed to Vlans table
sub vlan { return (shift)->vlans->first }

=head2 wireless_ports

Returns the set of wireless IDs known to be configured on Ports on this
Device.



( run in 0.806 second using v1.01-cache-2.11-cpan-39bf76dae61 )