Class: CloudstackSpec::Resource::Network

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudstack_spec/resource/network.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#get_zone, #inspect, #job_status?, #to_ary, #to_s

Constructor Details

#initialize(name = 'rspec-net1', vpcname = nil, zonename = nil) ⇒ Network

Returns a new instance of Network.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cloudstack_spec/resource/network.rb', line 6

def initialize(name='rspec-net1', vpcname=nil, zonename=nil)
  @name   = name
  @vpcname = ""
  @connection = CloudstackSpec::Helper::Api.new.connection
  @version = CloudstackSpec::Helper::Api.new.version
  @zone = get_zone(zonename)
  unless vpcname.nil?
    vpc = @connection.list_vpcs(listall: true, name: vpcname)
  end
  if vpc.nil? || vpc.empty?
    @vpc = nil
  else
    @vpc = vpc['vpc'].first
    router = @connection.list_routers(vpcid: @vpc['id'])
    if ! router.empty?
      @router = router['router'].first
    end
  end
#      @network = @connection.list_networks(:name => @name, zoneid: @zone['id'])
end

Instance Attribute Details

#vpcnameObject (readonly)

do nothing



4
5
6
# File 'lib/cloudstack_spec/resource/network.rb', line 4

def vpcname
  @vpcname
end

#zonenameObject (readonly)

do nothing



4
5
6
# File 'lib/cloudstack_spec/resource/network.rb', line 4

def zonename
  @zonename
end

Instance Method Details

#createObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cloudstack_spec/resource/network.rb', line 61

def create
  if network.count >= 1
    offering_id = @connection.list_network_offerings(:name => "DefaultIsolatedNetworkOfferingWithSourceNatService")["networkoffering"].first['id']
    newnetwork = @connection.create_network(
                :name => @name, 
                :displaytext => @name, 
                :networkofferingid => offering_id, 
                :zoneid => @zone['id']
               )
  else
    return "network already exist"
  end
end

#exist?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cloudstack_spec/resource/network.rb', line 27

def exist?
#      puts "vpc = #{$vpc}"
#      puts "vpc= #{@vpcname}, network name = #{@name}"
  #puts CloudstackSpec::Resource::Vpc('patate').name
  begin  
    if network.count >= 1
      return true
    else
      return false
    end
  rescue Exception => e
    return false
  end
end

#ready?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cloudstack_spec/resource/network.rb', line 42

def ready?
  #
  # verify the VR is running for this network and run the proper version.
  vr = @connection.list_routers(:guestnetworkid => state = network.first['id'])['router'].first
  if ! vr.nil?
    if vr['state'] == 'Running'
      if vr['version'] == @version
        return true
      else
        return "VR version #{vr['version']}"
      end
    else
      return "VR state: #{vr['state']}"
    end
  else
    return "vr not found for network #{name}"
  end
end