-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathec2host
executable file
·66 lines (56 loc) · 1.35 KB
/
ec2host
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
#!/usr/bin/env php
<?php
/**
* ec2host
*
* @copyright Copyright (c) fruux GmbH. All rights reserved.
* @author Dominik Tobschall (http://fruux.com/)
*/
/*
* Find the Composer autoloader.
* Credit: https://github.com/evert/sabre-vobject/blob/master/bin/vobjectvalidate.php
*/
$paths = [
__DIR__ . '/../vendor/autoload.php', // In case the project is cloned directly
__DIR__ . '/../../../autoload.php', // In case the project is a composer dependency.
];
foreach ($paths as $path) {
if (file_exists($path)) {
include($path);
break;
}
}
/* Setting a default timezone so PHP doesn't emit any warnings */
date_default_timezone_set('UTC');
/*
* Import namespaces
*/
use ec2dns\ec2;
use ec2dns\ec2host;
/*
* Instantiate main class.
*/
try {
$ec2 = new ec2(getenv('AWS_ACCESS_KEY_ID'), getenv('AWS_SECRET_ACCESS_KEY'), getenv('EC2_URL'));
} catch (Exception $e) {
fwrite(STDERR, $e->getMessage() . "\n");
die();
}
/*
* Run ec2host
*/
if (isset($argv[1])) {
$ec2host = new ec2host($ec2, $argv[1]);
} else {
$ec2host = new ec2host($ec2);
}
/*
* Output result of ec2host
*/
foreach ($ec2host->instances as $instance) {
if (isset($argv[1])) {
echo $instance['dnsName'] . "\n";
} else {
echo $instance['instanceId'] . ": " . $instance['tag'] . "\t" . $instance['dnsName'] . "\n";
}
}