Пример #1
0
from flask.ext.script import Manager

from compass.api import app
from compass.config_management.utils import config_manager
from compass.config_management.utils import config_reference
from compass.db import database
from compass.db.model import Adapter, Role, Switch, SwitchConfig
from compass.db.model import Machine, HostState, ClusterState
from compass.db.model import Cluster, ClusterHost, LogProgressingHistory
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('table_name',
          help='table name',
          default='')
flags.add('clusters',
          help=(
              'clusters to clean, the format is as '
              'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add('fake_switches_file',
          help=(
              'files for switches and machines '
              'connected to each switch. each line in the file '
              'is <switch ip>,<switch port>,<vlan>,<mac>'),
          default='')
flags.add('fake_switches_vendor',
          help='switch vendor used to set fake switch and machines.',
          default='huawei')
Пример #2
0
import functools
import lockfile
import logging

from compass.actions import update_progress
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util


flags.add('clusters',
          help=(
              'clusters to clean, the format is as '
              'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add_bool('async',
               help='run in async mode',
               default=True)
flags.add('run_interval',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)


def progress_update(cluster_hosts):
    """entry function."""
    if flags.OPTIONS.async:
        celery.send_task('compass.tasks.update_progress', (cluster_hosts,))
    else:
Пример #3
0
# 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.

"""script to import roles to chef server."""
import logging
import os
import os.path
import sys

from compass.utils import flags
from compass.utils import logsetting


flags.add('roles_dir',
          help='chef roles directory',
          default='/var/chef/roles')


def main():
    """main entry."""
    flags.init()
    logsetting.init()
    rolelist = []
    roles_dir = flags.OPTIONS.roles_dir

    for item in os.listdir(roles_dir):
        if item.endswith('.rb'):
            rolelist.append(os.path.join(roles_dir, item))
        else:
            logging.info('ignore %s in %s', item, roles_dir)
Пример #4
0
sys.path.append(current_dir)

import switch_virtualenv

from compass.actions import clean
from compass.db.api import adapter_holder as adapter_api
from compass.db.api import database
from compass.db.api import user as user_api
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting

flags.add_bool('async', help='run in async mode', default=True)

flags.add('os_installers', help='comma seperated os installers', default='')
flags.add('package_installers',
          help='comma separated package installers',
          default='')


def clean_installers():
    os_installers = [
        os_installer for os_installer in flags.OPTIONS.os_installers.split(',')
        if os_installer
    ]
    package_installers = [
        package_installer
        for package_installer in flags.OPTIONS.package_installers.split(',')
        if package_installer
    ]
Пример #5
0

import switch_virtualenv


from compass.db.api import cluster as cluster_api
from compass.db.api import database
from compass.db.api import host as host_api
from compass.db.api import user as user_api
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('clusternames',
          help='comma seperated cluster names',
          default='')
flags.add_bool('delete_hosts',
               help='if all hosts related to the cluster will be deleted',
               default=False)


def delete_clusters():
    clusternames = [
        clustername
        for clustername in flags.OPTIONS.clusternames.split(',')
        if clustername
    ]
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
    list_cluster_args = {}
    if clusternames:
Пример #6
0

import switch_virtualenv

import netaddr
import requests
import simplejson as json

from compass.apiclient.restful import Client
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import util


flags.add('compass_server',
          help='compass server url',
          default='http://127.0.0.1/api')
flags.add('compass_user_email',
          help='compass user email',
          default='*****@*****.**')
flags.add('compass_user_password',
          help='compass user password',
          default='admin')
flags.add('switch_ips',
          help='comma seperated switch ips',
          default='')
flags.add('switch_credential',
          help='comma separated <credential key>=<credential value>',
          default='version=2c,community=public')
flags.add('switch_max_retries', type='int',
          help='max retries of poll switch',
Пример #7
0
import signal
import sys
import time
import daemon

from compass.actions import progress_update
from compass.db import database
from compass.db.model import Cluster
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('clusterids',
          help='comma seperated cluster ids',
          default='')
flags.add_bool('async',
               help='ryn in async mode',
               default=True)
flags.add_bool('once',
               help='run once or forever',
               default=False)
flags.add('run_interval',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)
flags.add_bool('daemonize',
               help='run as daemon',
               default=False)

Пример #8
0
"""main script to run as service to update hosts installing progress."""
import logging
import signal
import sys
import time
import daemon

from compass.actions import progress_update
from compass.db import database
from compass.db.model import Cluster
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting

flags.add('clusterids', help='comma seperated cluster ids', default='')
flags.add_bool('async', help='ryn in async mode', default=True)
flags.add_bool('once', help='run once or forever', default=False)
flags.add('run_interval',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)
flags.add_bool('daemonize', help='run as daemon', default=False)

BUSY = False
KILLED = False


def handle_term(signum, frame):
    global BUSY
    global KILLED
    logging.info('Caught signal %s', signum)
Пример #9
0
from multiprocessing import Pool

from compass.actions import poll_switch
from compass.actions import util
from compass.db.api import database
from compass.db.api import switch as switch_api
from compass.db.api import user as user_api
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('switch_ips',
          help='comma seperated switch ips',
          default='')
flags.add_bool('async',
               help='ryn in async mode',
               default=True)
flags.add('thread_pool_size', type='int',
          help='thread pool size when run in noasync mode',
          default=4)
flags.add('run_interval', type='int',
          help='run interval in seconds',
          default=setting.POLLSWITCH_INTERVAL)


def pollswitches(switch_ips):
    """poll switch."""
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
Пример #10
0
# limitations under the License.
"""main script to run as service to update hosts installing progress."""
import functools
import lockfile
import logging

from compass.actions import update_progress
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util

flags.add('clusters',
          help=('clusters to clean, the format is as '
                'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add_bool('async', help='run in async mode', default=True)
flags.add('run_interval',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)


def progress_update(cluster_hosts):
    """entry function."""
    if flags.OPTIONS. async:
        celery.send_task('compass.tasks.update_progress', (cluster_hosts, ))
    else:
        try:
            update_progress.update_progress(cluster_hosts)
        except Exception as error:
Пример #11
0
current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir)

import switch_virtualenv

import netaddr
import requests
import simplejson as json

from compass.apiclient.restful import Client
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import util

flags.add('compass_server',
          help='compass server url',
          default='http://127.0.0.1/api')
flags.add('compass_user_email',
          help='compass user email',
          default='*****@*****.**')
flags.add('compass_user_password',
          help='compass user password',
          default='admin')
flags.add('switch_ips', help='comma seperated switch ips', default='')
flags.add('switch_credential',
          help='comma separated <credential key>=<credential value>',
          default='version=2c,community=public')
flags.add('switch_max_retries',
          type='int',
          help='max retries of poll switch',
          default=10)
Пример #12
0
from compass.actions import update_progress
from compass.db.api import database
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util


flags.add_bool('async',
               help='run in async mode',
               default=True)
flags.add('run_interval', type='int',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)


def progress_update():
    """entry function."""
    if flags.OPTIONS.async:
        celery.send_task('compass.tasks.update_progress', ())
    else:
        try:
            update_progress.update_progress()
        except Exception as error:
            logging.error('failed to update progress')
            logging.exception(error)

Пример #13
0
"""Ansible playbook callback after a playbook run has completed."""
import logging
import os
import simplejson as json
import sys

current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir + '/..')

import switch_virtualenv

from compass.apiclient.restful import Client
from compass.utils import flags

flags.add('compass_server',
          help='compass server url',
          default='http://127.0.0.1/api')
flags.add('compass_user_email',
          help='compass user email',
          default='*****@*****.**')
flags.add('compass_user_password',
          help='compass user password',
          default='admin')


class CallbackModule(object):
    def __init__(self):
        self.disabled = False
        try:
            self.client = self._get_client()
        except Exception:
Пример #14
0
"""Module to setup logging configuration.

   .. moduleauthor:: Xiaodong Wang <*****@*****.**>
"""

import logging
import logging.handlers
import os
import sys
import os.path

from compass.utils import flags
from compass.utils import setting_wrapper as setting


flags.add('loglevel',
          help='logging level', default=setting.DEFAULT_LOGLEVEL)
flags.add('logdir',
          help='logging directory', default=setting.DEFAULT_LOGDIR)
flags.add('logfile',
          help='logging filename', default=None)
flags.add('log_interval', type='int',
          help='log interval', default=setting.DEFAULT_LOGINTERVAL)
flags.add('log_interval_unit',
          help='log interval unit', default=setting.DEFAULT_LOGINTERVAL_UNIT)
flags.add('log_format',
          help='log format', default=setting.DEFAULT_LOGFORMAT)


# mapping str setting in flag --loglevel to logging level.
LOGLEVEL_MAPPING = {
    'finest': logging.DEBUG - 2,  # more detailed log.
Пример #15
0
import logging
import os
import os.path
import sys

from flask.ext.script import Manager

from compass.api import app
from compass.config_management.utils import config_manager
from compass.db import database
from compass.db.model import Adapter, Role, Switch, Machine, HostState, ClusterState, Cluster, ClusterHost, LogProgressingHistory
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting

flags.add('table_name', help='table name', default='')

manager = Manager(app, usage="Perform database operations")

TABLE_MAPPING = {
    'role': Role,
    'adapter': Adapter,
    'switch': Switch,
    'machine': Machine,
    'hoststate': HostState,
    'clusterstate': ClusterState,
    'cluster': Cluster,
    'clusterhost': ClusterHost,
    'logprogressinghistory': LogProgressingHistory,
}
Пример #16
0
from multiprocessing import Pool

from compass.actions import poll_switch
from compass.actions import util
from compass.db.api import database
from compass.db.api import switch as switch_api
from compass.db.api import user as user_api
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('switch_ips',
          help='comma seperated switch ips',
          default='')
flags.add_bool('async',
               help='ryn in async mode',
               default=True)
flags.add('thread_pool_size', type='int',
          help='thread pool size when run in noasync mode',
          default=4)
flags.add('run_interval', type='int',
          help='run interval in seconds',
          default=setting.POLLSWITCH_INTERVAL)


def pollswitches(switch_ips):
    """poll switch."""
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
Пример #17
0
from compass.actions import clean
from compass.db.api import adapter_holder as adapter_api
from compass.db.api import database
from compass.db.api import user as user_api
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add_bool('async',
               help='run in async mode',
               default=True)

flags.add('os_installers',
          help='comma seperated os installers',
          default='')
flags.add('package_installers',
          help='comma separated package installers',
          default='')


def clean_installers():
    os_installers = [
        os_installer
        for os_installer in flags.OPTIONS.os_installers.split(',')
        if os_installer
    ]
    package_installers = [
        package_installer
        for package_installer in flags.OPTIONS.package_installers.split(',')
Пример #18
0
import logging
import sys
import signal
import time

from compass.actions import poll_switch 
from compass.db import database
from compass.db.model import Switch
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('switchids',
          help='comma seperated switch ids',
          default='')
flags.add_bool('async',
               help='ryn in async mode',
               default=True)
flags.add_bool('once',
               help='run once or forever',
               default=False)
flags.add('run_interval',
          help='run interval in seconds',
          default=setting.POLLSWITCH_INTERVAL)
flags.add_bool('daemonize',
               help='run as daemon',
               default=False)

Пример #19
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 cookbooks to chef server."""
import logging
import os
import os.path
import sys

from compass.utils import flags
from compass.utils import logsetting

flags.add('cookbooks_dir',
          help='chef cookbooks directory',
          default='/var/chef/cookbooks')


def main():
    """main entry."""
    flags.init()
    logsetting.init()
    cookbooks_dir = flags.OPTIONS.cookbooks_dir
    logging.info('add cookbooks %s', cookbooks_dir)
    cmd = "knife cookbook upload --all --cookbook-path %s" % cookbooks_dir
    status = os.system(cmd)
    logging.info('run cmd %s returns %s', cmd, status)
    if status:
        sys.exit(1)
Пример #20
0
import os.path
import sys

from flask.ext.script import Manager

from compass.api import app
from compass.config_management.utils import config_manager
from compass.db import database
from compass.db.model import Adapter, Role, Switch, Machine, HostState, ClusterState, Cluster, ClusterHost, LogProgressingHistory    
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting


flags.add('table_name',
          help='table name',
          default='')


manager = Manager(app, usage="Perform database operations")


TABLE_MAPPING = {
    'role': Role,
    'adapter': Adapter,
    'switch': Switch,
    'machine': Machine,
    'hoststate': HostState,
    'clusterstate': ClusterState,
    'cluster': Cluster,
    'clusterhost': ClusterHost,
Пример #21
0
import os
import os.path
import shutil
import sys

from flask.ext.script import Manager

from compass.api import app
from compass.config_management.utils import config_manager
from compass.db import database
from compass.db.model import Adapter, Role, Switch, Machine, HostState, ClusterState, Cluster, ClusterHost, LogProgressingHistory
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting

flags.add('table_name', help='table name', default='')
flags.add('clusters',
          help=('clusters to clean, the format is as '
                'clusterid:hostname1,hostname2,...;...'),
          default='')

manager = Manager(app, usage="Perform database operations")

TABLE_MAPPING = {
    'role': Role,
    'adapter': Adapter,
    'switch': Switch,
    'machine': Machine,
    'hoststate': HostState,
    'clusterstate': ClusterState,
    'cluster': Cluster,
Пример #22
0
"""Module to setup logging configuration.

   .. moduleauthor:: Xiaodong Wang <*****@*****.**>
"""

import logging
import logging.handlers
import os
import sys
import os.path

from compass.utils import flags
from compass.utils import setting_wrapper as setting

flags.add('loglevel', help='logging level', default=setting.DEFAULT_LOGLEVEL)
flags.add('logdir', help='logging directory', default=setting.DEFAULT_LOGDIR)
flags.add('logfile', help='logging filename', default=None)
flags.add('log_interval',
          type='int',
          help='log interval',
          default=setting.DEFAULT_LOGINTERVAL)
flags.add('log_interval_unit',
          help='log interval unit',
          default=setting.DEFAULT_LOGINTERVAL_UNIT)
flags.add('log_format', help='log format', default=setting.DEFAULT_LOGFORMAT)

# mapping str setting in flag --loglevel to logging level.
LOGLEVEL_MAPPING = {
    'finest': logging.DEBUG - 2,  # more detailed log.
    'fine': logging.DEBUG - 1,  # detailed log.
    'debug': logging.DEBUG,
Пример #23
0
# 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 databags to chef server."""
import logging
import os
import os.path
import sys

from compass.utils import flags
from compass.utils import logsetting


flags.add('databags_dir',
          help='chef databags directory',
          default='/var/chef/databags')


def main():
    """main entry."""
    flags.init()
    logsetting.init()
    databags = []
    databags_dir = flags.OPTIONS.databags_dir
    for item in os.listdir(databags_dir):
        databags.append(item)

    for databag in databags:
        logging.info('add databag %s', databag)
        cmd = "knife data bag create %s" % databag
Пример #24
0
import sys

from distutils.version import LooseVersion
from ansible import __version__ as __ansible_version__
from ansible.plugins.callback import CallbackBase

compass_bin = "/opt/compass/bin"
sys.path.append(compass_bin)

import switch_virtualenv  # noqa: F401

from compass.apiclient.restful import Client  # noqa: E402
from compass.utils import flags  # noqa: E402

flags.add('compass_server',
          help='compass server url',
          default='http://compass-deck/api')
flags.add('compass_user_email',
          help='compass user email',
          default='*****@*****.**')
flags.add('compass_user_password',
          help='compass user password',
          default='admin')


class CallbackModule(CallbackBase):
    CALLBACK_VERSION = 2.0
    CALLBACK_TYPE = 'notification'
    CALLBACK_NAME = 'playbook_done'
    CALLBACK_NEEDS_WHITELIST = True
Пример #25
0
#
#     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.

"""main script to start an instance of compass server ."""
import logging

from compass.api import app
from compass.utils import flags
from compass.utils import logsetting


flags.add('server_host',
          help='server host address',
          default='0.0.0.0')
flags.add_bool('debug',
               help='run in debug mode',
               default=True)


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    logging.info('run server')
    app.run(host=flags.OPTIONS.server_host, debug=flags.OPTIONS.debug)
Пример #26
0
from compass.actions import deploy
from compass.actions import reinstall
from compass.api import app
from compass.db.api import database
from compass.db.api import switch as switch_api
from compass.db.api import user as user_api
from compass.tasks.client import celery
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util


flags.add('table_name',
          help='table name',
          default='')
flags.add('clusters',
          help=(
              'clusters and hosts of each cluster, the format is as '
              'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add_bool('async',
               help='ryn in async mode',
               default=True)
flags.add('switch_machines_file',
          help=(
              'files for switches and machines '
              'connected to each switch. each line in the file '
              'is machine,<switch ip>,<switch port>,<vlan>,<mac> '
              'or switch,<switch_ip>,<switch_vendor>,'
Пример #27
0
#
#     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.

"""main script to start an instance of compass server ."""
import logging

from compass.api import app
from compass.utils import flags
from compass.utils import logsetting


flags.add('server_host',
          help='server host address',
          default='0.0.0.0')
flags.add_bool('debug',
               help='run in debug mode',
               default=True)


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    logging.info('run server')
    app.run(host=flags.OPTIONS.server_host, debug=flags.OPTIONS.debug)
Пример #28
0
#!/usr/bin/env python

import logging
import os
import os.path


from compass.utils import flags
from compass.utils import logsetting


flags.add('cookbooks_dir',
          help='chef cookbooks directory',
          default='/var/chef/cookbooks')


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    cookbooks = []
    cookbooks_dir = flags.OPTIONS.cookbooks_dir
    logging.info('add cookbooks %s', cookbooks_dir)
    cmd = "knife cookbook upload --all --cookbook-path %s" % cookbooks_dir
    os.system(cmd)

Пример #29
0
# limitations under the License.
"""script to import roles to chef server."""
import logging
import os
import os.path
import sys

current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir)

import switch_virtualenv

from compass.utils import flags
from compass.utils import logsetting

flags.add('roles_dir', help='chef roles directory', default='/var/chef/roles')


def main():
    """main entry."""
    flags.init()
    logsetting.init()
    rolelist = []
    roles_dir = flags.OPTIONS.roles_dir

    for item in os.listdir(roles_dir):
        if item.endswith('.rb') or item.endswith('.json'):
            rolelist.append(os.path.join(roles_dir, item))
        else:
            logging.info('ignore %s in %s', item, roles_dir)
Пример #30
0
# See the License for the specific language governing permissions and
# limitations under the License.

"""binary to deploy a cluster by compass client api."""
import logging
import re
import requests
import time

from compass.apiclient.restful import Client
from compass.utils import flags
from compass.utils import logsetting


flags.add('compass_server',
          help='compass server url',
          default='http://127.0.0.1/api')
flags.add('switch_ips',
          help='comma seperated switch ips',
          default='')
flags.add('switch_credential',
          help='comma separated <credential key>=<credential value>',
          default='version=v2c,community=public')
flags.add('switch_max_retries', type='int',
          help='max retries of poll switch',
          default=5)
flags.add('switch_retry_interval', type='int',
          help='interval to repoll switch',
          default=10)
flags.add_bool('poll_switches',
               help='if the client polls switches',
Пример #31
0
"""import databags to chef server."""
import logging
import os
import os.path
import sys

current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir)

import switch_virtualenv

from compass.utils import flags
from compass.utils import logsetting

flags.add('databags_dir',
          help='chef databags directory',
          default='/var/chef/databags')


def main():
    """main entry."""
    flags.init()
    logsetting.init()
    databags = []
    databags_dir = flags.OPTIONS.databags_dir
    for item in os.listdir(databags_dir):
        databags.append(item)

    for databag in databags:
        logging.info('add databag %s', databag)
        cmd = "knife data bag create %s" % databag
Пример #32
0
import yaml

from flask_script import Manager

from compass.api import app
from compass.db.api import database
from compass.db.api import switch as switch_api
from compass.db.api import machine as machine_api
from compass.db.api import network as network_api
from compass.db.api import user as user_api
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util

flags.add('table_name', help='table name', default='')
flags.add('clusters',
          help=('clusters and hosts of each cluster, the format is as '
                'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add_bool('async', help='ryn in async mode', default=True)
flags.add('switch_machines_file',
          help=('files for switches and machines '
                'connected to each switch. each line in the file '
                'is machine,<switch ip>,<switch port>,<vlan>,<mac> '
                'or switch,<switch_ip>,<switch_vendor>,'
                '<switch_version>,<switch_community>,<switch_state>'),
          default='')
flags.add('machine_file',
          help=('file for add machine '
                'contains one or more mac address of a host '
Пример #33
0
import sys

current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir)

import switch_virtualenv

from compass.db.api import cluster as cluster_api
from compass.db.api import database
from compass.db.api import host as host_api
from compass.db.api import user as user_api
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting

flags.add('clusternames', help='comma seperated cluster names', default='')
flags.add_bool('delete_hosts',
               help='if all hosts related to the cluster will be deleted',
               default=False)


def delete_clusters():
    clusternames = [
        clustername for clustername in flags.OPTIONS.clusternames.split(',')
        if clustername
    ]
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
    list_cluster_args = {}
    if clusternames:
        list_cluster_args['name'] = clusternames
    clusters = cluster_api.list_clusters(user=user, **list_cluster_args)
Пример #34
0
sys.path.append(current_dir)

import switch_virtualenv

from flask_script import Manager

from compass.api import app
from compass.db.api import database
from compass.db.api import switch as switch_api
from compass.db.api import user as user_api
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util

flags.add('table_name', help='table name', default='')
flags.add('clusters',
          help=('clusters and hosts of each cluster, the format is as '
                'clusterid:hostname1,hostname2,...;...'),
          default='')
flags.add_bool('async', help='ryn in async mode', default=True)
flags.add('switch_machines_file',
          help=('files for switches and machines '
                'connected to each switch. each line in the file '
                'is machine,<switch ip>,<switch port>,<vlan>,<mac> '
                'or switch,<switch_ip>,<switch_vendor>,'
                '<switch_version>,<switch_community>,<switch_state>'),
          default='')
flags.add('search_cluster_properties',
          help='comma separated properties to search in cluster config',
          default='')
Пример #35
0
import switch_virtualenv

import lockfile

from compass.actions import update_progress
from compass.db.api import database
from compass.tasks.client import celery
from compass.utils import daemonize
from compass.utils import flags
from compass.utils import logsetting
from compass.utils import setting_wrapper as setting
from compass.utils import util

flags.add_bool('async', help='run in async mode', default=True)
flags.add('run_interval',
          type='int',
          help='run interval in seconds',
          default=setting.PROGRESS_UPDATE_INTERVAL)


def progress_update():
    """entry function."""
    if flags.OPTIONS. async:
        celery.send_task('compass.tasks.update_progress', ())
    else:
        try:
            update_progress.update_progress()
        except Exception as error:
            logging.error('failed to update progress')
            logging.exception(error)