def _check_if_up(instance): if hasattr(instance, '_is_up'): return True server = nova.get_instance_info(instance) if server.status == 'ERROR': # TODO(slukjanov): replace with specific error raise RuntimeError("node %s has error status" % server.name) if server.status != 'ACTIVE': return False if len(server.networks) == 0: return False if not networks.init_instances_ips(instance, server): return False try: exit_code, _ = remote.get_remote(instance).execute_command("hostname") if exit_code: return False except Exception as ex: LOG.debug("Can't login to node %s (%s), reason %s", server.name, instance.management_ip, ex) return False instance._is_up = True return True
def init_instances_ips(instance): """Extracts internal and management ips. As internal ip will be used the first ip from the nova networks CIDRs. If use_floating_ip flag is set than management ip will be the first non-internal ip. """ server = nova.get_instance_info(instance) management_ip = None internal_ip = None for network_label, addresses in six.iteritems(server.addresses): for address in addresses: if address['OS-EXT-IPS:type'] == 'fixed': internal_ip = internal_ip or address['addr'] else: management_ip = management_ip or address['addr'] if not CONF.use_floating_ips: management_ip = internal_ip conductor.instance_update(context.ctx(), instance, {"management_ip": management_ip, "internal_ip": internal_ip}) return internal_ip and management_ip
def init_instances_ips(instance): """Extracts internal and management ips. As internal ip will be used the first ip from the nova networks CIDRs. If use_floating_ip flag is set than management ip will be the first non-internal ip. """ server = nova.get_instance_info(instance) management_ip = None internal_ip = None for network_label, addresses in six.iteritems(server.addresses): for address in addresses: if address['OS-EXT-IPS:type'] == 'fixed': internal_ip = internal_ip or address['addr'] else: management_ip = management_ip or address['addr'] if not CONF.use_floating_ips: management_ip = internal_ip conductor.instance_update(context.ctx(), instance, { "management_ip": management_ip, "internal_ip": internal_ip }) return internal_ip and management_ip
def _check_if_active(self, instance): server = nova.get_instance_info(instance) if server.status == 'ERROR': # TODO(slukjanov): replace with specific error raise RuntimeError("node %s has error status" % server.name) return server.status == 'ACTIVE'
def _check_if_active(instance): server = nova.get_instance_info(instance) if server.status == 'ERROR': # TODO(slukjanov): replace with specific error raise RuntimeError("node %s has error status" % server.name) return server.status == 'ACTIVE'
def _generate_host_manifest(self, servers): host_manifest = {} hosts = [] host_id = 1 for server in servers: instance_info = n_helper.get_instance_info(server) hosts.append({'host_id': host_id, 'hostname': server.hostname, 'role': server.role, 'vm_image': instance_info.image, 'vm_flavor': instance_info.flavor, 'public_ip': server.management_ip, 'private_ip': server.internal_ip}) host_id += 1 host_manifest['hosts'] = hosts return json.dumps(host_manifest).strip('{}')
def init_instances_ips(instance): """Extracts internal and management ips. As internal ip will be used the first ip from the nova networks CIDRs. If use_floating_ip flag is set than management ip will be the first non-internal ip. """ server = nova.get_instance_info(instance) management_ip = None internal_ip = None for network_label, addresses in six.iteritems(server.addresses): for address in addresses: if address['OS-EXT-IPS:type'] == 'fixed': internal_ip = internal_ip or address['addr'] else: management_ip = management_ip or address['addr'] if not CONF.use_floating_ips: management_ip = internal_ip if not management_ip and CONF.use_neutron: neutron_client = neutron.client() target_port = None for port in neutron_client.list_ports()["ports"]: if port["device_id"] == server.id: target_port = port break for fl_ip in neutron_client.list_floatingips()['floatingips']: if fl_ip['port_id'] == target_port['id']: management_ip = fl_ip['floating_ip_address'] LOG.debug('Found floating IP %s for %s' % (management_ip, server.name)) break conductor.instance_update(context.ctx(), instance, { "management_ip": management_ip, "internal_ip": internal_ip }) return internal_ip and management_ip
def _check_if_up(instance): if instance.internal_ip and instance.management_ip: return True server = nova.get_instance_info(instance) if server.status == 'ERROR': # TODO(slukjanov): replace with specific error raise RuntimeError("node %s has error status" % server.name) if server.status != 'ACTIVE': return False if len(server.networks) == 0: return False if not networks.init_instances_ips(instance, server): return False return True
def _generate_host_manifest(self, servers): host_manifest = {} hosts = [] host_id = 1 for server in servers: instance_info = n_helper.get_instance_info(server) hosts.append({ 'host_id': host_id, 'hostname': server.hostname, 'role': utils.get_host_role(server), 'vm_image': instance_info.image, 'vm_flavor': instance_info.flavor, 'public_ip': server.management_ip, 'private_ip': server.internal_ip }) host_id += 1 host_manifest['hosts'] = hosts return json.dumps(host_manifest).strip('{}')
def _generate_host_manifest(self, servers): host_manifest = {} hosts = [] host_id = 1 for server in servers: instance_info = n_helper.get_instance_info(server) hosts.append( { "host_id": host_id, "hostname": server.hostname, "role": utils.get_host_role(server), "vm_image": instance_info.image, "vm_flavor": instance_info.flavor, "public_ip": server.management_ip, "private_ip": server.internal_ip, } ) host_id += 1 host_manifest["hosts"] = hosts return json.dumps(host_manifest).strip("{}")