Class: Fog::Hetznercloud::Compute::FloatingIp

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/hetznercloud/models/compute/floating_ip.rb

Instance Method Summary collapse

Instance Method Details

#assign(serverid) ⇒ Object



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
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 72

def assign(serverid)
  requires :identity
  if serverid.nil?
    body = {}

    if (floating_ip = service.floating_ip_unassign(identity, body).body['floating_ip'])
      merge_attributes(floating_ip)
      true
    else
      false
    end
  else
    server_id = case serverid
                when Fog::Hetznercloud::Compute::Server
                  serverid.identity
                when String
                  service.servers.all(name: serverid).first.identity
                when Integer
                  serverid
                else
                  raise Fog::Hetznercloud::Error::InvalidInputError, 'ERROR: Need Fog::Hetznercloud::Compute::Server|String|Integer'
                              end

    body = {
      server: server_id
    }

    if (floating_ip = service.floating_ip_assign_to_server(identity, body).body['floating_ip'])
      merge_attributes(floating_ip)
      true
    else
      false
    end
  end
end

#description=(value) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 25

def description=(value)
  @lastdescription = attributes[:description]
  attributes[:description] = value
  if @lastdescription && @lastdescription != attributes[:description]
    @needsupdate = true
  else
    @needsupdate = false
  end
end

#destroyObject



57
58
59
60
61
62
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 57

def destroy
  requires :identity

  service.delete_floating_ip(identity)
  true
end

#home_location=(value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 35

def home_location=(value)
  attributes[:home_location] = case value
                               when Hash
                                 service.locations.new(value)
                               when String
                                 service.locations.new(identity: value)
                               else
                                 value
                                end
end

#saveObject



64
65
66
67
68
69
70
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 64

def save
  if persisted?
    reassign && unassign && update
  else
    create
  end
end

#server=(value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 46

def server=(value)
  attributes[:server] = case value
                        when Hash
                          service.servers.new(value)
                        when Integer
                          service.servers.get(value)
                        else
                          value
                                end
end

#type=(value) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 16

def type=(value)
  valid = %w[ipv4 ipv6]
  if !valid.include? value
    raise Fog::Hetznercloud::Compute::InvalidInputError, "ERROR: floating_ip type must be one of #{valid}"
  else
    attributes[:type] = value
  end
end

#unassignObject



124
125
126
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 124

def unassign
  assign(nil) unless server.nil?
end

#update_dns_ptr(newname) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fog/hetznercloud/models/compute/floating_ip.rb', line 108

def update_dns_ptr(newname)
  requires :identity

  body = {
    ip: ip,
    dns_ptr: newname
  }

  if (floating_ip = service.floating_ip_update_dns_ptr(identity, body).body['floating_ip'])
    merge_attributes(floating_ip)
    true
  else
    false
  end
end