Changeset 305


Ignore:
Timestamp:
Oct 11, 2017, 10:19:45 PM (7 years ago)
Author:
g7moreau
Message:
  • Add host-setlocation command (beginning)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r304 r305  
    77use strict;
    88use warnings;
    9 use version; our $VERSION = qv('0.7.0');
     9use version; our $VERSION = qv('0.7.1');
    1010
    1111use Readonly;
     
    9191   'vlan-getname'         => \&cmd_vlan_getname,
    9292   'vlan-list'            => \&cmd_vlan_list,
     93   'host-setlocation'     => \&cmd_host_setlocation,
    9394   'rebootsw'             => \&cmd_rebootsw,
    9495   );
     
    21872188
    21882189#---------------------------------------------------------------
     2190sub cmd_host_setlocation {
     2191   @ARGV = @_;
     2192
     2193   my ($verbose, $force);
     2194   GetOptions(
     2195      'verbose|v' => \$verbose,
     2196      'force|f'   => \$force,
     2197      );
     2198
     2199   my $switch_name = shift @ARGV || q{};
     2200   my $switch_location = shift @ARGV || q{};
     2201
     2202   if ($switch_name eq q{} or $switch_location eq q{}) {
     2203      die "Usage: klask host-setlocation SWITCH_NAME LOCATION\n";
     2204      }
     2205
     2206   for my $sw_name (split /,/, $switch_name) {
     2207      if (not defined $SWITCH_DB{$sw_name}) {
     2208         die "Switch $sw_name must be defined in klask configuration file\n";
     2209         }
     2210
     2211      my $oid_search = $OID_NUMBER{'sysLocation'};
     2212
     2213      my $sw = $SWITCH_DB{$sw_name};
     2214      my ($session, $error) = Net::SNMP->session(snmp_get_rwsession($sw));
     2215      print "$error \n" if $error;
     2216
     2217      my $result = $session->set_request(
     2218         -varbindlist => [$oid_search, OCTET_STRING, $switch_location],
     2219         );
     2220      print $session->error()."\n" if $session->error_status();
     2221
     2222      $session->close;
     2223      }
     2224   return;
     2225   }
     2226
     2227#---------------------------------------------------------------
    21892228# not finish - do not use
    21902229sub cmd_port_setvlan {
Note: See TracChangeset for help on using the changeset viewer.