def test_bm_pxe_ip_associate(self): self._create_pxe_ip() node = db.bm_node_create(self.context, utils.new_bm_node()) ip_id = db.bm_pxe_ip_associate(self.context, node['id']) ref = db.bm_pxe_ip_get(self.context, ip_id) self.assertEqual(ref['bm_node_id'], node['id'])
def activate_bootloader(self, var, context, node, instance): tftp_root = var['tftp_root'] image_path = var['image_path'] deploy_aki_id = FLAGS.baremetal_deploy_kernel deploy_ari_id = FLAGS.baremetal_deploy_ramdisk aki_id = str(instance['kernel_id']) ari_id = str(instance['ramdisk_id']) images = [ (deploy_aki_id, 'deploy_kernel'), (deploy_ari_id, 'deploy_ramdisk'), (aki_id, 'kernel'), (ari_id, 'ramdisk'), ] utils.ensure_tree(tftp_root) if FLAGS.baremetal_pxe_vlan_per_host: tftp_paths = [i[1] for i in images] else: tftp_paths = [ os.path.join(str(instance['uuid']), i[1]) for i in images ] utils.ensure_tree(os.path.join(tftp_root, str(instance['uuid']))) LOG.debug("tftp_paths=%s", tftp_paths) def _cache_image_b(image_id, target): LOG.debug("fetching id=%s target=%s", image_id, target) _cache_image_x(context=context, image_id=image_id, target=target, user_id=instance['user_id'], project_id=instance['project_id']) for image, path in zip(images, tftp_paths): target = os.path.join(tftp_root, path) _cache_image_b(image[0], target) pxe_config_dir = os.path.join(tftp_root, 'pxelinux.cfg') pxe_config_path = os.path.join(pxe_config_dir, self._pxe_cfg_name(node)) root_mb = instance['root_gb'] * 1024 inst_type_id = instance['instance_type_id'] inst_type = instance_types.get_instance_type(inst_type_id) swap_mb = inst_type['swap'] if swap_mb < 1024: swap_mb = 1024 pxe_ip = None if FLAGS.baremetal_pxe_vlan_per_host: pxe_ip_id = bmdb.bm_pxe_ip_associate(context, node['id']) pxe_ip = bmdb.bm_pxe_ip_get(context, pxe_ip_id) deployment_key = _random_alnum(32) deployment_id = bmdb.bm_deployment_create(context, deployment_key, image_path, pxe_config_path, root_mb, swap_mb) deployment_iscsi_iqn = "iqn-%s" % str(instance['uuid']) iscsi_portal = None if FLAGS.baremetal_pxe_append_iscsi_portal: if pxe_ip: iscsi_portal = pxe_ip['server_address'] pxeconf = _build_pxe_config(deployment_id, deployment_key, deployment_iscsi_iqn, deployment_aki_path=tftp_paths[0], deployment_ari_path=tftp_paths[1], aki_path=tftp_paths[2], ari_path=tftp_paths[3], iscsi_portal=iscsi_portal) utils.ensure_tree(pxe_config_dir) libvirt_utils.write_to_file(pxe_config_path, pxeconf) if FLAGS.baremetal_pxe_vlan_per_host: vlan_id = node['prov_vlan_id'] server_address = pxe_ip['server_address'] client_address = pxe_ip['address'] _start_per_host_pxe_server(tftp_root, vlan_id, server_address, client_address)
def activate_bootloader(self, var, context, node, instance): tftp_root = var['tftp_root'] image_path = var['image_path'] deploy_aki_id = FLAGS.baremetal_deploy_kernel deploy_ari_id = FLAGS.baremetal_deploy_ramdisk aki_id = str(instance['kernel_id']) ari_id = str(instance['ramdisk_id']) images = [(deploy_aki_id, 'deploy_kernel'), (deploy_ari_id, 'deploy_ramdisk'), (aki_id, 'kernel'), (ari_id, 'ramdisk'), ] utils.ensure_tree(tftp_root) if FLAGS.baremetal_pxe_vlan_per_host: tftp_paths = [i[1] for i in images] else: tftp_paths = [os.path.join(str(instance['uuid']), i[1]) for i in images] utils.ensure_tree( os.path.join(tftp_root, str(instance['uuid']))) LOG.debug("tftp_paths=%s", tftp_paths) def _cache_image_b(image_id, target): LOG.debug("fetching id=%s target=%s", image_id, target) _cache_image_x(context=context, image_id=image_id, target=target, user_id=instance['user_id'], project_id=instance['project_id']) for image, path in zip(images, tftp_paths): target = os.path.join(tftp_root, path) _cache_image_b(image[0], target) pxe_config_dir = os.path.join(tftp_root, 'pxelinux.cfg') pxe_config_path = os.path.join(pxe_config_dir, self._pxe_cfg_name(node)) root_mb = instance['root_gb'] * 1024 inst_type_id = instance['instance_type_id'] inst_type = instance_types.get_instance_type(inst_type_id) swap_mb = inst_type['swap'] if swap_mb < 1024: swap_mb = 1024 pxe_ip = None if FLAGS.baremetal_pxe_vlan_per_host: pxe_ip_id = bmdb.bm_pxe_ip_associate(context, node['id']) pxe_ip = bmdb.bm_pxe_ip_get(context, pxe_ip_id) deployment_key = _random_alnum(32) deployment_id = bmdb.bm_deployment_create(context, deployment_key, image_path, pxe_config_path, root_mb, swap_mb) deployment_iscsi_iqn = "iqn-%s" % str(instance['uuid']) iscsi_portal = None if FLAGS.baremetal_pxe_append_iscsi_portal: if pxe_ip: iscsi_portal = pxe_ip['server_address'] pxeconf = _build_pxe_config(deployment_id, deployment_key, deployment_iscsi_iqn, deployment_aki_path=tftp_paths[0], deployment_ari_path=tftp_paths[1], aki_path=tftp_paths[2], ari_path=tftp_paths[3], iscsi_portal=iscsi_portal) utils.ensure_tree(pxe_config_dir) libvirt_utils.write_to_file(pxe_config_path, pxeconf) if FLAGS.baremetal_pxe_vlan_per_host: vlan_id = node['prov_vlan_id'] server_address = pxe_ip['server_address'] client_address = pxe_ip['address'] _start_per_host_pxe_server(tftp_root, vlan_id, server_address, client_address)