Class: HP::Cloud::NetworkHelper

Inherits:
BaseHelper show all
Defined in:
lib/hpcloud/network_helper.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHelper

#connection, #cstatus, #fog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHelper

#is_valid?, #set_error, #to_hash

Constructor Details

#initialize(connection, foggy = nil) ⇒ NetworkHelper

Returns a new instance of NetworkHelper.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hpcloud/network_helper.rb', line 33

def initialize(connection, foggy = nil)
  super(connection, foggy)
  @shared = false
  @admin_state_up = true
  if foggy.nil?
    return
  end
  @id = foggy.id
  @name = foggy.name
  @tenant_id = foggy.tenant_id
  @status = foggy.status
  @shared = foggy.shared
  @admin_state_up = foggy.admin_state_up
  @admin_state = foggy.admin_state_up ? "up" : "down"
  @subnets_array = foggy.subnets
  @subnets = ''
  unless foggy.subnets.nil?
    foggy.subnets.each{ |x|
      @subnets = ',' unless @subnets.empty?
      @subnets = x.id.to_s
    }
  end
  @router_external = foggy.router_external
end

Instance Attribute Details

#admin_stateObject

Returns the value of attribute admin_state.



27
28
29
# File 'lib/hpcloud/network_helper.rb', line 27

def admin_state
  @admin_state
end

#admin_state_upObject

Returns the value of attribute admin_state_up.



26
27
28
# File 'lib/hpcloud/network_helper.rb', line 26

def admin_state_up
  @admin_state_up
end

#idObject

Returns the value of attribute id.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def id
  @id
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def name
  @name
end

#router_externalObject

Returns the value of attribute router_external.



26
27
28
# File 'lib/hpcloud/network_helper.rb', line 26

def router_external
  @router_external
end

#sharedObject

Returns the value of attribute shared.



26
27
28
# File 'lib/hpcloud/network_helper.rb', line 26

def shared
  @shared
end

#statusObject

Returns the value of attribute status.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def status
  @status
end

#subnetsObject

Returns the value of attribute subnets.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def subnets
  @subnets
end

#subnets_arrayObject

Returns the value of attribute subnets_array.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def subnets_array
  @subnets_array
end

#tenant_idObject

Returns the value of attribute tenant_id.



25
26
27
# File 'lib/hpcloud/network_helper.rb', line 25

def tenant_id
  @tenant_id
end

Class Method Details

.get_keysObject



29
30
31
# File 'lib/hpcloud/network_helper.rb', line 29

def self.get_keys()
  return [ "id", "name", "status", "shared", "admin_state", "subnets" ]
end

Instance Method Details

#destroyObject



83
84
85
# File 'lib/hpcloud/network_helper.rb', line 83

def destroy
  @connection.network.delete_network(@id)
end

#saveObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hpcloud/network_helper.rb', line 58

def save
  return false if is_valid? == false
  hsh = {:name => @name,
     :tenant_id => @tenant_id,
     :shared => @shared.to_s,
     :admin_state_up => @admin_state_up.to_s}
  if @fog.nil?
    response = @connection.network.create_network(hsh)
    if response.nil?
      set_error("Error creating network '#{@name}'")
      return false
    end
    @id = response.body["network"]["id"]
    @status = response.body["network"]["status"]
    @foggy = response.body["network"]
  else
    response = @connection.network.update_network(@id, hsh)
    if response.nil?
      set_error("Error updating network '#{@name}'")
      return false
    end
  end
  return true
end