Skip to content

Commit 7c9f5b8

Browse files
committed
Added the ability to cancel firewalls
1 parent 42431a1 commit 7c9f5b8

2 files changed

Lines changed: 66 additions & 10 deletions

File tree

lib/softlayer/ServerFirewall.rb

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ def initialize(client, network_hash)
8686
@protected_server = nil
8787
end
8888

89+
##
90+
# Cancel the firewall
91+
#
92+
# This method cancels the firewall and releases its
93+
# resources. The cancellation is processed immediately!
94+
# Call this method with careful deliberation!
95+
#
96+
# Notes is a string that describes the reason for the
97+
# cancellation. If empty or nil, a default string will
98+
# be added
99+
#
100+
def cancel!(notes = nil)
101+
user = self.softlayer_client[:Account].object_mask("mask[id,account]").getCurrentUser
102+
notes = "Cancelled by a call to #{__method__} in the softlayer_api gem" if notes == nil || notes == ""
103+
104+
cancellation_request = {
105+
'accountId' => user['account']['id'],
106+
'userId' => user['id'],
107+
'items' => [ {
108+
'billingItemId' => self['billingItem']['id'],
109+
'immediateCancellationFlag' => true
110+
} ],
111+
'notes' => notes
112+
}
113+
114+
self.softlayer_client[:Billing_Item_Cancellation_Request].createObject(cancellation_request)
115+
end
116+
89117
##
90118
# Change the set of rules for the firewall.
91119
# The rules_data parameter should be an array of hashes where
@@ -117,9 +145,9 @@ def change_rules!(rules_data)
117145
# through the firewall. Compare the behavior of this routine with
118146
# change_routing_bypass!
119147
#
120-
# It is important to note that changing the bypass to :bypass_firewall_rules
121-
# removes ALL the protection offered by the firewall. This routine should be
122-
# used with extreme discretion.
148+
# It is important to note that changing the bypass to :bypass_firewall_rules
149+
# removes ALL the protection offered by the firewall. This routine should be
150+
# used with careful deliberation.
123151
#
124152
# Note that this routine queues a rule change and rule changes may take
125153
# time to process. The change will probably not take effect immediately
@@ -205,9 +233,9 @@ def softlayer_properties(object_mask = nil)
205233
service = service.object_mask(object_mask) if object_mask
206234

207235
if self.has_sl_property?('networkComponent')
208-
service.object_mask("mask[id,status,networkComponent.downlinkComponent.hardwareId]").getObject
236+
service.object_mask("mask[id,status,billingItem.id,networkComponent.downlinkComponent.hardwareId]").getObject
209237
else
210-
service.object_mask("mask[id,status,guestNetworkComponent.guest.id]").getObject
238+
service.object_mask("mask[id,status,billingItem.id,guestNetworkComponent.guest.id]").getObject
211239
end
212240
end
213241

@@ -216,7 +244,7 @@ def softlayer_properties(object_mask = nil)
216244
private
217245

218246
def self.network_vlan_mask
219-
"mask[firewallNetworkComponents[id,status,networkComponent.downlinkComponent.hardwareId],firewallGuestNetworkComponents[id,status,guestNetworkComponent.guest.id]]"
247+
"mask[firewallNetworkComponents[id,status,billingItem.id,networkComponent.downlinkComponent.hardwareId],firewallGuestNetworkComponents[id,status,billingItem.id,guestNetworkComponent.guest.id]]"
220248
end
221249

222250
def self.default_rules_mask

lib/softlayer/VLANFirewall.rb

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ class VLANFirewall < SoftLayer::ModelBase
5151
end
5252
end
5353

54+
##
55+
# Cancel the firewall
56+
#
57+
# This method cancels the firewall and releases its
58+
# resources. The cancellation is processed immediately!
59+
# Call this method with careful deliberation!
60+
#
61+
# Notes is a string that describes the reason for the
62+
# cancellation. If empty or nil, a default string will
63+
# be added
64+
#
65+
def cancel!(notes = nil)
66+
user = self.softlayer_client[:Account].object_mask("mask[id,account.id]").getCurrentUser
67+
notes = "Cancelled by a call to #{__method__} in the softlayer_api gem" if notes == nil || notes == ""
68+
69+
cancellation_request = {
70+
'accountId' => user['account']['id'],
71+
'userId' => user['id'],
72+
'items' => [ {
73+
'billingItemId' => self['networkVlanFirewall']['billingItem']['id'],
74+
'immediateCancellationFlag' => true
75+
} ],
76+
'notes' => notes
77+
}
78+
79+
self.softlayer_client[:Billing_Item_Cancellation_Request].createObject(cancellation_request)
80+
end
81+
5482
##
5583
# Change the set of rules for the firewall.
5684
# The rules_data parameter should be an array of hashes where
@@ -82,8 +110,8 @@ def change_rules!(rules_data)
82110
# through the firewall. Compare the behavior of this routine with
83111
# change_routing_bypass!
84112
#
85-
# It is important to note that changing the bypass to :bypass_firewall_rules
86-
# removes ALL the protection offered by the firewall. This routine should be
113+
# It is important to note that changing the bypass to :bypass_firewall_rules
114+
# removes ALL the protection offered by the firewall. This routine should be
87115
# used with extreme discretion.
88116
#
89117
# Note that this routine queues a rule change and rule changes may take
@@ -117,7 +145,7 @@ def change_rules_bypass!(bypass_symbol)
117145
# change_rules_bypass!
118146
#
119147
# It is important to note that changing the routing to :route_around_firewall
120-
# removes ALL the protection offered by the firewall. This routine should be
148+
# removes ALL the protection offered by the firewall. This routine should be
121149
# used with extreme discretion.
122150
#
123151
# Note that this routine constructs a transaction. The Routing change
@@ -224,7 +252,7 @@ def rules_ACL_id
224252
def self.vlan_firewall_mask
225253
return "mask[primaryRouter,highAvailabilityFirewallFlag," +
226254
"firewallInterfaces.firewallContextAccessControlLists," +
227-
"networkVlanFirewall[id, datacenter, primaryIpAddress, firewallType, fullyQualifiedDomainName]]"
255+
"networkVlanFirewall[id,datacenter,primaryIpAddress,firewallType,fullyQualifiedDomainName,billingItem.id]]"
228256
end
229257

230258
def self.default_rules_mask

0 commit comments

Comments
 (0)