def build_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) tmpl_path, tmpl_file = os.path.split(CONF.baremetal.net_config_template) env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) template = env.get_template(tmpl_file) return template.render({'interfaces': interfaces, 'use_ipv6': CONF.use_ipv6})
def destroy(self, instance, network_info, block_device_info=None, context=None): """Destroy (shutdown and delete) the specified instance. If the instance is not found (for example if networking failed), this function should still succeed. It's probably a good idea to log a warning in that case. :param context: security context :param instance: Instance object as returned by DB layer. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices that should be detached from the instance. :param destroy_disks: Indicates if disks should be destroyed """ #import pdb #pdb.set_trace() context = nova_context.get_admin_context() try: node = bm_driver._get_baremetal_node_by_instance_uuid(instance['uuid']) except exception.InstanceNotFound: LOG.warning(_("Destroy function called on a non-existing instance %s") % instance['uuid']) return try: macs = self.macs_for_instance(instance) nodename = self.xcat.get_xcat_node_name(macs) interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) fixed_ip=None if interfaces and interfaces[0]: if CONF.use_ipv6: fixed_ip = interfaces[0].get('address_v6') else: fixed_ip = interfaces[0].get('address') if fixed_ip: self.xcat.cleanup_node(nodename, fixed_ip) else: self.xcat.cleanup_node(nodename) except Exception as e: #just log it and move on LOG.warning(_("Destroy called with xCAT error:" + str(e))) try: self._detach_block_devices(instance, block_device_info) self._stop_firewall(instance, network_info) self._unplug_vifs(instance, network_info) bm_driver._update_state(context, node, None, baremetal_states.DELETED) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error(_("Error occurred while destroying instance %s: %s") % (instance['uuid'], str(e))) bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
def build_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) cheetah = _get_cheetah() network_config = str( cheetah(open(CONF.baremetal.net_config_template).read(), searchList=[{ 'interfaces': interfaces, 'use_ipv6': CONF.use_ipv6, }])) return network_config
def build_pxe_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) template = None if not CONF.use_ipv6: template = "ip=%(address)s::%(gateway)s:%(netmask)s::%(name)s:off" else: template = "ip=[%(address_v6)s]::[%(gateway_v6)s]:" "[%(netmask_v6)s]::%(name)s:off" net_config = [template % iface for iface in interfaces] return " ".join(net_config)
def build_pxe_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) template = None if not CONF.use_ipv6: template = "ip=%(address)s::%(gateway)s:%(netmask)s::%(name)s:off" else: template = ("ip=[%(address_v6)s]::[%(gateway_v6)s]:" "[%(netmask_v6)s]::%(name)s:off") net_config = [template % iface for iface in interfaces] return ' '.join(net_config)
def build_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) cheetah = _get_cheetah() network_config = str(cheetah( open(CONF.baremetal.net_config_template).read(), searchList=[ {'interfaces': interfaces, 'use_ipv6': CONF.use_ipv6, } ])) return network_config
def spawn( self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None ): """ Create a new instance/VM/domain on the virtualization platform. Once this successfully completes, the instance should be running (power_state.RUNNING). If this fails, any partial instance should be completely cleaned up, and the virtualization platform should be in the state that it was before this call began. :param context: security context :param instance: Instance object as returned by DB layer. This function should use the data there to guide the creation of the new instance. :param image_meta: image object returned by nova.image.glance that defines the image from which to boot this instance :param injected_files: User files to inject into instance. :param admin_password: Administrator password to set in instance. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices to be attached to the instance. """ # import pdb # pdb.set_trace() node_uuid = self._require_node(instance) node = db.bm_node_associate_and_update( context, node_uuid, { "instance_uuid": instance["uuid"], "instance_name": instance["hostname"], "task_state": baremetal_states.BUILDING, }, ) try: self._plug_vifs(instance, network_info, context=context) self._attach_block_devices(instance, block_device_info) self._start_firewall(instance, network_info) macs = self.macs_for_instance(instance) nodename = self.xcat.get_xcat_node_name(macs) imagename = self._get_xCAT_image_name(image_meta) hostname = instance.get("hostname") # get the network information for the new node interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) if CONF.use_ipv6: fixed_ip = interfaces[0].get("address_v6") netmask = interfaces[0].get("netmask_v6") gateway = interfaces[0].get("gateway_v6") else: fixed_ip = interfaces[0].get("address") netmask = interfaces[0].get("netmask") gateway = interfaces[0].get("gateway") # convert netmask from IPAddress to unicode string if netmask: netmask = unicode(netmask) # let xCAT install it bm_driver._update_state(context, node, instance, baremetal_states.DEPLOYING) self.xcat.deploy_node(nodename, imagename, hostname, fixed_ip, netmask, gateway) bm_driver._update_state(context, node, instance, baremetal_states.ACTIVE) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error( _("Error occured while deploying instance %(instance)s " "on baremetal node %(node)s: %(error)s") % {"instance": instance["uuid"], "node": node["uuid"], "error": str(e)} ) bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None): """ Create a new instance/VM/domain on the virtualization platform. Once this successfully completes, the instance should be running (power_state.RUNNING). If this fails, any partial instance should be completely cleaned up, and the virtualization platform should be in the state that it was before this call began. :param context: security context :param instance: Instance object as returned by DB layer. This function should use the data there to guide the creation of the new instance. :param image_meta: image object returned by nova.image.glance that defines the image from which to boot this instance :param injected_files: User files to inject into instance. :param admin_password: Administrator password to set in instance. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices to be attached to the instance. """ #import pdb #pdb.set_trace() node_uuid = self._require_node(instance) node = db.bm_node_associate_and_update( context, node_uuid, { 'instance_uuid': instance['uuid'], 'instance_name': instance['hostname'], 'task_state': baremetal_states.BUILDING }) try: self._plug_vifs(instance, network_info, context=context) self._attach_block_devices(instance, block_device_info) self._start_firewall(instance, network_info) macs = self.macs_for_instance(instance) nodename = self.xcat.get_xcat_node_name(macs) imagename = self._get_xCAT_image_name(image_meta) hostname = instance.get('hostname') #get the network information for the new node interfaces = bm_utils.map_network_interfaces( network_info, CONF.use_ipv6) if CONF.use_ipv6: fixed_ip = interfaces[0].get('address_v6') netmask = interfaces[0].get('netmask_v6') gateway = interfaces[0].get('gateway_v6') else: fixed_ip = interfaces[0].get('address') netmask = interfaces[0].get('netmask') gateway = interfaces[0].get('gateway') #convert netmask from IPAddress to unicode string if netmask: netmask = unicode(netmask) #let xCAT install it bm_driver._update_state(context, node, instance, baremetal_states.DEPLOYING) self.xcat.deploy_node(nodename, imagename, hostname, fixed_ip, netmask, gateway) bm_driver._update_state(context, node, instance, baremetal_states.ACTIVE) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error( _("Error occured while deploying instance %(instance)s " "on baremetal node %(node)s: %(error)s") % { 'instance': instance['uuid'], 'node': node['uuid'], 'error': str(e) }) bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
def destroy(self, instance, network_info, block_device_info=None, context=None): """Destroy (shutdown and delete) the specified instance. If the instance is not found (for example if networking failed), this function should still succeed. It's probably a good idea to log a warning in that case. :param context: security context :param instance: Instance object as returned by DB layer. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices that should be detached from the instance. :param destroy_disks: Indicates if disks should be destroyed """ #import pdb #pdb.set_trace() context = nova_context.get_admin_context() try: node = bm_driver._get_baremetal_node_by_instance_uuid( instance['uuid']) except exception.InstanceNotFound: LOG.warning( _("Destroy function called on a non-existing instance %s") % instance['uuid']) return try: macs = self.macs_for_instance(instance) nodename = self.xcat.get_xcat_node_name(macs) interfaces = bm_utils.map_network_interfaces( network_info, CONF.use_ipv6) fixed_ip = None if interfaces and interfaces[0]: if CONF.use_ipv6: fixed_ip = interfaces[0].get('address_v6') else: fixed_ip = interfaces[0].get('address') if fixed_ip: self.xcat.cleanup_node(nodename, fixed_ip) else: self.xcat.cleanup_node(nodename) except Exception as e: #just log it and move on LOG.warning(_("Destroy called with xCAT error:" + str(e))) try: self._detach_block_devices(instance, block_device_info) self._stop_firewall(instance, network_info) self._unplug_vifs(instance, network_info) bm_driver._update_state(context, node, None, baremetal_states.DELETED) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error( _("Error occurred while destroying instance %s: %s") % (instance['uuid'], str(e))) bm_driver._update_state(context, node, instance, baremetal_states.ERROR)