Пример #1
0
 def test_parse_compute_hosts(self):
     assert common.parse_compute_hosts('') == []
     assert common.parse_compute_hosts('test1, test2') == \
         ['test1', 'test2']
     assert common.parse_compute_hosts('test-1, test_2') == \
         ['test-1', 'test_2']
     assert common.parse_compute_hosts('t1,,  t2 , t3') == \
         ['t1', 't2', 't3']
Пример #2
0
 def test_parse_compute_hosts(self):
     assert common.parse_compute_hosts('') == []
     assert common.parse_compute_hosts('test1, test2') == \
         ['test1', 'test2']
     assert common.parse_compute_hosts('test-1, test_2') == \
         ['test-1', 'test_2']
     assert common.parse_compute_hosts('t1,,  t2 , t3') == \
         ['t1', 't2', 't3']
Пример #3
0
def init_state(config):
    """ Initialize a dict for storing the state of the global manager.

    :param config: A config dictionary.
     :type config: dict(str: *)

    :return: A dict containing the initial state of the global managerr.
     :rtype: dict
    """
    return {
        'previous_time':
        0,
        'db':
        init_db(config['sql_connection']),
        'nova':
        client.Client(config['os_admin_user'],
                      config['os_admin_password'],
                      config['os_admin_tenant_name'],
                      config['os_auth_url'],
                      service_type="compute"),
        'hashed_username':
        sha1(config['os_admin_user']).hexdigest(),
        'hashed_password':
        sha1(config['os_admin_password']).hexdigest(),
        'compute_hosts':
        common.parse_compute_hosts(config['compute_hosts']),
        'host_macs': {}
    }
Пример #4
0
def init_state(config):
    """ Initialize a dict for storing the state of the global manager.

    :param config: A config dictionary.
     :type config: dict(str: *)

    :return: A dict containing the initial state of the global managerr.
     :rtype: dict
    """
    return {'previous_time': 0,
            'db': init_db(config['sql_connection']),
            'nova': client.Client(config['os_admin_user'],
                                  config['os_admin_password'],
                                  config['os_admin_tenant_name'],
                                  config['os_auth_url'],
                                  service_type="compute"),
            'hashed_username': sha1(config['os_admin_user']).hexdigest(),
            'hashed_password': sha1(config['os_admin_password']).hexdigest(),
            'compute_hosts': common.parse_compute_hosts(
                                        config['compute_hosts']),
            'host_macs': {}}
import sys


def vm_hostname(vm):
    return str(getattr(vm, 'OS-EXT-SRV-ATTR:host'))


config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                  REQUIRED_FIELDS)
db = manager.init_db(config['sql_connection'])
nova = client.Client(config['os_admin_user'],
                     config['os_admin_password'],
                     config['os_admin_tenant_name'],
                     config['os_auth_url'],
                     service_type="compute")
hosts = common.parse_compute_hosts(config['compute_hosts'])

hosts_cpu_total, hosts_cpu_cores, hosts_ram_total = \
    db.select_host_characteristics()
hosts_cpu_core = \
    dict((host, int(hosts_cpu_total[host] / hosts_cpu_cores[host]))
         for host in hosts_cpu_total.keys())
hosts_to_vms = manager.vms_by_hosts(nova, hosts)
vms = [item for sublist in hosts_to_vms.values() for item in sublist]

vms_names = []
vms_status = {}
for uuid in vms:
    vm = nova.servers.get(uuid)
    vms_names.append((vm.human_id, uuid))
    vms_status[uuid] = str(vm.status)
#!/usr/bin/python2

# Copyright 2012 Anton Beloglazov
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from neat.config import *
import neat.common as common

config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                  REQUIRED_FIELDS)
compute_hosts = common.parse_compute_hosts(config['compute_hosts'])

common.execute_on_hosts(compute_hosts,
                        ['service openstack-neat-data-collector stop'])
Пример #7
0
# Copyright 2012 Anton Beloglazov
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess

from neat.config import *
import neat.common as common


config = read_and_validate_config([DEFAULT_CONFIG_PATH, CONFIG_PATH], REQUIRED_FIELDS)
compute_hosts = common.parse_compute_hosts(config["compute_hosts"])

for host in compute_hosts:
    subprocess.call("ssh " + host + ' "mkdir -p /etc/neat"', shell=True)
    command = "scp /etc/neat/neat.conf " + host + ":/etc/neat"
    print "$ " + command
    output = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True).communicate()[0]
    if output:
        print output