def detach(nova_client, neutron_client, **kwargs): if is_external_relationship(ctx): ctx.logger.info('Not detaching port from server since ' 'external port and server are being used') return port_id = ctx.target.instance.runtime_properties[OPENSTACK_ID_PROPERTY] server_id = ctx.source.instance.runtime_properties[OPENSTACK_ID_PROPERTY] server_floating_ip = get_server_floating_ip(neutron_client, server_id) if server_floating_ip: ctx.logger.info('We have floating ip {0} attached to server' .format(server_floating_ip['floating_ip_address'])) server = nova_client.servers.get(server_id) server.remove_floating_ip(server_floating_ip['floating_ip_address']) return ctx.operation.retry( message='Waiting for the floating ip {0} to ' 'detach from server {1}..' .format(server_floating_ip['floating_ip_address'], server_id), retry_after=10) change = { 'port': { 'device_id': '', 'device_owner': '' } } ctx.logger.info('Detaching port {0}...'.format(port_id)) neutron_client.update_port(port_id, change) ctx.logger.info('Successfully detached port {0}'.format(port_id))
def detach(nova_client, neutron_client, **kwargs): if is_external_relationship(ctx): ctx.logger.info('Not detaching port from server since ' 'external port and server are being used') return port_id = get_openstack_id(ctx.target) server_id = get_openstack_id(ctx.source) server_floating_ip = get_server_floating_ip(neutron_client, server_id) if server_floating_ip: ctx.logger.info('We have floating ip {0} attached to server'.format( server_floating_ip['floating_ip_address'])) server = nova_client.servers.get(server_id) server.remove_floating_ip(server_floating_ip['floating_ip_address']) return ctx.operation.retry( message='Waiting for the floating ip {0} to ' 'detach from server {1}..'.format( server_floating_ip['floating_ip_address'], server_id), retry_after=10) change = {PORT_OPENSTACK_TYPE: {'device_id': '', 'device_owner': ''}} ctx.logger.info('Detaching port {0}...'.format(port_id)) neutron_client.update_port(port_id, change) ctx.logger.info('Successfully detached port {0}'.format(port_id))
def disconnect_floatingip(nova_client, neutron_client, **kwargs): if is_external_relationship(ctx): ctx.logger.info('Not disassociating floatingip and server since ' 'external floatingip and server are being used') return server_id = get_openstack_id(ctx.source) ctx.logger.info("Remove floating ip {0}".format( ctx.target.instance.runtime_properties[IP_ADDRESS_PROPERTY])) server_floating_ip = get_server_floating_ip(neutron_client, server_id) if server_floating_ip: server = nova_client.servers.get(server_id) server.remove_floating_ip(server_floating_ip['floating_ip_address']) ctx.logger.info("Floating ip {0} detached from server" .format(server_floating_ip['floating_ip_address']))
def disconnect_floatingip(nova_client, neutron_client, **kwargs): if is_external_relationship(ctx): ctx.logger.info('Not disassociating floatingip and server since ' 'external floatingip and server are being used') return server_id = ctx.source.instance.runtime_properties[OPENSTACK_ID_PROPERTY] ctx.logger.info("Remove floating ip {0}".format( ctx.target.instance.runtime_properties[IP_ADDRESS_PROPERTY])) server_floating_ip = get_server_floating_ip(neutron_client, server_id) if server_floating_ip: server = nova_client.servers.get(server_id) server.remove_floating_ip(server_floating_ip['floating_ip_address']) ctx.logger.info("Floating ip {0} detached from server" .format(server_floating_ip['floating_ip_address']))