1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[google] Add support for network and external_ip

* Add support for an other network than default
   ("default" network is still default network)
 * Can specify if creation or not of an external_ip
   (External_ip is still created by default)
This commit is contained in:
Romain Vrignaud 2013-08-01 15:10:19 +02:00
parent 04062770a4
commit 7dc1f7f9a2
2 changed files with 26 additions and 9 deletions

View file

@ -10,6 +10,8 @@ module Fog
identity :name
attribute :image_name, :aliases => 'image'
attribute :network_interfaces, :aliases => 'networkInterfaces'
attribute :network, :aliases => 'network'
attribute :external_ip, :aliases => 'externalIP'
attribute :state, :aliases => 'status'
attribute :zone_name, :aliases => 'zone'
attribute :machine_type, :aliases => 'machineType'
@ -77,6 +79,8 @@ module Fog
'image' => image_name,
'machineType' => machine_type,
'networkInterfaces' => network_interfaces,
'network' => network,
'externalIp' => external_ip,
'disks' => disks,
'kernel' => kernel,
'metadata' => metadata

View file

@ -36,16 +36,29 @@ module Fog
body_object['image'] = @image_url
end
body_object['machineType'] = @api_url + @project + "/zones/#{zone_name}/machineTypes/#{options.delete 'machineType'}"
networkInterfaces = []
if @default_network
networkInterfaces << {
'network' => @api_url + @project + "/global/networks/#{@default_network}",
'accessConfigs' => [
{'type' => 'ONE_TO_ONE_NAT',
'name' => 'External NAT'}
]
}
network = nil
if options.has_key? 'network'
network = options.delete 'network'
elsif @default_network
network = @default_network
end
# ExternalIP is default value for server creation
if options.has_key? 'externalIp'
external_ip = options.delete 'externalIp'
else
external_ip = true
end
networkInterfaces = []
if ! network.nil?
networkInterface = { 'network' => @api_url + @project + "/global/networks/#{network}" }
if external_ip
networkInterface['accessConfigs'] = [{'type' => 'ONE_TO_ONE_NAT', 'name' => 'External NAT'}]
end
networkInterfaces << networkInterface
end
# TODO: add other networks
body_object['networkInterfaces'] = networkInterfaces