Skip to content

Instantly share code, notes, and snippets.

@kjelly
Last active November 20, 2019 03:19
Show Gist options
  • Save kjelly/c4826f5ceeb60013e4ab68103bb628cc to your computer and use it in GitHub Desktop.
Save kjelly/c4826f5ceeb60013e4ab68103bb628cc to your computer and use it in GitHub Desktop.
neutron-meter-agent for kolla-ansible rocky
From a5badc89f2dc1c4b711554a7960c28c1f34dc1b2 Mon Sep 17 00:00:00 2001
From: caoyuan <[email protected]>
Date: Sat, 15 Apr 2017 19:51:16 +0800
Subject: [PATCH] Add neutron metering role into kolla-ansible
Refer to neutron docs [1][2]
[1]: https://docs.openstack.org/neutron/pike/admin/archives/adv-config.html#l3-metering-service-driver
[2]: https://wiki.openstack.org/wiki/Neutron/Metering/Bandwidth
Co-Authored-By: ZhijunWei <[email protected]>
Change-Id: I4a676d041bc2a86497cb139d9347365738b156df
---
ansible/group_vars/all.yml | 1 +
ansible/inventory/all-in-one | 3 ++
ansible/inventory/multinode | 3 ++
ansible/roles/neutron/defaults/main.yml | 20 +++++++++++
ansible/roles/neutron/handlers/main.yml | 25 +++++++++++++
ansible/roles/neutron/tasks/config.yml | 20 +++++++++++
.../neutron/templates/metering_agent.ini.j2 | 3 ++
.../templates/neutron-metering-agent.json.j2 | 36 +++++++++++++++++++
ansible/site.yml | 1 +
etc/kolla/globals.yml | 1 +
...ron-metering-support-4266364hudc5l80c.yaml | 3 ++
tests/templates/inventory.j2 | 3 ++
12 files changed, 119 insertions(+)
create mode 100644 ansible/roles/neutron/templates/metering_agent.ini.j2
create mode 100644 ansible/roles/neutron/templates/neutron-metering-agent.json.j2
create mode 100644 releasenotes/notes/add-neutron-metering-support-4266364hudc5l80c.yaml
diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index c6c94284b..c9a73a391 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -517,6 +517,7 @@ enable_neutron_bgp_dragent: "no"
enable_neutron_provider_networks: "no"
enable_neutron_segments: "no"
enable_neutron_sfc: "no"
enable_neutron_infoblox_ipam_agent: "no"
enable_nova_serialconsole_proxy: "no"
enable_nova_ssh: "yes"
diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one
index 0fd9e7425..abf78d472 100644
--- a/ansible/inventory/all-in-one
+++ b/ansible/inventory/all-in-one
@@ -306,6 +306,9 @@ neutron
[neutron-infoblox-ipam-agent:children]
neutron
+[neutron-metering-agent:children]
+neutron
+
[ironic-neutron-agent:children]
neutron
diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode
index 6c23e0b83..bd1027514 100644
--- a/ansible/inventory/multinode
+++ b/ansible/inventory/multinode
@@ -325,6 +325,9 @@ neutron
[neutron-infoblox-ipam-agent:children]
neutron
+[neutron-metering-agent:children]
+neutron
+
[ironic-neutron-agent:children]
neutron
diff --git a/ansible/roles/neutron/defaults/main.yml b/ansible/roles/neutron/defaults/main.yml
index c8a9118a3..1af74f0ec 100644
--- a/ansible/roles/neutron/defaults/main.yml
+++ b/ansible/roles/neutron/defaults/main.yml
@@ -193,6 +193,19 @@ neutron_services:
- "/run:/run:shared"
- "kolla_logs:/var/log/kolla/"
dimensions: "{{ neutron_infoblox_ipam_agent_dimensions }}"
+ neutron-metering-agent:
+ container_name: "neutron_metering_agent"
+ image: "{{ neutron_metering_agent_image_full }}"
+ privileged: True
+ enabled: "{{ enable_neutron_metering | bool }}"
+ group: "neutron-metering-agent"
+ host_in_groups: "{{ inventory_hostname in groups['neutron-metering-agent'] }}"
+ volumes:
+ - "{{ node_config_directory }}/neutron-metering-agent/:{{ container_config_directory }}/:ro"
+ - "/etc/localtime:/etc/localtime:ro"
+ - "/run:/run:shared"
+ - "kolla_logs:/var/log/kolla/"
+ dimensions: "{{ neutron_metering_agent_dimensions }}"
ironic-neutron-agent:
container_name: "ironic_neutron_agent"
image: "{{ ironic_neutron_agent_image_full }}"
@@ -260,6 +273,10 @@ neutron_infoblox_ipam_agent_image: "{{ docker_registry ~ '/' if docker_registry
neutron_infoblox_ipam_agent_tag: "{{ neutron_tag }}"
neutron_infoblox_ipam_agent_image_full: "{{ neutron_infoblox_ipam_agent_image }}:{{ neutron_infoblox_ipam_agent_tag }}"
+neutron_metering_agent_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ neutron_install_type }}-neutron-metering-agent"
+neutron_metering_agent_tag: "{{ neutron_tag }}"
+neutron_metering_agent_image_full: "{{ neutron_metering_agent_image }}:{{ neutron_metering_agent_tag }}"
+
ironic_neutron_agent_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ neutron_install_type }}-ironic-neutron-agent"
ironic_neutron_agent_tag: "{{ neutron_tag }}"
ironic_neutron_agent_image_full: "{{ ironic_neutron_agent_image }}:{{ ironic_neutron_agent_tag }}"
@@ -275,6 +292,7 @@ neutron_server_dimensions: "{{ default_container_dimensions }}"
neutron_bgp_dragent_dimensions: "{{ default_container_dimensions }}"
neutron_infoblox_ipam_agent_dimensions: "{{ default_container_dimensions }}"
neutron_openvswitch_agent_xenapi_dimensions: "{{ default_container_dimensions }}"
+neutron_metering_agent_dimensions: "{{ default_container_dimensions }}"
ironic_neutron_agent_dimensions: "{{ default_container_dimensions }}"
@@ -332,6 +350,8 @@ service_plugins:
enabled: "{{ enable_neutron_lbaas | bool and not enable_octavia | bool }}"
- name: "lbaasv2-proxy"
enabled: "{{ enable_neutron_lbaas | bool and enable_octavia | bool }}"
+ - name: "metering"
+ enabled: "{{ enable_neutron_metering | bool }}"
- name: "neutron_dynamic_routing.services.bgp.bgp_plugin.BgpPlugin"
enabled: "{{ enable_neutron_bgp_dragent | bool }}"
- name: "qos"
diff --git a/ansible/roles/neutron/handlers/main.yml b/ansible/roles/neutron/handlers/main.yml
index a9c95df43..018453297 100644
--- a/ansible/roles/neutron/handlers/main.yml
+++ b/ansible/roles/neutron/handlers/main.yml
@@ -344,6 +344,31 @@
or neutron_ml2_conf | changed
or neutron_infoblox_ipam_agent_container | changed
+- name: Restart neutron-metering-agent container
+ vars:
+ service_name: "neutron-metering-agent"
+ service: "{{ neutron_services[service_name] }}"
+ config_json: "{{ neutron_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
+ neutron_conf: "{{ neutron_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
+ neutron_metering_agent_container: "{{ check_neutron_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
+ become: true
+ kolla_docker:
+ action: "recreate_or_restart_container"
+ common_options: "{{ docker_common_options }}"
+ name: "{{ service.container_name }}"
+ image: "{{ service.image }}"
+ volumes: "{{ service.volumes }}"
+ dimensions: "{{ service.dimensions }}"
+ privileged: "{{ service.privileged | default(False) }}"
+ when:
+ - kolla_action != "config"
+ - service.enabled | bool
+ - service.host_in_groups | bool
+ - config_json | changed
+ or neutron_conf | changed
+ or neutron_metering_agent_ini | changed
+ or neutron_metering_agent_container | changed
+
- name: Restart ironic-neutron-agent container
vars:
service_name: "ironic-neutron-agent"
diff --git a/ansible/roles/neutron/tasks/config.yml b/ansible/roles/neutron/tasks/config.yml
index 8f06a9300..c52b75934 100644
--- a/ansible/roles/neutron/tasks/config.yml
+++ b/ansible/roles/neutron/tasks/config.yml
@@ -55,6 +55,7 @@
- "neutron-l3-agent"
- "neutron-linuxbridge-agent"
- "neutron-metadata-agent"
+ - "neutron-metering-agent"
- "neutron-openvswitch-agent"
- "neutron-openvswitch-agent-xenapi"
- "neutron-server"
@@ -306,6 +307,24 @@
notify:
- "Restart {{ service_name }} container"
+- name: Copying over metering_agent.ini
+ become: true
+ vars:
+ service_name: "neutron-metering-agent"
+ neutron_metering_agent: "{{ neutron_services[service_name] }}"
+ merge_configs:
+ sources:
+ - "{{ role_path }}/templates/metering_agent.ini.j2"
+ - "{{ node_custom_config }}/neutron/metering_agent.ini"
+ dest: "{{ node_config_directory }}/{{ service_name }}/metering_agent.ini"
+ mode: "0660"
+ register: neutron_metering_agent_ini
+ when:
+ - neutron_metering_agent.enabled | bool
+ - neutron_metering_agent.host_in_groups | bool
+ notify:
+ - "Restart {{ service_name }} container"
+
- name: Copying over ironic_neutron_agent.ini
become: true
vars:
@@ -373,6 +392,7 @@
- "neutron-l3-agent"
- "neutron-linuxbridge-agent"
- "neutron-metadata-agent"
+ - "neutron-metering-agent"
- "neutron-openvswitch-agent"
- "neutron-openvswitch-agent-xenapi"
- "neutron-server"
diff --git a/ansible/roles/neutron/templates/metering_agent.ini.j2 b/ansible/roles/neutron/templates/metering_agent.ini.j2
new file mode 100644
index 000000000..3a8cc7254
--- /dev/null
+++ b/ansible/roles/neutron/templates/metering_agent.ini.j2
@@ -0,0 +1,3 @@
+[DEFAULT]
+interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
+driver = neutron.services.metering.drivers.iptables.iptables_driver.IptablesMeteringDriver
diff --git a/ansible/roles/neutron/templates/neutron-metering-agent.json.j2 b/ansible/roles/neutron/templates/neutron-metering-agent.json.j2
new file mode 100644
index 000000000..ad8272975
--- /dev/null
+++ b/ansible/roles/neutron/templates/neutron-metering-agent.json.j2
@@ -0,0 +1,36 @@
+{
+ "command": "neutron-metering-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/metering_agent.ini",
+ "config_files": [
+ {
+ "source": "{{ container_config_directory }}/neutron.conf",
+ "dest": "/etc/neutron/neutron.conf",
+ "owner": "neutron",
+ "perm": "0600"
+ },
+ {
+ "source": "{{ container_config_directory }}/metering_agent.ini",
+ "dest": "/etc/neutron/metering_agent.ini",
+ "owner": "neutron",
+ "perm": "0600"
+ },
+ {
+ "source": "{{ container_config_directory }}/policy.json",
+ "dest": "/etc/neutron/policy.json",
+ "owner": "neutron",
+ "perm": "0600",
+ "optional": true
+ }
+ ],
+ "permissions": [
+ {
+ "path": "/var/log/kolla/neutron",
+ "owner": "neutron:neutron",
+ "recurse": true
+ },
+ {
+ "path": "/var/lib/neutron/kolla",
+ "owner": "neutron:neutron",
+ "recurse": true
+ }
+ ]
+}
diff --git a/ansible/site.yml b/ansible/site.yml
index 3ccdb5369..7c4c54ebd 100644
--- a/ansible/site.yml
+++ b/ansible/site.yml
@@ -654,6 +654,7 @@
- neutron-lbaas-agent
- ironic-neutron-agent
- neutron-metadata-agent
+ - neutron-metering-agent
- compute
- manila-share
serial: '{{ kolla_serial|default("0") }}'
diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml
index 824414375..d430bf0ab 100644
--- a/etc/kolla/globals.yml
+++ b/etc/kolla/globals.yml
@@ -255,6 +255,7 @@ kolla_internal_vip_address: "10.10.10.254"
#enable_neutron_vpnaas: "no"
#enable_neutron_sriov: "no"
#enable_neutron_sfc: "no"
+#enable_neutron_metering: "no"
#enable_nova_fake: "no"
#enable_nova_serialconsole_proxy: "no"
#enable_nova_ssh: "yes"
diff --git a/releasenotes/notes/add-neutron-metering-support-4266364hudc5l80c.yaml b/releasenotes/notes/add-neutron-metering-support-4266364hudc5l80c.yaml
new file mode 100644
index 000000000..24697566c
--- /dev/null
+++ b/releasenotes/notes/add-neutron-metering-support-4266364hudc5l80c.yaml
@@ -0,0 +1,3 @@
+---
+features:
+ - Add neutron-metering-agent into kolla-ansible
diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2
index d3e00d0c0..e42ae3521 100644
--- a/tests/templates/inventory.j2
+++ b/tests/templates/inventory.j2
@@ -302,6 +302,9 @@ neutron
[neutron-infoblox-ipam-agent:children]
neutron
+[neutron-metering-agent:children]
+neutron
+
[ironic-neutron-agent:children]
neutron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment