def take_elastic_ip(self, az): elastic_ip_allocation_id = self.config.elastic_ip_allocation_id(az) if elastic_ip_allocation_id: ec2 = connect_to_ec2(self.current_region) interface_id = self.eth0_id if az == self.current_az else self.eth1_id ec2.associate_address(network_interface_id=interface_id, allocation_id=elastic_ip_allocation_id, allow_reassociation=True)
def attach_interface(self): device_index = 1 ec2 = connect_to_ec2(self.current_region) interface = ec2.get_all_network_interfaces(filters={'network_interface_id': self.eth1_id}) if interface and interface[0].status == 'available': ec2.attach_network_interface(self.eth1_id, self.current_instance_id, device_index) while True: call("ifdown --force eth1 2> /dev/null && ifup --force eth1", shell=True) dev = check_output('ifconfig | grep -o eth1 || echo ""', shell=True).strip() if dev == "eth1": log('eth1 is up') break else: log('eth1 is not up. Retrying ...') time.sleep(1)
def attach_interface(self): device_index = 1 ec2 = connect_to_ec2(self.current_region) interface = ec2.get_all_network_interfaces( filters={'network_interface_id': self.eth1_id}) if interface and interface[0].status == 'available': ec2.attach_network_interface(self.eth1_id, self.current_instance_id, device_index) while True: call("ifdown --force eth1 2> /dev/null && ifup --force eth1", shell=True) dev = check_output('ifconfig | grep -o eth1 || echo ""', shell=True).strip() if dev == "eth1": log('eth1 is up') break else: log('eth1 is not up. Retrying ...') time.sleep(1)
def detach_interface(self): ec2 = connect_to_ec2(self.current_region) interface = ec2.get_all_network_interfaces(filters={'network_interface_id': self.eth1_id}) if interface and interface[0].status == 'in-use': interface[0].detach(True)
def eth0_id(self): ec2 = connect_to_ec2(self.current_region) instance = ec2.get_only_instances(instance_ids=[self.current_instance_id])[0] eth0 = [i for i in instance.interfaces if i.id != self.eth1_id] return eth0[0].id
def detach_interface(self): ec2 = connect_to_ec2(self.current_region) interface = ec2.get_all_network_interfaces( filters={'network_interface_id': self.eth1_id}) if interface and interface[0].status == 'in-use': interface[0].detach(True)
def eth0_id(self): ec2 = connect_to_ec2(self.current_region) instance = ec2.get_only_instances( instance_ids=[self.current_instance_id])[0] eth0 = [i for i in instance.interfaces if i.id != self.eth1_id] return eth0[0].id