Class: SoftLayer::VLANFirewall

Inherits:
ModelBase show all
Includes:
DynamicAttribute
Defined in:
lib/softlayer/VLANFirewall.rb

Overview

The VLANFirewall class represents the firewall that protects all the servers on a VLAN in the SoftLayer Environment. It is also known as a “Dedicated Firewall” in some documentation.

Instances of this class are a bit odd because they actually represent a VLAN (the VLAN protected by the firewall to be specific), and not the physical hardware implementing the firewall itself. (although the device is accessible as the “networkVlanFirewall” property)

As a result, instances of this class correspond to certain instances in the SoftLayer_Network_Vlan service.

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicAttribute

included

Methods inherited from ModelBase

#[], #has_sl_property?, #initialize, #refresh_details, sl_attr, #to_ary

Constructor Details

This class inherits a constructor from SoftLayer::ModelBase

Class Method Details

.find_firewalls(client = nil) ⇒ Object

Collect a list of the firewalls on the account.

This list is obtained by asking the account for all the VLANs it has that also have a networkVlanFirewall component.


209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/softlayer/VLANFirewall.rb', line 209

def self.find_firewalls(client = nil)
  softlayer_client = client || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  # only VLAN firewallas have a networkVlanFirewall component
  vlan_firewall_filter = SoftLayer::ObjectFilter.new() { |filter|
    filter.accept("networkVlans.networkVlanFirewall").when_it is_not_null
  }

  vlan_firewalls = softlayer_client[:Account].object_mask(vlan_firewall_mask).object_filter(vlan_firewall_filter).getNetworkVlans
  vlan_firewalls.collect { |firewall_data| SoftLayer::VLANFirewall.new(softlayer_client, firewall_data)}
end

Instance Method Details

#cancel!(notes = nil) ⇒ Object

Cancel the firewall

This method cancels the firewall and releases its resources. The cancellation is processed immediately! Call this method with careful deliberation!

Notes is a string that describes the reason for the cancellation. If empty or nil, a default string will be added.


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/softlayer/VLANFirewall.rb', line 91

def cancel!(notes = nil)
  user = self.softlayer_client[:Account].object_mask("mask[id,account.id]").getCurrentUser
  notes = "Cancelled by a call to #{__method__} in the softlayer_api gem" if notes == nil || notes == ""

  cancellation_request = {
    'accountId' => user['account']['id'],
    'userId'    => user['id'],
    'items' => [ {
      'billingItemId' => self['networkVlanFirewall']['billingItem']['id'],
      'immediateCancellationFlag' => true
      } ],
    'notes' => notes
  }

  self.softlayer_client[:Billing_Item_Cancellation_Request].createObject(cancellation_request)
end

#change_routing_bypass!(routing_symbol) ⇒ Object

This method allows you to route traffic around the firewall and directly to the servers it protects. Compare the behavior of this routine with change_rules_bypass!

It is important to note that changing the routing to :route_around_firewall removes ALL the protection offered by the firewall. This routine should be used with extreme discretion.

Note that this routine constructs a transaction. The Routing change may not happen immediately.

The two symbols accepted as arguments by the routine are: :route_through_firewall - Network traffic is sent through the firewall to the servers in the VLAN segment it protects. This is the usual operating mode of the firewall. :route_around_firewall - Network traffic will be sent directly to the servers in the VLAN segment protected by this firewall. This means that the firewall will NOT be protecting those servers.


189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/softlayer/VLANFirewall.rb', line 189

def change_routing_bypass!(routing_symbol)
  vlan_firewall_id = self['networkVlanFirewall']['id']

  raise "Could not identify the device for a VLAN firewall" if !vlan_firewall_id

  case routing_symbol
  when :route_through_firewall
    self.softlayer_client[:Network_Vlan_Firewall].object_with_id(vlan_firewall_id).updateRouteBypass(false)
  when :route_around_firewall
    self.softlayer_client[:Network_Vlan_Firewall].object_with_id(vlan_firewall_id).updateRouteBypass(true)
  else
    raise ArgumentError, "An invalid parameter was sent to #{__method__}. It accepts :route_through_firewall and :route_around_firewall"
  end
end

#change_rules!(rules_data) ⇒ Object

Change the set of rules for the firewall. The rules_data parameter should be an array of hashes where each hash gives the conditions of the rule. The keys of the hashes should be entries from the array returned by SoftLayer::ServerFirewall.default_rules_mask_keys

NOTE! When changing the rules on the firewall, you must pass in a complete set of rules each time. The rules you submit will replace the entire ruleset on the destination firewall.

NOTE! The rules themselves have an “orderValue” property. It is this property, and not the order that the rules are found in the rules_data array, which will determine in which order the firewall applies its rules to incomming traffic.

NOTE! Changes to the rules are not applied immediately on the server side. Instead, they are enqueued by the firewall update service and updated periodically. A typical update will take about one minute to apply, but times may vary depending on the system load and other circumstances.


130
131
132
133
134
135
136
137
# File 'lib/softlayer/VLANFirewall.rb', line 130

def change_rules!(rules_data)
  change_object = {
    "firewallContextAccessControlListId" => rules_ACL_id(),
    "rules" => rules_data
  }

  self.softlayer_client[:Network_Firewall_Update_Request].createObject(change_object)
end

#change_rules_bypass!(bypass_symbol) ⇒ Object

This method asks the firewall to ignore its rule set and pass all traffic through the firewall. Compare the behavior of this routine with change_routing_bypass!

It is important to note that changing the bypass to :bypass_firewall_rules removes ALL the protection offered by the firewall. This routine should be used with extreme discretion.

Note that this routine queues a rule change and rule changes may take time to process. The change will probably not take effect immediately.

The two symbols accepted as arguments by this routine are: :apply_firewall_rules - The rules of the firewall are applied to traffic. This is the default operating mode of the firewall :bypass_firewall_rules - The rules of the firewall are ignored. In this configuration the firewall provides no protection.


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/softlayer/VLANFirewall.rb', line 155

def change_rules_bypass!(bypass_symbol)
  change_object = {
    "firewallContextAccessControlListId" => rules_ACL_id(),
    "rules" => self.rules
  }

  case bypass_symbol
  when :apply_firewall_rules
    change_object['bypassFlag'] = false
    self.softlayer_client[:Network_Firewall_Update_Request].createObject(change_object)
  when :bypass_firewall_rules
    change_object['bypassFlag'] = true
    self.softlayer_client[:Network_Firewall_Update_Request].createObject(change_object)
  else
    raise ArgumentError, "An invalid parameter was sent to #{__method__}. It accepts :apply_firewall_rules and :bypass_firewall_rules"
  end
end

#fullyQualifiedDomainNameObject

The fully qualified domain name of the physical device the firewall is implemented by.


64
65
66
67
68
69
70
# File 'lib/softlayer/VLANFirewall.rb', line 64

def fullyQualifiedDomainName
  if self.has_sl_property?('networkVlanFirewall')
    return self['networkVlanFirewall']['fullyQualifiedDomainName']
  else
    return @softlayer_hash
  end
end

#high_availability?Boolean

Returns true if this is a “high availability” firewall, that is a firewall that exists as one member of a redundant pair.


75
76
77
78
# File 'lib/softlayer/VLANFirewall.rb', line 75

def high_availability?
  # note that highAvailabilityFirewallFlag is a boolean in the softlayer hash
  return self.has_sl_property?('highAvailabilityFirewallFlag') && self['highAvailabilityFirewallFlag']
end

#primaryRouterObject

Returns the name of the primary router the firewall is attached to. This is often a “customer router” in one of the datacenters.


57
58
59
# File 'lib/softlayer/VLANFirewall.rb', line 57

def primaryRouter
  return self['primaryRouter']['hostname']
end

#rulesObject

:attr_reader:

The set of rules applied by this firewall to incoming traffic. The object will retrieve the rules from the network API every time you ask it for the rules.

The code will sort the rules by their “orderValue” which is the order that the firewall applies the rules, however please see the important note in change_rules! concerning the “orderValue” property of the rules.


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/softlayer/VLANFirewall.rb', line 41

sl_dynamic_attr :rules do |firewall_rules|
  firewall_rules.should_update? do
    # firewall rules update every time you ask for them.
    return true
  end

  firewall_rules.to_update do
    acl_id = rules_ACL_id()
    rules_data = self.softlayer_client[:Network_Firewall_AccessControlList].object_with_id(acl_id).object_mask(self.class.default_rules_mask).getRules
    rules_data.sort { |lhs, rhs| lhs['orderValue'] <=> rhs['orderValue'] }
  end
end

#serviceObject

– Methods for the SoftLayer model ++


227
228
229
230
231
232
# File 'lib/softlayer/VLANFirewall.rb', line 227

def service
  # Objects of this class are a bit odd because they actually represent VLANs (the VLAN protected by the firewall)
  # and not the physical hardware implementing the firewall itself.  (although the device is accessible as the
  # "networkVlanFirewall" property)
  self.softlayer_client[:Network_Vlan].object_with_id(self.id)
end

#softlayer_properties(object_mask = nil) ⇒ Object


234
235
236
237
238
# File 'lib/softlayer/VLANFirewall.rb', line 234

def softlayer_properties(object_mask = nil)
  service = self.service
  service = service.object_mask(object_mask) if object_mask
  service.object_mask(self.class.vlan_firewall_mask).getObject
end