-
Notifications
You must be signed in to change notification settings - Fork 68
/
ec2.html
136 lines (126 loc) · 5.2 KB
/
ec2.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!--
Copyright 2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="amazon ec2">
<div class="form-row">
<label for="node-input-aws"><i class="fa fa-user"></i> AWS</label>
<input type="text" id="node-input-aws">
</div>
<div class="form-row">
<label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
<select type="text" id="node-input-operation">
<option value="reboot">Reboot</option>
<option value="start">Start</option>
<option value="stop">Stop</option>
</select>
</div>
<div class="form-row">
<label for="node-input-region"><i class="fa fa-wrench"></i> Region</label>
<select type="text" id="node-input-region">
<option value="">=== Select Region ===</option>
<option value="us-east-1">US East (N. Virginia)</option>
<option value="us-west-2">US West (Oregon)</option>
<option value="us-west-1">US West (N. California)</option>
<option value="eu-west-1">EU (Ireland)</option>
<option value="eu-central-1">EU (Frankfurt)</option>
<option value="ap-southeast-1">Asia Pacific (Singapore)</option>
<option value="ap-southeast-2">Asia Pacific (Sydney)</option>
<option value="ap-northeast-1">Asia Pacific (Tokyo)</option>
<option value="sa-east-1">South America (Sao Paulo)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-instanceid"><i class="fa fa-tag"></i> Instance ID</label>
<select id="node-input-instanceid">
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="amazon ec2">
</script>
<script type="text/javascript">
RED.nodes.registerType('amazon ec2',{
category: 'storage-output',
color:"#C0DEED",
defaults: {
aws: {type:"aws-config",required:true},
operation: { value: 'reboot' },
region: { value: '' },
instanceid: { value: '' },
name: {value:""}
},
inputs:1,
outputs:1,
icon: "amazon.png",
align: "right",
label: function() {
return this.name || "ec2";
},
oneditprepare: function () {
ec2Node = RED.nodes.node(this.id);
$("#node-input-region").change(function () {
var id = $("#node-input-region option:selected").val();
if(id != ec2Node.instanceid){
$("#node-input-instanceid").val("");
}
if(id){
window.ec2NodeIntervalId = window.setTimeout(pollEC2Instances,2000);
}
});
}
});
var ec2Node;
function updateEC2InstanceList(lists) {
var instances = $("#node-input-instanceid");
instances.children("option").remove();
instances.append('<option value=""> == select Instance == </option>');
$.each(lists.Reservations, function(i, opt){
$.each(opt.Instances, function(j, item){
var name = "";
$.each(item.Tags, function(k, tag){
if(tag.Key == "Name"){
name = tag.Value;
return false;
}
});
instances.append('<option value="' + item.InstanceId + '">' + name + '</option>');
});
});
instances.val(ec2Node.instanceid);
}
function pollEC2Instances() {
var configid = $("#node-input-aws option:selected").val();
var awsconfig = RED.nodes.node(configid);
var param = "";
if(ec2Node.aws || configid ||
( awsconfig.credentials && awsconfig.credentials.accesskeyid && awsconfig.credentials.secretaccesskey ) ){
if (awsconfig.credentials) {
param = '&accesskeyid='+awsconfig.credentials.accesskeyid+'&secretaccesskey='+awsconfig.credentials.secretaccesskey;
}
var region = $("#node-input-region option:selected").val();
$.getJSON('amazon-ec2/describeinstances?id='+ec2Node.id+'®ion='+region+param,
function(data) {
if (data) {
updateEC2InstanceList(data);
delete window.ec2NodeIntervalId;
} else {
window.ec2NodeIntervalId = window.setTimeout(pollEC2Instances,2000);
}
});
}else{
window.ec2NodeIntervalId = window.setTimeout(pollEC2Instances,2000);
}
}
</script>