示例#1
0
    def test_extract_image_args_from_disks(self):
        args1 = ['--disk', '/path/to/image,opt1=val1,opt2=val2']
        args2 = ['--disk', 'opt1=val1,path=/path/to/image,opt2=val2']
        args3 = ['-b', '-c', '--something']

        self.assertEqual(['-a', '/path/to/image'],
                         utils.extract_image_args_from_disks(args1))
        self.assertEqual(['-a', '/path/to/image'],
                         utils.extract_image_args_from_disks(args2))
        self.assertRaises(ValueError,
                          utils.extract_domain_or_image_args, args3)
示例#2
0
def _fetch_nics_from_image(args):
    image_args = utils.extract_image_args_from_disks(args)
    nic_names = _get_nic_names_from_image(image_args)
    command = ['guestfish', '-i', '--ro'] + image_args
    with open(FETCH_SCRIPT_TEMPLATE) as template_file:
        template = jinja2.Template(template_file.read())
    script = template.render(
        nic_config_dir=NIC_CONFIG_DIR,
        nic_config_prefix=NIC_CONFIG_PREFIX,
        nic_names=nic_names)
    LOG.debug('Running guestfish to get NIC config details: %s', str(command))
    fetcher = subprocess.Popen(command, stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, _ = fetcher.communicate(script)
    LOG.debug('guestfish returned: %s', output)
    return _filter_ethernet_nics(_parse_nics_output(output))
示例#3
0
def _fetch_nics_from_image(args):
    image_args = utils.extract_image_args_from_disks(args)
    nic_names = _get_nic_names_from_image(image_args)
    command = ['guestfish', '-i', '--ro'] + image_args
    with open(FETCH_SCRIPT_TEMPLATE) as template_file:
        template = jinja2.Template(template_file.read())
    script = template.render(nic_config_dir=NIC_CONFIG_DIR,
                             nic_config_prefix=NIC_CONFIG_PREFIX,
                             nic_names=nic_names)
    LOG.debug('Running guestfish to get NIC config details: %s', str(command))
    fetcher = subprocess.Popen(command,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    output, _ = fetcher.communicate(script)
    LOG.debug('guestfish returned: %s', output)
    return _filter_ethernet_nics(_parse_nics_output(output))