OpenStack Novaのメタデータ更新時の動作

Junoの話。

インスタンス削除後の`nova show`はできないので、DBにSELECTをかけるしかない。`show`できるようにするblueprintは漂流中。

## メタデータ追加
`nova meta instance1 set key1=value1`

```
mysql> select * from instance_metadata;
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| created_at          | updated_at | deleted_at          | id | key  | value  | instance_uuid                        | deleted |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| 2015-09-07 08:38:15 | NULL       | NULL                |  2 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       0 |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
```

## メタデータ削除
`nova meta instance1 delete key1`

```
mysql> select * from instance_metadata;
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| created_at          | updated_at | deleted_at          | id | key  | value  | instance_uuid                        | deleted |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| 2015-09-07 08:38:15 | NULL       | 2015-09-07 08:38:58 |  2 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       2 |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
```

`deleted_at`が更新され、`deleted`フラグが正の値になる。

## メタデータ再追加
`nova meta instance1 set key1=value1`

```
mysql> select * from instance_metadata;
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| created_at          | updated_at | deleted_at          | id | key  | value  | instance_uuid                        | deleted |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
| 2015-09-07 08:38:15 | NULL       | 2015-09-07 08:38:58 |  2 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       2 |
| 2015-09-07 08:39:29 | NULL       | NULL                |  3 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       0 |
+---------------------+------------+---------------------+----+------+--------+--------------------------------------+---------+
```

入りなおし。

## メタデータ更新
`nova meta instance set key1=value2`

```
mysql> select * from instance_metadata;
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
| created_at          | updated_at          | deleted_at          | id | key  | value  | instance_uuid                        | deleted |
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
| 2015-09-07 08:38:15 | NULL                | 2015-09-07 08:38:58 |  2 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       2 |
| 2015-09-07 08:39:29 | 2015-09-07 08:40:07 | NULL                |  3 | key1 | value2 | 18222f80-1266-4bb9-bbaf-653992957581 |       0 |
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
```

`updated_at`が更新。

## インスタンス削除
`nova delete instance1`

```
mysql> select * from instance_metadata;
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
| created_at          | updated_at          | deleted_at          | id | key  | value  | instance_uuid                        | deleted |
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
| 2015-09-07 08:38:15 | NULL                | 2015-09-07 08:38:58 |  2 | key1 | value1 | 18222f80-1266-4bb9-bbaf-653992957581 |       2 |
| 2015-09-07 08:39:29 | 2015-09-07 08:40:07 | 2015-09-07 08:40:24 |  3 | key1 | value2 | 18222f80-1266-4bb9-bbaf-653992957581 |       3 |
+---------------------+---------------------+---------------------+----+------+--------+--------------------------------------+---------+
```