TerraformにするかHeatにするか悩んで、いったんTerraformにしたのだけど、一応Heatも触っておいた方がいいなあと思ったので軽く触る(決める時に触っておこうよという話だが…)。試すだけであればPackStackが楽。例によって、「触ってみた」以上の情報はない。なお、http://docs.openstack.org/developer/heat/ に全ての情報は書かれており、Mitakaを使って試した。
インスタンスを作成する
何はともあれインスタンスを作ってみよう。以下のようなテンプレートを用意する。
heat_template_version: 2016-04-08 description: テストだよ。 resources: my_instance: type: OS::Nova::Server properties: name: hoge key_name: r_takaishi image: cirros flavor: m1.tiny
作成。引数の最後で指定しているのはStackの名前で、Stackとはリソースの集合ということのようだ。また、Terraformはインスタンスの作成などは同期実行だが、HeatはOpenStack上のコントローラーがやってくれるので非同期実行である。
$ openstack stack create -t ./r_takaishi.yml r_takaishi +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | id | 5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | stack_name | r_takaishi | | description | テストだよ。 | | creation_time | 2017-02-13T11:58:10Z | | updated_time | None | | stack_status | CREATE_IN_PROGRESS | | stack_status_reason | Stack CREATE started | +---------------------+--------------------------------------+
スタックの詳細を見てみる。
$ openstack stack show r_takaishi +-----------------------+--------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------------+--------------------------------------------------------------------------------------------------------------------------+ | id | 5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | stack_name | r_takaishi | | description | テストだよ。 | | creation_time | 2017-02-13T11:58:10Z | | updated_time | None | | stack_status | CREATE_COMPLETE | | stack_status_reason | Stack CREATE completed successfully | | parameters | OS::project_id: 130a838dafb3440b81fb8b2332b2c965 | | | OS::stack_id: 5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | | OS::stack_name: r_takaishi | | | | | outputs | [] | | | | | links | - href: http://127.0.0.1:8004/v1/130a838dafb3440b81fb8b2332b2c965/stacks/r_takaishi/5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | | rel: self | | | | | parent | None | | disable_rollback | True | | deletion_time | None | | stack_user_project_id | f8e641a4c3be4badad9f9facc6948bf9 | | capabilities | [] | | notification_topics | [] | | stack_owner | None | | timeout_mins | None | | tags | null | | | ... | | | | +-----------------------+--------------------------------------------------------------------------------------------------------------------------+
作成されたリソース一覧。
$ openstack stack resource list r_takaishi +---------------+--------------------------------------+------------------+-----------------+----------------------+ | resource_name | physical_resource_id | resource_type | resource_status | updated_time | +---------------+--------------------------------------+------------------+-----------------+----------------------+ | my_instance | 882382de-9997-451f-9105-1f7577943146 | OS::Nova::Server | CREATE_COMPLETE | 2017-02-13T11:58:10Z | +---------------+--------------------------------------+------------------+-----------------+----------------------+
Horizonからもいろいろ見ることができる。
トポロジーがあった。ほうほう。
リソース一覧。
イベントの一覧も見られる。ここを見ればどのような操作が行われたのか分かるのは便利そう。
というわけで、インスタンスは無事に作成できた。次は、ネットワークを作成してみる。
ネットワークを作成する
manage-networks のサンプルをコピペしてきて、少しリソース名を変更した。
heat_template_version: 2016-04-08 description: テストだよ。 resources: my_instance: type: OS::Nova::Server properties: name: hoge key_name: r_takaishi image: cirros flavor: m1.tiny my_net: type: OS::Neutron::Net my_subnet: type: OS::Neutron::Subnet properties: network_id: { get_resource: my_net } cidr: "10.8.1.0/24" dns_nameservers: [ "8.8.8.8", "8.8.4.4" ] ip_version: 4
スタックを更新することでネットワークとサブネットが作られる模様。dry-runがあるのでまずはそれを試す。
$ openstack stack update --dry-run -t ./r_takaishi.yml r_takaishi +-----------+--------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------+--------------------------------------------------------------------------------------------------------------------------------+ | added | [ | | | { | | | "resource_name": "my_net", | | | "resource_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "/resources/my_net" | | | }, | | | "description": "", | | | "stack_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "" | | | }, | | | "stack_name": "r_takaishi", | | | "creation_time": null, | | | "resource_action": "INIT", | | | "resource_status": "COMPLETE", | | | "updated_time": null, | | | "required_by": [ | | | "my_subnet" | | | ], | | | "resource_status_reason": "", | | | "physical_resource_id": "", | | | "attributes": { | | | "status": null, | | | "subnets": null, | | | "qos_policy_id": null, | | | "admin_state_up": null, | | | "tenant_id": null, | | | "mtu": null, | | | "port_security_enabled": null, | | | "name": null | | | }, | | | "resource_type": "OS::Neutron::Net", | | | "metadata": {} | | | }, | | | { | | | "resource_name": "my_subnet", | | | "resource_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "/resources/my_subnet" | | | }, | | | "description": "", | | | "stack_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "" | | | }, | | | "stack_name": "r_takaishi", | | | "creation_time": null, | | | "resource_action": "INIT", | | | "resource_status": "COMPLETE", | | | "updated_time": null, | | | "required_by": [], | | | "resource_status_reason": "", | | | "physical_resource_id": "", | | | "attributes": { | | | "name": null, | | | "enable_dhcp": null, | | | "network_id": null, | | | "tenant_id": null, | | | "dns_nameservers": null, | | | "allocation_pools": null, | | | "host_routes": null, | | | "ip_version": null, | | | "gateway_ip": null, | | | "cidr": null | | | }, | | | "resource_type": "OS::Neutron::Subnet", | | | "metadata": {} | | | } | | | ] | | deleted | [] | | replaced | [] | | unchanged | [] | | updated | [ | | | { | | | "resource_name": "my_instance", | | | "resource_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "/resources/my_instance" | | | }, | | | "description": "", | | | "stack_identity": { | | | "stack_name": "r_takaishi", | | | "stack_id": "5d85e9a7-92e9-42b4-8c49-279f3f0cf7be", | | | "tenant": "130a838dafb3440b81fb8b2332b2c965", | | | "path": "" | | | }, | | | "stack_name": "r_takaishi", | | | "creation_time": "2017-02-13T11:58:10Z", | | | "resource_action": "CREATE", | | | "resource_status": "COMPLETE", | | | "updated_time": "2017-02-13T11:58:10Z", | | | "required_by": [], | | | "resource_status_reason": "state changed", | | | "physical_resource_id": "882382de-9997-451f-9105-1f7577943146", | | | "attributes": { | | | "OS-EXT-STS:task_state": null, | | | "addresses": { | | | "public": [ | | | { | | | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:a6:79:ad", | | | "version": 4, | | | "addr": "172.24.4.229", | | | "OS-EXT-IPS:type": "fixed" | | | } | | | ] | | | }, | | | "links": [ | | | { | | | "href": "http://127.0.0.1:8774/v2.1/130a838dafb3440b81fb8b2332b2c965/servers/882382de-9997-451f-9105-1f7577943146", | | | "rel": "self" | | | }, | | | { | | | "href": "http://127.0.0.1:8774/130a838dafb3440b81fb8b2332b2c965/servers/882382de-9997-451f-9105-1f7577943146", | | | "rel": "bookmark" | | | } | | | ], | | | "image": { | | | "id": "dd058582-d46c-4cef-84cf-2c96c0429ef2", | | | "links": [ | | | { | | | "href": "http://127.0.0.1:8774/130a838dafb3440b81fb8b2332b2c965/images/dd058582-d46c-4cef-84cf-2c96c0429ef2", | | | "rel": "bookmark" | | | } | | | ] | | | }, | | | "OS-EXT-STS:vm_state": "active", | | | "OS-EXT-SRV-ATTR:instance_name": "instance-00000002", | | | "OS-SRV-USG:launched_at": "2017-02-13T11:58:18.000000", | | | "flavor": { | | | "id": "1", | | | "links": [ | | | { | | | "href": "http://127.0.0.1:8774/130a838dafb3440b81fb8b2332b2c965/flavors/1", | | | "rel": "bookmark" | | | } | | | ] | | | }, | | | "id": "882382de-9997-451f-9105-1f7577943146", | | | "security_groups": [ | | | { | | | "name": "default" | | | } | | | ], | | | "user_id": "0e4b78ebf745422ea8acaa4aa3df754b", | | | "OS-DCF:diskConfig": "MANUAL", | | | "accessIPv4": "", | | | "accessIPv6": "", | | | "progress": 0, | | | "OS-EXT-STS:power_state": 1, | | | "OS-EXT-AZ:availability_zone": "nova", | | | "metadata": {}, | | | "status": "ACTIVE", | | | "updated": "2017-02-13T11:58:18Z", | | | "hostId": "e829214bd5943100a3546508fe272237d372572620c6f47c70a68641", | | | "OS-EXT-SRV-ATTR:host": "controller", | | | "OS-SRV-USG:terminated_at": null, | | | "key_name": "r_takaishi", | | | "OS-EXT-SRV-ATTR:hypervisor_hostname": "controller", | | | "name": "hoge", | | | "created": "2017-02-13T11:58:11Z", | | | "tenant_id": "130a838dafb3440b81fb8b2332b2c965", | | | "os-extended-volumes:volumes_attached": [], | | | "config_drive": "" | | | }, | | | "resource_type": "OS::Nova::Server", | | | "metadata": {} | | | } | | | ] | +-----------+--------------------------------------------------------------------------------------------------------------------------------+
滅茶苦茶長いが、追加したmy_netとmy_subnetがaddedにあることが分かる。これ、リソース増えた時収集つくのだろうか?
ひとまずそれは置いておき、本番実行する。
$ openstack stack update -t ./r_takaishi.yml r_takaishi +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | id | 5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | stack_name | r_takaishi | | description | テストだよ。 | | creation_time | 2017-02-13T11:58:10Z | | updated_time | 2017-02-13T12:19:35Z | | stack_status | UPDATE_IN_PROGRESS | | stack_status_reason | Stack UPDATE started | +---------------------+--------------------------------------+
完了。ネットワークとサブネットが作成されたのか、イベントを見てみる。なお、CLIからも見られるのでそちらを試す。
$ openstack stack event list r_takaishi 2017-02-13 11:58:10Z [r_takaishi]: CREATE_IN_PROGRESS Stack CREATE started 2017-02-13 11:58:11Z [r_takaishi.my_instance]: CREATE_IN_PROGRESS state changed 2017-02-13 11:58:19Z [r_takaishi.my_instance]: CREATE_COMPLETE state changed 2017-02-13 11:58:19Z [r_takaishi]: CREATE_COMPLETE Stack CREATE completed successfully 2017-02-13 12:19:35Z [r_takaishi]: UPDATE_IN_PROGRESS Stack UPDATE started 2017-02-13 12:19:35Z [r_takaishi.my_net]: CREATE_IN_PROGRESS state changed 2017-02-13 12:19:35Z [r_takaishi.my_net]: CREATE_COMPLETE state changed 2017-02-13 12:19:35Z [r_takaishi.my_subnet]: CREATE_IN_PROGRESS state changed 2017-02-13 12:19:36Z [r_takaishi.my_subnet]: CREATE_COMPLETE state changed 2017-02-13 12:19:36Z [r_takaishi]: UPDATE_COMPLETE Stack UPDATE completed successfully
ちゃんと作成されているようだ。リソース一覧もCLIから見られるので見てみよう。
$ openstack stack resource list r_takaishi +---------------+--------------------------------------+---------------------+-----------------+----------------------+ | resource_name | physical_resource_id | resource_type | resource_status | updated_time | +---------------+--------------------------------------+---------------------+-----------------+----------------------+ | my_net | e219ca84-d822-4d49-bfeb-339328f1fdc7 | OS::Neutron::Net | CREATE_COMPLETE | 2017-02-13T12:19:35Z | | my_subnet | 9af0d331-1d87-441f-8061-1aa0f8046c21 | OS::Neutron::Subnet | CREATE_COMPLETE | 2017-02-13T12:19:35Z | | my_instance | 882382de-9997-451f-9105-1f7577943146 | OS::Nova::Server | CREATE_COMPLETE | 2017-02-13T11:58:10Z | +---------------+--------------------------------------+---------------------+-----------------+----------------------+
ふむふむ〜。トポロジーを見ると、ネットワークとサブネットが追加されていた。
しかし、ネットワークトポロジーを見ると、パブリックネットワークに繋がっているが、今作成したネットワークには繋がっていない。インスタンスのネットワークを設定していないので、当然である。
というわけで、次はmy_netにインスタンスを繋げる。
インスタンスをネットワークに繋げる
my_instanceでnetworksを設定してやるだけでよい。なお、Publicネットワークとの接続はなくなるはず。
heat_template_version: 2016-04-08 description: テストだよ。 resources: my_instance: type: OS::Nova::Server properties: name: hoge key_name: r_takaishi image: cirros flavor: m1.tiny networks: - network: { get_resource: my_net } my_net: type: OS::Neutron::Net my_subnet: type: OS::Neutron::Subnet properties: network_id: { get_resource: my_net } cidr: "10.8.1.0/24" dns_nameservers: [ "8.8.8.8", "8.8.4.4" ] ip_version: 4
dry-runの結果は滅茶苦茶長いので省略。
$ openstack stack update -t ./r_takaishi.yml r_takaishi +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | id | 5d85e9a7-92e9-42b4-8c49-279f3f0cf7be | | stack_name | r_takaishi | | description | テストだよ。 | | creation_time | 2017-02-13T11:58:10Z | | updated_time | 2017-02-13T12:28:40Z | | stack_status | UPDATE_IN_PROGRESS | | stack_status_reason | Stack UPDATE started | +---------------------+--------------------------------------+
イベント一覧を見ると、インスタンスが更新されていることがわかる。
$ openstack stack event list r_takaishi 2017-02-13 11:58:10Z [r_takaishi]: CREATE_IN_PROGRESS Stack CREATE started 2017-02-13 11:58:11Z [r_takaishi.my_instance]: CREATE_IN_PROGRESS state changed 2017-02-13 11:58:19Z [r_takaishi.my_instance]: CREATE_COMPLETE state changed 2017-02-13 11:58:19Z [r_takaishi]: CREATE_COMPLETE Stack CREATE completed successfully 2017-02-13 12:19:35Z [r_takaishi]: UPDATE_IN_PROGRESS Stack UPDATE started 2017-02-13 12:19:35Z [r_takaishi.my_net]: CREATE_IN_PROGRESS state changed 2017-02-13 12:19:35Z [r_takaishi.my_net]: CREATE_COMPLETE state changed 2017-02-13 12:19:35Z [r_takaishi.my_subnet]: CREATE_IN_PROGRESS state changed 2017-02-13 12:19:36Z [r_takaishi.my_subnet]: CREATE_COMPLETE state changed 2017-02-13 12:19:36Z [r_takaishi]: UPDATE_COMPLETE Stack UPDATE completed successfully 2017-02-13 12:28:40Z [r_takaishi]: UPDATE_IN_PROGRESS Stack UPDATE started 2017-02-13 12:28:41Z [r_takaishi.my_instance]: UPDATE_IN_PROGRESS state changed 2017-02-13 12:28:46Z [r_takaishi.my_instance]: UPDATE_COMPLETE state changed 2017-02-13 12:28:47Z [r_takaishi]: UPDATE_COMPLETE Stack UPDATE completed successfully
インスタンスを見てみる。
$ openstack server show hoge +--------------------------------------+----------------------------------------------------------+ | Field | Value | +--------------------------------------+----------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | controller | | OS-EXT-SRV-ATTR:hypervisor_hostname | controller | | OS-EXT-SRV-ATTR:instance_name | instance-00000002 | | OS-EXT-STS:power_state | Running | | OS-EXT-STS:task_state | None | | OS-EXT-STS:vm_state | active | | OS-SRV-USG:launched_at | 2017-02-13T11:58:18.000000 | | OS-SRV-USG:terminated_at | None | | accessIPv4 | | | accessIPv6 | | | addresses | r_takaishi-my_net-v26sicemoajs=10.8.1.8 | | config_drive | | | created | 2017-02-13T11:58:11Z | | flavor | m1.tiny (1) | | hostId | e829214bd5943100a3546508fe272237d372572620c6f47c70a68641 | | id | 882382de-9997-451f-9105-1f7577943146 | | image | cirros (dd058582-d46c-4cef-84cf-2c96c0429ef2) | | key_name | r_takaishi | | name | hoge | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | project_id | 130a838dafb3440b81fb8b2332b2c965 | | properties | | | security_groups | [{u'name': u'default'}] | | status | ACTIVE | | updated | 2017-02-13T11:58:18Z | | user_id | 0e4b78ebf745422ea8acaa4aa3df754b | +--------------------------------------+----------------------------------------------------------+
my_netに繋がっている。ネットワークトポロジーを見ても、my_netに繋がっていることが分かった。
まとめ
Heatを使ってインスタンスを作成した。また、ネットワーク・サブネットを追加したあと、最初に作ったインスタンスをそのネットワークに繋げてみた。
参考リンクは以下の通りです。
2 Comments