Skip to content

Commit 424fe65

Browse files
committed
firewall-policy improvements
1 parent e902dde commit 424fe65

File tree

6 files changed

+61
-83
lines changed

6 files changed

+61
-83
lines changed

README.md

+6-20
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ var firewallPolicyData = {
364364
oneandone.addFirewallPolicy(server_id, ip_id, firewallPolicyData, function (error, response, body) {//consume the result });
365365
```
366366

367-
**Remove a firewall policy from a server's IP:**
368-
369-
`oneandone.deleteIpFirewallPolicy(server_id, ip_id, function (error, response, body) {//consume the result });`
370-
371367
**Assign a new load balancer to a server's IP:**
372368

373369
```
@@ -716,14 +712,14 @@ var firewallData = {
716712
"rules": [
717713
{
718714
"protocol": "TCP",
719-
"port_from": 80,
720-
"port_to": 80,
715+
"port": "80",
716+
"action": "allow",
721717
"source": "0.0.0.0"
722718
},
723719
{
724720
"protocol": "TCP",
725-
"port_from": 443,
726-
"port_to": 443,
721+
"port": "443",
722+
"action": "allow",
727723
"source": "0.0.0.0"
728724
}
729725
]
@@ -775,11 +771,6 @@ var assignData = {
775771
oneandone.assignServerIpToFirewallPolicy(firewall_policy_id, assignData, function (error, response, body) {//consume the result });
776772
```
777773

778-
**Remove a server/IP from a firewall policy:**
779-
780-
`oneandone.unassignServerIpFromFirewallPolicy(firewall_policy_id, server_ip_id, function (error, response, body) {//consume the result });`
781-
782-
783774
**List rules of a firewall policy:**
784775

785776
`oneandone.listFirewallPolicyRules(firewall_policy_id, function (error, response, body) {//consume the result });`
@@ -797,8 +788,8 @@ var ruleData = {
797788
"rules": [
798789
{
799790
"protocol": oneandone.RuleProtocol.TCP,
800-
"port_from": 4567,
801-
"port_to": 4567,
791+
"port": "4567",
792+
"action": "allow",
802793
"source": "0.0.0.0"
803794
}
804795
]
@@ -2982,11 +2973,6 @@ addFirewallPolicy: function (srv_id, ip_id, json, callback) {
29822973
}
29832974
```
29842975
```javascript
2985-
deleteIpFirewallPolicy: function (srv_id, ip_id, callback) {
2986-
req.is_del(["servers", srv_id, "ips", ip_id, "firewall_policy"], callback)
2987-
}
2988-
```
2989-
```javascript
29902976
listIpLoadBalancer: function (srv_id, ip_id, callback) {
29912977
req.is_get(["servers", srv_id, "ips", ip_id, "load_balancers"], callback)
29922978
}

lib/firewall-policy.js

-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ module.exports = {
6161
req.is_get([this.fpEndPointPath, fp_id, "server_ips", ip_id], callback)
6262
},
6363

64-
unassignServerIpFromFirewallPolicy: function (fp_id, ip_id, json, callback) {
65-
req.is_del([this.fpEndPointPath, fp_id, "server_ips", ip_id], json, callback)
66-
},
67-
6864
listFirewallPolicyRules: function (fp_id, callback) {
6965
req.is_get([this.fpEndPointPath, fp_id, "rules"], callback)
7066
},

lib/server.js

-4
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ module.exports = {
166166
req.is_put(["servers", srv_id, "ips", ip_id, "firewall_policy"], json, callback)
167167
},
168168

169-
deleteIpFirewallPolicy: function (srv_id, ip_id, callback) {
170-
req.is_del(["servers", srv_id, "ips", ip_id, "firewall_policy"], callback)
171-
},
172-
173169
listIpLoadBalancer: function (srv_id, ip_id, callback) {
174170
req.is_get(["servers", srv_id, "ips", ip_id, "load_balancers"], callback)
175171
},

test/firewall-policy.js

+18-26
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ describe('Firewall Policy tests', function () {
1616
before(function (done) {
1717
helper.authenticate(oneandone);
1818
var options = {
19-
query: "centos"
19+
query: "ubuntu"
2020
};
2121
oneandone.listServerAppliancesWithOptions(options, function (error, response, body) {
2222
var res = JSON.parse(body);
23-
appliance = res[0];
23+
for (var i=0;i<res.length;i++){
24+
if(res[i].type=="IMAGE"){
25+
appliance = res[i];
26+
break;
27+
}
28+
}
29+
2430
var options = {
2531
query: "us"
2632
};
@@ -54,14 +60,14 @@ describe('Firewall Policy tests', function () {
5460
"rules": [
5561
{
5662
"protocol": "TCP",
57-
"port_from": 80,
58-
"port_to": 80,
63+
"port": "80",
64+
"action":"allow",
5965
"source": "0.0.0.0"
6066
},
6167
{
6268
"protocol": "TCP",
63-
"port_from": 443,
64-
"port_to": 443,
69+
"port": "90",
70+
"action":"allow",
6571
"source": "0.0.0.0"
6672
}
6773
]
@@ -104,12 +110,12 @@ describe('Firewall Policy tests', function () {
104110
}
105111
};
106112
after(function (done) {
107-
removeFirewallPolicy(firewallPolicy, function () {
108-
setTimeout(function () {
109-
removeServer(server, function () {
113+
removeServer(server, function () {
114+
helper.checkServerRemoved(server, function () {
115+
removeFirewallPolicy(firewallPolicy, function () {
110116
done();
111117
});
112-
}, 100000);
118+
});
113119
});
114120
});
115121

@@ -227,27 +233,13 @@ describe('Firewall Policy tests', function () {
227233
});
228234
});
229235

230-
it('Delete Firewall Policy server ip', function (done) {
231-
oneandone.unassignServerIpFromFirewallPolicy(firewallPolicy.id, server.ips[0].id, function (error, response, body) {
232-
helper.assertNoError(202, response, function (result) {
233-
assert(result);
234-
});
235-
assert.notEqual(response, null);
236-
assert.notEqual(body, null);
237-
var object = JSON.parse(body);
238-
assert.equal(object.id, firewallPolicy.id);
239-
done();
240-
});
241-
242-
});
243-
244236
it('Add rule', function (done) {
245237
ruleData = {
246238
"rules": [
247239
{
248240
"protocol": oneandone.RuleProtocol.TCP,
249-
"port_from": 4567,
250-
"port_to": 4567,
241+
"port": "4567",
242+
"action": "allow",
251243
"source": "0.0.0.0"
252244
}
253245
]

test/server-network.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@ describe('Server Network tests', function () {
1717
before(function (done) {
1818
helper.authenticate(oneandone);
1919
var options = {
20-
query: "centos"
20+
query: "ubuntu"
2121
};
2222
oneandone.listServerAppliancesWithOptions(options, function (error, response, body) {
2323
var res = JSON.parse(body);
24-
appliance = res[0];
24+
for (var i=0;i<res.length;i++){
25+
if(res[i].type=="IMAGE"){
26+
appliance = res[i];
27+
break;
28+
}
29+
}
2530
var options = {
2631
query: "us"
2732
};
2833
oneandone.listDatacentersWithOptions(options, function (error, response, body) {
2934
var res1 = JSON.parse(body);
3035
dataCenter = res1[0];
3136
var serverData = {
32-
"name": "Node Server network test2",
37+
"name": "Node Server network test",
3338
"description": "description",
3439
"hardware": {
3540
"vcore": 2,
@@ -190,20 +195,6 @@ describe('Server Network tests', function () {
190195
});
191196
});
192197

193-
it('Remove Firewall Policy from an IP', function (done) {
194-
helper.checkServerReady(server, function () {
195-
oneandone.deleteIpFirewallPolicy(server.id, currentIp.id, function (error, response, body) {
196-
helper.assertNoError(202, response, function (result) {
197-
assert(result);
198-
});
199-
assert.notEqual(response, null);
200-
assert.notEqual(body, null);
201-
done();
202-
});
203-
});
204-
205-
});
206-
207198
it('Add LoadBalancer to an IP', function (done) {
208199
oneandone.listLoadBalancers(function (lbError, lbResponse, lbBody) {
209200
var loadBalancerId = JSON.parse(lbBody);

test/testHelper.js

+29-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ helper.checkServerReady = function (currentServer, callback) {
1717
oneandone.getServer(currentServer.id, function (error, response, body) {
1818
checkServer = JSON.parse(body);
1919
if ((checkServer.status.state != oneandone.ServerState.POWERED_OFF
20-
&& checkServer.status.state != oneandone.ServerState.POWERED_ON)
21-
|| (checkServer.status.percent != null && checkServer.status.percent != 0)) {
20+
&& checkServer.status.state != oneandone.ServerState.POWERED_ON)
21+
|| (checkServer.status.percent != null && checkServer.status.percent != 0)) {
2222
setTimeout(function () {
2323
helper.checkServerReady(checkServer, callback);
2424
}, 20000);
@@ -28,6 +28,23 @@ helper.checkServerReady = function (currentServer, callback) {
2828
});
2929
};
3030

31+
helper.checkServerRemoved = function (currentServer, callback) {
32+
var checkServer = {};
33+
if (!currentServer || !currentServer.id) {
34+
callback();
35+
}
36+
oneandone.getServer(currentServer.id, function (error, response, body) {
37+
checkServer = JSON.parse(body);
38+
if (!error && response.statusCode == 200) {
39+
setTimeout(function () {
40+
helper.checkServerRemoved(checkServer, callback);
41+
}, 20000);
42+
} else {
43+
callback();
44+
}
45+
});
46+
};
47+
3148
helper.checkImageReady = function (currentImage, callback) {
3249
var checkImage = {};
3350
oneandone.getImage(currentImage.id, function (error, response, body) {
@@ -46,16 +63,16 @@ helper.checkImageReady = function (currentImage, callback) {
4663
helper.checkPrivateNetworkReady = function (currentServer, privateNetwork, callback) {
4764
var checkPn = {};
4865
oneandone.getServerPrivateNetwork(currentServer.id, privateNetwork.id,
49-
function (error, response, body) {
50-
checkPn = JSON.parse(body);
51-
if (checkPn.state != oneandone.GenericState.ACTIVE) {
52-
setTimeout(function () {
53-
helper.checkPrivateNetworkReady(currentServer, privateNetwork, callback);
54-
}, 5000);
55-
} else {
56-
callback();
57-
}
58-
}
66+
function (error, response, body) {
67+
checkPn = JSON.parse(body);
68+
if (checkPn.state != oneandone.GenericState.ACTIVE) {
69+
setTimeout(function () {
70+
helper.checkPrivateNetworkReady(currentServer, privateNetwork, callback);
71+
}, 5000);
72+
} else {
73+
callback();
74+
}
75+
}
5976
)
6077
;
6178
};

0 commit comments

Comments
 (0)