Sha256: 1d70df11f93211e5d0d0fba0415d55b7243c763c51a05436f2dda4d16f728f1f
Contents?: true
Size: 1.37 KB
Versions: 12
Compression:
Stored size: 1.37 KB
Contents
module Brightbox desc 'map Cloud IPs' arg_name 'cloudip-id destination' command [:map] do |c| c.desc "Unmap mapped ips before remapping them" c.switch [:u, "unmap"] c.action do |global_options,options,args| if args.size > 2 raise "Too many arguments" end if args.size < 2 raise "You must specify the cloud ip id and the destination" end ip_id = args.first ip = CloudIP.find ip_id destination_id = args.last case destination_id when /^srv\-/ server = Server.find destination_id destination_id = server.interfaces.first["id"] info "Mapping #{ip} to interface #{destination_id} on #{server}" when /^lba\-/ lb = LoadBalancer.find destination_id info "Mapping #{ip} to load balancer #{lb}" else raise "Unknown destination '#{destination_id}'" end if ip.mapped? if options[:u] ip.unmap 3.times do break unless ip.mapped? sleep 1 ip.reload end else raise "Refusing to map already mapped ip #{ip}" end end ip.map destination_id # Wait up to 3 seconds for mapping to complete 3.times do ip.reload break if ip.mapped? sleep 1 end render_table([ip], global_options) end end end
Version data entries
12 entries across 12 versions & 1 rubygems