« blib/lib/App/Netdisco/DB/Result/AccessControlListName.pm
↑ Summary
blib/lib/App/Netdisco/DB/Result/Community.pm »
| 1 | use utf8; | ||
| 2 | package App::Netdisco::DB::Result::Admin; | ||
| 3 | |||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use base 'App::Netdisco::DB::Result'; | ||
| 9 | __PACKAGE__->table("admin"); | ||
| 10 | __PACKAGE__->add_columns( | ||
| 11 | "job", | ||
| 12 | { | ||
| 13 | data_type => "integer", | ||
| 14 | is_auto_increment => 1, | ||
| 15 | is_nullable => 0, | ||
| 16 | sequence => "admin_job_seq", | ||
| 17 | }, | ||
| 18 | "entered", | ||
| 19 | { | ||
| 20 | data_type => "timestamp", | ||
| 21 | default_value => \"LOCALTIMESTAMP", | ||
| 22 | is_nullable => 1, | ||
| 23 | original => { default_value => \"LOCALTIMESTAMP" }, | ||
| 24 | }, | ||
| 25 | "started", | ||
| 26 | { data_type => "timestamp", is_nullable => 1 }, | ||
| 27 | "finished", | ||
| 28 | { data_type => "timestamp", is_nullable => 1 }, | ||
| 29 | "device", | ||
| 30 | { data_type => "inet", is_nullable => 1 }, | ||
| 31 | "port", | ||
| 32 | { data_type => "text", is_nullable => 1 }, | ||
| 33 | "action", | ||
| 34 | { data_type => "text", is_nullable => 1 }, | ||
| 35 | "subaction", | ||
| 36 | { data_type => "text", is_nullable => 1 }, | ||
| 37 | "status", | ||
| 38 | { data_type => "text", is_nullable => 1 }, | ||
| 39 | "username", | ||
| 40 | { data_type => "text", is_nullable => 1 }, | ||
| 41 | "userip", | ||
| 42 | { data_type => "inet", is_nullable => 1 }, | ||
| 43 | "log", | ||
| 44 | { data_type => "text", is_nullable => 1 }, | ||
| 45 | "debug", | ||
| 46 | { data_type => "boolean", is_nullable => 1 }, | ||
| 47 | "device_key", | ||
| 48 | { data_type => "text", is_nullable => 1 }, | ||
| 49 | "backend", | ||
| 50 | { data_type => "text", is_nullable => 1 }, | ||
| 51 | ); | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | __PACKAGE__->set_primary_key("job"); | ||
| 56 | |||
| 57 | =head1 RELATIONSHIPS | ||
| 58 | |||
| 59 | =head2 device_skips( $backend?, $max_deferrals?, $retry_after? ) | ||
| 60 | |||
| 61 | Returns the set of C<device_skip> entries which apply to this job. They match | ||
| 62 | the device IP, current backend, and job action. | ||
| 63 | |||
| 64 | You probably want to use the ResultSet method C<skipped> which completes this | ||
| 65 | query with a C<backend> host, C<max_deferrals>, and C<retry_after> parameters | ||
| 66 | (or sensible defaults). | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | __PACKAGE__->might_have( device_skips => 'App::Netdisco::DB::Result::DeviceSkip', | ||
| 71 | sub { | ||
| 72 | my $args = shift; | ||
| 73 | return { | ||
| 74 | "$args->{foreign_alias}.backend" => { '=' => \'?' }, | ||
| 75 | "$args->{foreign_alias}.device" | ||
| 76 | => { -ident => "$args->{self_alias}.device" }, | ||
| 77 | -or => [ | ||
| 78 | "$args->{foreign_alias}.actionset" | ||
| 79 | => { '@>' => \"string_to_array($args->{self_alias}.action,'')" }, | ||
| 80 | -and => [ | ||
| 81 | "$args->{foreign_alias}.deferrals" => { '>=' => \'?' }, | ||
| 82 | "$args->{foreign_alias}.last_defer" => | ||
| 83 | { '>', \'(LOCALTIMESTAMP - ?::interval)' }, | ||
| 84 | ], | ||
| 85 | ], | ||
| 86 | }; | ||
| 87 | }, | ||
| 88 | { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } | ||
| 89 | ); | ||
| 90 | |||
| 91 | =head2 target | ||
| 92 | |||
| 93 | Returns the single C<device> to which this Job entry was associated. | ||
| 94 | |||
| 95 | The JOIN is of type LEFT, in case the C<device> is not in the database. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | __PACKAGE__->belongs_to( target => 'App::Netdisco::DB::Result::Device', | ||
| 100 | { 'foreign.ip' => 'self.device' }, { join_type => 'LEFT' } ); | ||
| 101 | |||
| 102 | =head1 METHODS | ||
| 103 | |||
| 104 | =head2 display_name | ||
| 105 | |||
| 106 | An attempt to make a meaningful statement about the job. | ||
| 107 | |||
| 108 | =cut | ||
| 109 | |||
| 110 | sub display_name { | ||
| 111 | my $job = shift; | ||
| 112 | return join ' ', | ||
| 113 | $job->action, | ||
| 114 | ($job->device || ''), | ||
| 115 | ($job->port || ''); | ||
| 116 | # ($job->subaction ? (q{'}. $job->subaction .q{'}) : ''); | ||
| 117 | } | ||
| 118 | |||
| 119 | =head1 ADDITIONAL COLUMNS | ||
| 120 | |||
| 121 | =head2 entered_stamp | ||
| 122 | |||
| 123 | Formatted version of the C<entered> field, accurate to the minute. | ||
| 124 | |||
| 125 | The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> | ||
| 126 | between the date stamp and time stamp. That is: | ||
| 127 | |||
| 128 | 2012-02-06 12:49 | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | sub entered_stamp { return (shift)->get_column('entered_stamp') } | ||
| 133 | |||
| 134 | =head2 started_stamp | ||
| 135 | |||
| 136 | Formatted version of the C<started> field, accurate to the minute. | ||
| 137 | |||
| 138 | The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> | ||
| 139 | between the date stamp and time stamp. That is: | ||
| 140 | |||
| 141 | 2012-02-06 12:49 | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | sub started_stamp { return (shift)->get_column('started_stamp') } | ||
| 146 | |||
| 147 | =head2 finished_stamp | ||
| 148 | |||
| 149 | Formatted version of the C<finished> field, accurate to the minute. | ||
| 150 | |||
| 151 | The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> | ||
| 152 | between the date stamp and time stamp. That is: | ||
| 153 | |||
| 154 | 2012-02-06 12:49 | ||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub finished_stamp { return (shift)->get_column('finished_stamp') } | ||
| 159 | |||
| 160 | =head2 duration | ||
| 161 | |||
| 162 | Difference between started and finished. | ||
| 163 | |||
| 164 | =cut | ||
| 165 | |||
| 166 | sub duration { return (shift)->get_column('duration') } | ||
| 167 | |||
| 168 | 1; |