39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/build-cloud/networkinterface.rb', line 39
def create
return if exists?
@log.info( "Creating network interface #{@options[:name]}" )
options = @options.dup
unless options[:subnet_id]
options[:subnet_id] = BuildCloud::Subnet.get_id_by_name( options[:subnet_name] )
options.delete(:subnet_name)
end
unless options[:security_groups]
options[:group_set] = []
options[:security_group_names].each do |sg|
options[:group_set] << BuildCloud::SecurityGroup.get_id_by_name( sg )
end
options.delete(:security_group_names)
end
options[:description] = options[:name]
options.delete(:name)
tags = options[:tags] || {}
options.delete(:tags)
interface = @compute.network_interfaces.new(options)
interface.save
wait_until_ready
tags.merge!({'Name' => options[:description]})
tags.each do |k,v|
attributes = {}
attributes[:resource_id] = interface.network_interface_id
attributes[:key] = k
attributes[:value] = v
interface_tag = @compute.tags.new(attributes)
interface_tag.save
end
if options[:assign_new_public_ip] and ! options[:existing_public_ip].nil?
raise "Cannot specifiy both new and existing IP addresses"
end
if options[:assign_new_public_ip]
ip = @compute.allocate_address(domain='vpc')
public_ip = ip.body['publicIp']
allocation_id = ip.body['allocationId']
@compute.associate_address(nil, public_ip, interface.network_interface_id, allocation_id )
@log.info( "Assigned new public IP #{public_ip}" )
end
unless options[:existing_public_ip].nil?
ip = @compute.addresses.get(options[:existing_public_ip])
public_ip = ip.public_ip
allocation_id = ip.allocation_id
@compute.associate_address(nil, ip.public_ip, interface.network_interface_id, allocation_id )
end
unless options[:source_dest_check].nil?
@compute.modify_network_interface_attribute(interface.network_interface_id, 'sourceDestCheck', options[:source_dest_check])
end
@log.debug( interface.inspect )
@log.debug( ip.inspect ) unless ! options[:assign_new_public_ip]
@log.debug( ip.inspect ) unless options[:existing_public_ip].nil?
end
|