-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pl
75 lines (55 loc) · 1.6 KB
/
main.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl -w
use strict;
use HTTP::Request;
use LWP::UserAgent;
use Getopt::Long;
use JSON::Any;
my ($verbose, $check, $action, $file, $help, $result);
$result = GetOptions ("verbose" => \$verbose,
"check" => \$check,
"action=s" => \$action,
"file=s" => \$file,
"help" => \$help);
# ACTIONS:
# start - start vps from file
# stop - stop vps from file
# getstate - get vps status from file
# restart - restart vps from file
# OPTIONS:
# vesbose - verbose mode on
# check - check runing vps and services
# action - action
# file - path to file whith vps numbers & id's
# help - call for help
# STATUS RESPONSE:
# error status - error
# stop status- stop
# running status - r
# install status - install
# backup status - backup
# restore status - restore
my $get_dc = " https://api.clodo.ru/v1/system/dcs";
my $vps_status = "/v1/system/vpsstatus/?vps=";
my $vps_start = "/v1/system/vpsstart/?vps=";
my $vps_stop = "/v1/system/vpsstop/?vps=";
my $vps_restart = "/v1/system/vpsrestart/?vps=";
my $https = "https://";
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
die ("Option --file and --actions must be!\n") if !defined $file or !defined $action;
$check = 1 if $action =~ m/(start|stop|restart)/;
open (FILE, "<", "$file") or die ("Can't open file or file does not exist.\n");
chomp(my @vps_id_array = <FILE>);
close(FILE);
print "@vps_id_array\n" if $verbose;
sub GET {
$_ = shift;
my $response = $ua->get($_);
if ($response->is_success) {
my $res = $response->content; # or whatever
print "response is - $res\n";
}
else {
die $response->status_line;
}
}