Openstack - Glance image を直接 MySQL を操作して削除

## What's this?

`glance image-delete` で image 削除したにもかかわらず、なぜか `glance image-list` で Status=deleted で表示され続ける事があったので、直接 MySQL を操作して削除してみた。

    # glance image-list
    +--------------------------------------+---------+-------------+------------------+----------+---------+
    | ID                                   | Name    | Disk Format | Container Format | Size     | Status  |
    +--------------------------------------+---------+-------------+------------------+----------+---------+
    | 5b62762b-9fd8-479b-a62c-011d2a744032 | image02 | raw         | bare             | 41126400 | deleted |
    | 93610bcc-0dda-4082-a8dd-66dbc562a12f | image01 | qcow2       | bare             | 13167616 | active  |
    +--------------------------------------+---------+-------------+------------------+----------+---------+

## Procedure

#### MySQL login

    # mysql -uroot

#### Database 参照

    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | cinder             |
    | glance             |
    | heat               |
    | keystone           |
    | murano             |
    | mysql              |
    | neutron            |
    | nova               |
    | performance_schema |
    | sahara             |
    | test               |
    +--------------------+
    12 rows in set (0.00 sec)

#### Glance Database に接続

    mysql> use glance;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed

#### Table 参照

    mysql> show tables;
    +----------------------------------+
    | Tables_in_glance                 |
    +----------------------------------+
    | image_locations                  |
    | image_members                    |
    | image_properties                 |
    | image_tags                       |
    | images                           |
    | metadef_namespace_resource_types |
    | metadef_namespaces               |
    | metadef_objects                  |
    | metadef_properties               |
    | metadef_resource_types           |
    | migrate_version                  |
    | task_info                        |
    | tasks                            |
    +----------------------------------+
    13 rows in set (0.00 sec)

#### Images Table 参照

    mysql> desc images;
    +------------------+--------------+------+-----+---------+-------+
    | Field            | Type         | Null | Key | Default | Extra |
    +------------------+--------------+------+-----+---------+-------+
    | id               | varchar(36)  | NO   | PRI | NULL    |       |
    | name             | varchar(255) | YES  |     | NULL    |       |
    | size             | bigint(20)   | YES  |     | NULL    |       |
    | status           | varchar(30)  | NO   |     | NULL    |       |
    | is_public        | tinyint(1)   | NO   | MUL | NULL    |       |
    | created_at       | datetime     | NO   |     | NULL    |       |
    | updated_at       | datetime     | YES  |     | NULL    |       |
    | deleted_at       | datetime     | YES  |     | NULL    |       |
    | deleted          | tinyint(1)   | NO   | MUL | NULL    |       |
    | disk_format      | varchar(20)  | YES  |     | NULL    |       |
    | container_format | varchar(20)  | YES  |     | NULL    |       |
    | checksum         | varchar(32)  | YES  | MUL | NULL    |       |
    | owner            | varchar(255) | YES  | MUL | NULL    |       |
    | min_disk         | int(11)      | NO   |     | NULL    |       |
    | min_ram          | int(11)      | NO   |     | NULL    |       |
    | protected        | tinyint(1)   | YES  |     | NULL    |       |
    | virtual_size     | bigint(20)   | YES  |     | NULL    |       |
    +------------------+--------------+------+-----+---------+-------+
    17 rows in set (0.06 sec)

    mysql> select name, deleted from images;
    +---------+---------+
    | name    | deleted |
    +---------+---------+
    | image01 |       0 |
    | image02 |       0 |
    | image03 |       1 |
    +---------+---------+
    3 rows in set (0.00 sec)

#### 削除したい image の deleted flag に "1" を設定

    mysql> update images set deleted=1 where name="image02";
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0

    mysql> select name, deleted from images;
    +---------+---------+
    | name    | deleted |
    +---------+---------+
    | image01 |       0 |
    | image02 |       1 |
    | image03 |       1 |
    +---------+---------+
    3 rows in set (0.00 sec)

#### MySQL logout

    mysql> quit
    Bye

#### 確認

    # glance image-list
    +---------+--------+-------------+------------------+----------+--------+
    | ID      | Name   | Disk Format | Container Format | Size     | Status |
    +---------+--------+-------------+------------------+----------+--------+
    | image01 | TestVM | qcow2       | bare             | 13167616 | active |
    +---------+--------+-------------+------------------+----------+--------+

## Environment

    Openstack : Juno

    # glance --version
    0.15.0

    # mysql --version
    mysql  Ver 14.14 Distrib 5.6.16, for Linux (x86_64) using  EditLine wrapper