Module: CloudstackClient::PortForwardingRule

Defined in:
lib/cloudstack_client/commands/port_forwarding_rule.rb

Instance Method Summary collapse

Instance Method Details

#create_port_forwarding_rule(ip_address_id, private_port, protocol, public_port, virtual_machine_id, async = true) ⇒ Object

Creates a port forwarding rule.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cloudstack_client/commands/port_forwarding_rule.rb', line 35

def create_port_forwarding_rule(ip_address_id, private_port, protocol, public_port, virtual_machine_id, async = true)
  params = {
      'command' => 'createPortForwardingRule',
      'ipAddressId' => ip_address_id,
      'privatePort' => private_port,
      'protocol' => protocol,
      'publicPort' => public_port,
      'virtualMachineId' => virtual_machine_id
  }
  async ? send_async_request(params)['portforwardingrule'] : send_request(params)
end

#get_ssh_port_forwarding_rule(server, cached_rules = nil) ⇒ Object

Gets the SSH port forwarding rule for the specified server.



23
24
25
26
27
28
29
30
# File 'lib/cloudstack_client/commands/port_forwarding_rule.rb', line 23

def get_ssh_port_forwarding_rule(server, cached_rules=nil)
  rules = cached_rules || list_port_forwarding_rules || []
  rules.find_all { |r|
    r['virtualmachineid'] == server['id'] &&
        r['privateport'] == '22'&&
        r['publicport'] == '22'
  }.first
end

#list_port_forwarding_rules(ip_address_id = nil, project_id) ⇒ Object

Lists all port forwarding rules.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cloudstack_client/commands/port_forwarding_rule.rb', line 8

def list_port_forwarding_rules(ip_address_id=nil, project_id)
  params = {
      'command' => 'listPortForwardingRules',
      'listall' => true,
      'isrecursive' => true
  }
  params['ipAddressId'] = ip_address_id if ip_address_id
  params['projectid'] = project_id if project_id
  json = send_request(params)
  json['portforwardingrule'] || []
end