Created
April 3, 2014 20:17
-
-
Save anonymous/9962071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_and_route_public_block(gateway_ip) | |
num_devices = @environment.non_gateway_devices.length | |
prefix = CIDR.smallest_prefix(num_devices) | |
public_block = | |
PublicIpBlock.find_and_route_block_to_public_ip_address(gateway_ip, prefix) | |
public_block.reserve_to(gateway_ip.network_device) | |
public_block | |
end | |
then here I will try to delete it | |
def make_assignments(net_device_block, ex_net_zone) | |
@environment = SimpleConfig::Environment.create(@owner, @gateway, | |
@devices, @alias_name, | |
ex_net_zone.zone) | |
gateway_ip = net_device_block.assign_gateway_ip | |
ip_blocks = SimpleConfig::IpBlocks.new(@private_cidr, environment) | |
public_block = ip_blocks.find_and_route_public_block(gateway_ip) | |
ActiveRecord::Base.transaction do | |
private_block = ip_blocks.create_private_block | |
public_block.nat_to(private_block) | |
ip_blocks.allocate_ips_to_devices(public_block, private_block) | |
SimpleConfig::ServiceNet.assign(@devices, @owner) | |
SimpleConfig::Vlan.create(@vlan_segment_name, | |
environment, | |
private_block, | |
ex_net_zone.zone) | |
environment.reload | |
end | |
rescue => e | |
remove_devices = @devices.map{ |d| d.destroy} #"destroy the network devices in the environment" | |
remove_environment = @environment.network_environment.destroy #"destroy the environment" | |
remove_gateway_ip = gateway_ip.hard_deallocate! #"destroy the gateway's IP" | |
remove_public_ip_block = public_block.destroy #"destroy the good block" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment