Exemple #1
0
def glance_image_create_cmd(config,
                            image_name,
                            disk_format,
                            file_path,
                            container_format="bare"):
    """Generates glance command which creates image based on arguments
    provided. Command output is filtered for 'id'

    :returns: Openstack CLI command"""
    if file_path.startswith("http"):
        file_prefix = "location"
    else:
        file_prefix = "file"
    args = ("image-create "
            "--name {image_name} "
            "--disk-format={disk_format} "
            "--container-format={container_format} "
            "--{file_prefix} {file_path}").format(
                image_name=image_name,
                disk_format=disk_format,
                container_format=container_format,
                file_prefix=file_prefix,
                file_path=file_path)
    return r"{image_create} | grep '\<id\>'".format(
        image_create=clients.os_cli_cmd(config, 'glance', args))
Exemple #2
0
def glance_image_download_cmd(config, image_id, destination_file):
    """Generates glance command which stores `image_id` in `destination_file`

    :returns: Openstack CLI command
    """
    image_download_cmd = clients.os_cli_cmd(config, 'glance', 'image-download',
                                            image_id)

    return "{img_download_cmd} > {file}".format(
        img_download_cmd=image_download_cmd, file=destination_file)
Exemple #3
0
def glance_image_download_cmd(config, image_id, destination_file):
    """Generates glance command which stores `image_id` in `destination_file`

    :returns: Openstack CLI command
    """
    image_download_cmd = clients.os_cli_cmd(
        config, 'glance', 'image-download', image_id)

    return "{img_download_cmd} > {file}".format(
        img_download_cmd=image_download_cmd,
        file=destination_file)
Exemple #4
0
    def test_skips_region_if_not_set_in_config(self):
        config = mock.Mock()

        config.region = None
        config.tenant = 't1'
        config.user = '******'
        config.password = '******'
        config.auth_url = 'auth url'

        cmd = clients.os_cli_cmd(config, 'glance', 'help')

        self.assertNotIn('--os-region', cmd)
Exemple #5
0
def cobalt_live_migrate_vm(config, vm_id, dest_host):
    """Cobalt live migration is implemented as nova extension, so it's not
    reachable through standard `novaclient.v1_1.Client()` instance
    (or at least I was unable to find a way in a reasonable timeframe). Thus
    running it as a CLI command."""
    LOG.info("migrating %s to %s using Cobalt", vm_id, dest_host)

    host_string = "{user}@{host}".format(
        user=config.cloud.ssh_user, host=config.cloud.ssh_host)

    with settings(warn_only=True,
                  host_string=host_string,
                  key_filename=config.migrate.key_filename,
                  connection_attempts=config.migrate.ssh_connection_attempts):
        migrate_cmd = clients.os_cli_cmd(config.cloud, "nova",
                                         "cobalt-migrate", vm_id,
                                         "--dest", dest_host)

        LOG.debug(migrate_cmd)

        run(migrate_cmd)
Exemple #6
0
def cobalt_live_migrate_vm(config, vm_id, dest_host):
    """Cobalt live migration is implemented as nova extension, so it's not
    reachable through standard `novaclient.v1_1.Client()` instance
    (or at least I was unable to find a way in a reasonable timeframe). Thus
    running it as a CLI command."""
    LOG.info("migrating %s to %s using Cobalt", vm_id, dest_host)

    host_string = "{user}@{host}".format(user=config.cloud.ssh_user,
                                         host=config.cloud.ssh_host)

    with settings(warn_only=True,
                  host_string=host_string,
                  key_filename=config.migrate.key_filename,
                  connection_attempts=config.migrate.ssh_connection_attempts):
        migrate_cmd = clients.os_cli_cmd(config.cloud, "nova",
                                         "cobalt-migrate", vm_id, "--dest",
                                         dest_host)

        LOG.debug(migrate_cmd)

        run(migrate_cmd)
Exemple #7
0
    def test_builds_cmd_with_all_required_creds(self):
        config = mock.Mock()

        config.region = 'region1'
        config.tenant = 't1'
        config.user = '******'
        config.password = '******'
        config.auth_url = 'auth url'

        client = 'glance'
        args = ['image-get', 'image-id1']

        cmd = clients.os_cli_cmd(config, client, *args)

        self.assertIn('--os-tenant-name', cmd)
        self.assertIn('--os-username', cmd)
        self.assertIn('--os-password', cmd)
        self.assertIn('--os-auth-url', cmd)
        self.assertIn('--os-region', cmd)

        self.assertTrue(cmd.startswith(client))
        self.assertTrue(cmd.endswith(" ".join(args)))
Exemple #8
0
def glance_image_create_cmd(config, image_name, disk_format, file_path,
                            container_format="bare"):
    """Generates glance command which creates image based on arguments
    provided. Command output is filtered for 'id'

    :returns: Openstack CLI command"""
    if file_path.startswith("http"):
        file_prefix = "location"
    else:
        file_prefix = "file"
    args = ("image-create "
            "--name {image_name} "
            "--disk-format={disk_format} "
            "--container-format={container_format} "
            "--{file_prefix} {file_path}").format(
        image_name=image_name,
        disk_format=disk_format,
        container_format=container_format,
        file_prefix=file_prefix,
        file_path=file_path
    )
    return r"{image_create} | grep '\<id\>'".format(
        image_create=clients.os_cli_cmd(config, 'glance', args))