# 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. """Module to provider util functions in all compass code .. moduleauthor:: Xiaodong Wang <*****@*****.**> """ import daemon import logging import signal import sys import time from compass.utils import flags flags.add_bool('daemonize', help='run as daemon', default=False) BUSY = False KILLED = False def handle_term(signum, frame): """Handle sig term.""" global KILLED logging.info('Caught signal %s in %s', signum, frame) KILLED = True if not BUSY: sys.exit(0) def _daemon(callback, run_interval):
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='') flags.add('print_cluster_properties', help='comma separated cluster config properties to print', default='') flags.add('search_host_properties', help='comma separated properties to search in host config',
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', default=True) flags.add('machines', help='comma separated mac addresses of machines', default='') flags.add('adapter_os_name', help='adapter os name', default=r'(?i)centos.*') flags.add('adapter_target_system', help='adapter target system name', default='openstack') flags.add('cluster_name', help='cluster name', default='cluster1') flags.add('credentials', help=(
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) poll_switches = [] all_switches = dict([ (switch['ip'], switch['credentials'])
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) BUSY = False KILLED = False
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
# # 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)
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) delete_underlying_host = flags.OPTIONS.delete_hosts for cluster in clusters:
import switch_virtualenv from compass.actions import delete from compass.db.api import cluster as cluster_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('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 ]
# limitations under the License. """Module to provider util functions in all compass code .. moduleauthor:: Xiaodong Wang <*****@*****.**> """ import daemon import logging import signal import sys import time from compass.utils import flags flags.add_bool("daemonize", help="run as daemon", default=False) BUSY = False KILLED = False def handle_term(signum, frame): """Handle sig term.""" global KILLED logging.info("Caught signal %s in %s", signum, frame) KILLED = True if not BUSY: sys.exit(0)
import logging import sys 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.actions import trigger_install flags.add('clusterids', help='comma seperated cluster ids', default='') flags.add_bool('async', help='ryn in async mode') def main(argv): flags.init() logsetting.init() clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() trigger_clusterids = [cluster.id for cluster in clusters] else: trigger_clusterids = clusterids
#!/usr/bin/python import logging import sys 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.actions import trigger_install flags.add('clusterids', help='comma seperated cluster ids', default='') flags.add_bool('async', help='ryn in async mode') def main(argv): flags.init() logsetting.init() clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() trigger_clusterids = [cluster.id for cluster in clusters] else: trigger_clusterids = clusterids logging.info('trigger installer for clusters: %s', trigger_clusterids) for clusterid in trigger_clusterids: