Guest User

Untitled

a guest
Apr 3rd, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. def find_and_route_public_block(gateway_ip)
  2. num_devices = @environment.non_gateway_devices.length
  3. prefix = CIDR.smallest_prefix(num_devices)
  4. public_block =
  5. PublicIpBlock.find_and_route_block_to_public_ip_address(gateway_ip, prefix)
  6. public_block.reserve_to(gateway_ip.network_device)
  7. public_block
  8. end
  9.  
  10.  
  11. then here I will try to delete it
  12.  
  13. def make_assignments(net_device_block, ex_net_zone)
  14. @environment = SimpleConfig::Environment.create(@owner, @gateway,
  15. @devices, @alias_name,
  16. ex_net_zone.zone)
  17. gateway_ip = net_device_block.assign_gateway_ip
  18. ip_blocks = SimpleConfig::IpBlocks.new(@private_cidr, environment)
  19. public_block = ip_blocks.find_and_route_public_block(gateway_ip)
  20. ActiveRecord::Base.transaction do
  21. private_block = ip_blocks.create_private_block
  22. public_block.nat_to(private_block)
  23. ip_blocks.allocate_ips_to_devices(public_block, private_block)
  24. SimpleConfig::ServiceNet.assign(@devices, @owner)
  25. SimpleConfig::Vlan.create(@vlan_segment_name,
  26. environment,
  27. private_block,
  28. ex_net_zone.zone)
  29. environment.reload
  30. end
  31. rescue => e
  32. remove_devices = @devices.map{ |d| d.destroy} #"destroy the network devices in the environment"
  33. remove_environment = @environment.network_environment.destroy #"destroy the environment"
  34. remove_gateway_ip = gateway_ip.hard_deallocate! #"destroy the gateway's IP"
  35. remove_public_ip_block = public_block.destroy #"destroy the good block"
  36. end
Advertisement
Add Comment
Please, Sign In to add comment