Class: Fog::Network::Softlayer::Ip

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/softlayer/models/network/ip.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Ip

Returns a new instance of Ip.



27
28
29
30
# File 'lib/fog/softlayer/models/network/ip.rb', line 27

def initialize(attributes)
  @connection = attributes[:connection]
  super
end

Instance Method Details

#broadcast?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/fog/softlayer/models/network/ip.rb', line 60

def broadcast?
  !!attributes[:broadcast]
end

#createObject



37
38
39
# File 'lib/fog/softlayer/models/network/ip.rb', line 37

def create

end

#destination_ip=(ip) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/fog/softlayer/models/network/ip.rb', line 45

def destination_ip=(ip)
  if ip.is_a?(Hash)
    attributes[:destination_ip] = Fog::Network::Softlayer::Ip.new(ip)
  elsif ip.is_a?(Fog::Network::Softlayer::Ip) or ip.nil?
    attributes[:destination_ip] = ip
  else
    raise ArgumentError, "Invalid argument type in #{self.class.name}##{__method__}."
  end
end

#destroyObject



55
56
57
58
# File 'lib/fog/softlayer/models/network/ip.rb', line 55

def destroy
  raise "Only Global IP Addresses can be destroyed.  Regular IP Addresses are part of Fog::Softlayer::Network::Subnet" unless global?
  service.delete_global_ip_address(self.global_id).status == 200
end

#gateway?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/fog/softlayer/models/network/ip.rb', line 64

def gateway?
  !!attributes[:gateway]
end

#global?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/fog/softlayer/models/network/ip.rb', line 68

def global?
  !!attributes[:global_id]
end

#network?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/fog/softlayer/models/network/ip.rb', line 72

def network?
  !!attributes[:network]
end

#reserved?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/fog/softlayer/models/network/ip.rb', line 76

def reserved?
  !!attributes[:reserved]
end

#route(dest_ip) ⇒ Object

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
# File 'lib/fog/softlayer/models/network/ip.rb', line 80

def route(dest_ip)
  requires :global_id
  raise ArgumentError, "Invalid argument type in #{self.class.name}##{__method__}." unless dest_ip.is_a?(Fog::Network::Softlayer::Ip)
  raise ArgumentError, "The destination IP may not be the network address of the destination subnet" if dest_ip.network?
  raise ArgumentError, "The destination IP may not be the gateway address of the destination subnet" if dest_ip.gateway?
  raise ArgumentError, "The destination IP may not be the broadcast address of the destination subnet" if dest_ip.broadcast?
  raise ArgumentError, "The destination IP may not be another global IP address" if dest_ip.global?
  service.route_global_ip(self.global_id, dest_ip.address).status == 200
end

#routed?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/fog/softlayer/models/network/ip.rb', line 90

def routed?
  !!self.assigned_to or !!self.destination_ip
end

#saveObject



32
33
34
35
# File 'lib/fog/softlayer/models/network/ip.rb', line 32

def save
  requires :subnet_id
  identity ? update : create
end

#unrouteObject



94
95
96
97
# File 'lib/fog/softlayer/models/network/ip.rb', line 94

def unroute
  requires :global_id
  service.unroute_global_ip(self.global_id).status == 200
end

#updateObject



41
42
43
# File 'lib/fog/softlayer/models/network/ip.rb', line 41

def update
  self
end