Module: CloudstackClient::Router

Defined in:
lib/cloudstack-client/commands/router.rb

Instance Method Summary collapse

Instance Method Details

#destroy_router(id, opts = {async: true}) ⇒ Object

Destroy virtual router.



56
57
58
59
60
61
62
# File 'lib/cloudstack-client/commands/router.rb', line 56

def destroy_router(id, opts = {async: true})
  params = {
    'command' => 'destroyRouter',
    'id' => id
  }
  opts[:async] ? send_async_request(params)['router'] : send_request(params)
end

#get_router(name) ⇒ Object

Get a router with a given name.



8
9
10
11
12
13
14
15
16
17
# File 'lib/cloudstack-client/commands/router.rb', line 8

def get_router(name)
  params = {
      'command' => 'listRouters',
      'listall' => 'true',
      'name' => name
  }

  json = send_request(params)
  json['router'] ? json['router'].first : nil
end

#list_routers(args = {:account => nil, :zone => nil, :projectid => nil, :status => nil, :name => nil}) ⇒ Object

Lists all virtual routers.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cloudstack-client/commands/router.rb', line 22

def list_routers(args = {:account => nil, :zone => nil, :projectid => nil, :status => nil, :name => nil})
  params = {
      'command' => 'listRouters',
      'listall' => 'true',
      'isrecursive' => 'true'
  }
  if args[:zone]
    zone = get_zone(args[:zone])
    unless zone 
      puts "Error: Zone #{args[:zone]} not found"
      exit 1
    end
    params['zoneid'] = zone['id']  
  end
  params['projectid'] = args[:projectid] if args[:projectid]
  params['state'] = args[:status] if args[:status]
  params['name'] = args[:name] if args[:name]
  if args[:account]
     = list_accounts({name: args[:account]}).first
    unless 
      puts "Error: Account #{args[:account]} not found."
      exit 1
    end
    params['domainid'] = ["domainid"]
    params['account'] = args[:account]
  end

  json = send_request(params)
  json['router'] || []
end

#start_router(id, opts = {async: true}) ⇒ Object

Start virtual router.



67
68
69
70
71
72
73
# File 'lib/cloudstack-client/commands/router.rb', line 67

def start_router(id, opts = {async: true})
  params = {
    'command' => 'startRouter',
    'id' => id
  }
  opts[:async] ? send_async_request(params)['router'] : send_request(params)
end

#stop_router(id, opts = {async: true}) ⇒ Object

Stop virtual router.



78
79
80
81
82
83
84
# File 'lib/cloudstack-client/commands/router.rb', line 78

def stop_router(id, opts = {async: true})
  params = {
    'command' => 'stopRouter',
    'id' => id
  }
  opts[:async] ? send_async_request(params)['router'] : send_request(params)
end