summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/config-osa/templates/create-network.yml.j2
blob: 301bf9da56f5cf5e199e8da02ea1f7a65aab5659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
- name: Create external network
  hosts: utility_container[0]
  max_fail_percentage: 20
  user: root
  tasks:
    - name: create external net
      shell: |
        . /root/openrc;
        openstack network create --external \
        --provider-physical-network {{ public_net_info.provider_network }} \
        --provider-network-type {{ public_net_info.type }}  {{ public_net_info.network }};
      when: {{ public_net_info.enable }} == True
            and "{{ public_net_info.type }}" == "flat"

    - name: create external net
      shell: |
        . /root/openrc;
        openstack network create --external \
        --network-segment {{ public_net_info.segment_id }} \
        --provider-network-type {{ public_net_info.type }}  {{ public_net_info.network }};
      when: {{public_net_info.enable}} == True
            and "{{ public_net_info.type }}" != "flat"

    - name: create external subnet
      shell: |
        . /root/openrc;
        openstack subnet create --network "{{ public_net_info.network }}" \
        --allocation-pool \
        start={{ public_net_info.floating_ip_start }},end={{ public_net_info.floating_ip_end }} \
        --gateway "{{ public_net_info.external_gw }}" \
        --subnet-range "{{ public_net_info.floating_ip_cidr }}" \
        "{{ public_net_info.subnet }}"
pan> argparse import json import logging HOSTNAME = socket.gethostname() PROG_NAME = 'ovs_pmd_stats' TYPE = 'counter' MAIN_THREAD = 'main thread' PMD_THREAD = 'pmd thread' REQUEST_MESSAGE = '{"id":0,"method":"dpif-netdev/pmd-stats-show","params":[]}' RESPONSE_MESSAGE_TIMEOUT = 1.0 # Setup arguments parser = argparse.ArgumentParser(prog=PROG_NAME) parser.add_argument('--socket-pid-file', required=True, help='ovs-vswitchd.pid file location') args = parser.parse_args() try: fp = open(args.socket_pid_file, 'r') pid = fp.readline() fp.close() except IOError as e: logging.error('I/O error({}): {}'.format(e.errno, e.strerror)) raise SystemExit() except: logging.error('Unexpected error:', sys.exc_info()[0]) raise SystemExit() server_address = args.socket_pid_file.replace('.pid', '.{}.ctl'.format(pid.strip())) # open unix socket to ovs-vswitch sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: sock.connect(server_address) except socket.error as msg: logging.error('Socket address: {} Error: {}'.format(server_address, msg)) raise SystemExit() # set timeout sock.settimeout(RESPONSE_MESSAGE_TIMEOUT) # send request sock.sendall(REQUEST_MESSAGE) # listen for respnse message rdata = '' while True: try: rdata += sock.recv(4096) if rdata.count('{') == rdata.count('}'): break except socket.timeout: logging.error('Response message has not been received in {} sec.'.format(RESPONSE_MESSAGE_TIMEOUT)) raise SystemExit() except socket.error as e: logging.error('Error received while reading: {}'.format(e.strerror)) raise SystemExit() # parse the message try: s = json.loads(rdata, strict=False) except ValueError as e: logging.error('Failed to parse JSON response: {}'.format(e.strerror)) raise SystemExit() # check for key string presence in the string if 'result' not in s or 'id' not in s or 'error' not in s: logging.error("One of the keys: ['id'], ['result'], ['error'] is missed in the response") logging.error('Msg: {}'.format(s)) raise SystemExit() array = s['result'].replace('\t', '').splitlines() # submit metrics in collectd format plugin_instance = '' for el in array: if MAIN_THREAD in el or PMD_THREAD in el: plugin_instance = el[:-1].replace(' ', '_') else: type_instance = el.split(':')[0].replace(' ', "_") value = el.split(':')[1].split(' ')[0] print('PUTVAL %s/%s-%s/%s-%s N:%s' % (HOSTNAME, PROG_NAME, plugin_instance, TYPE, type_instance, value)) # close socket sock.close()