Class: CloudstackSpec::Resource::Vpc

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

Instance Attribute Summary

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-vpc1', zonename = nil) ⇒ Vpc

do nothing



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cloudstack_spec/resource/vpc.rb', line 5

def initialize(name='rspec-vpc1', zonename=nil)
  @name   = name
  @connection = CloudstackSpec::Helper::Api.new.connection
  @zone = get_zone(zonename)
  @runner = Specinfra::Runner
  #vpc = @connection.list_vpcs(listall: true, name: @name)
  if vpc.empty?
    @router = nil
  else
    @router = @connection.list_routers(vpcid: vpc['id'])['router'].first
  end
  $vpc = vpc
end

Instance Method Details

#created?(cidr = '10.10.0.0/22') ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cloudstack_spec/resource/vpc.rb', line 48

def created?(cidr='10.10.0.0/22')
  if self.exist?
    puts "  VPC already exist"
    return true
  else
    job = @connection.create_vpc(
            :name => @name,
            :displaytext => @name,
            :cidr => cidr,
            :vpcofferingid => vpc_offering_id,
            :zoneid => @zone['id']
            )
    job_status = job_status?(job['jobid'])
    @router = @connection.list_routers(vpcid: vpc['id'])['router'].first
    $vpc = vpc
    return job_status

  end
end

#destroy?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
# File 'lib/cloudstack_spec/resource/vpc.rb', line 68

def destroy?
  sleep(5)
  if self.exist?
    job = @connection.delete_vpc(id: vpc['id'])
    return job_status?(job['jobid'])
  else
    puts "  Does not exist"
    return false
  end
end

#enable_remote_vpnObject



79
80
81
82
83
84
85
86
87
# File 'lib/cloudstack_spec/resource/vpc.rb', line 79

def enable_remote_vpn
  newvpn =  @connection.create_remote_access_vpn(publicipid: publicip_snat_id)
  job_status?(newvpn['jobid'])
  vpn = @connection.list_remote_access_vpns(publicipid: publicip_snat_id)
  vpn = vpn['remoteaccessvpn'].first
  if ! vpn.empty?
    return true
  end
end

#exist?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/cloudstack_spec/resource/vpc.rb', line 19

def exist?
    if vpc.empty?
      return false
    else
      return true
    end
end

#reachable?(port, proto, timeout) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/cloudstack_spec/resource/vpc.rb', line 43

def reachable?(port, proto, timeout)
  ip = @router['publicip']
  @runner.check_host_is_reachable(ip, port, proto, timeout)
end

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  begin
    if @router['state'] == 'Running'
      if @router['version'] == CloudstackSpec::Helper::Api.new.version
        return true
      else
        return "VR version #{@router['version']}"
      end
    else
      return false
    end
  rescue
      return false
  end
end

#remote_vpn_enabled?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
98
# File 'lib/cloudstack_spec/resource/vpc.rb', line 89

def remote_vpn_enabled?
  a = @connection.list_remote_access_vpns(listall: true, publicipid: publicip_snat_id)
  if a.empty?
    false
  else
    puts "    Pubic IP = #{a['remoteaccessvpn'].first['publicip']}"
    puts "    PreShared Key = #{a['remoteaccessvpn'].first['presharedkey']}"
    true
  end
end