<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2010 Openstack, LLC.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    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.

"""
Scheduler Service
"""

import functools
import novatools

from datetime import datetime

from nova import db
from nova import flags
from nova import log as logging
from nova import manager
from nova import rpc
from nova import utils

LOG = logging.getLogger('nova.scheduler.manager')
FLAGS = flags.FLAGS
flags.DEFINE_string('scheduler_driver',
                    'nova.scheduler.chance.ChanceScheduler',
                    'Driver to use for the scheduler')
flags.DEFINE_integer('zone_db_check_interval',
                    60,
                    'Seconds between getting fresh zone info from db.')


class ZoneState(object):
    """Holds the state of all connected child zones."""
    def __init__(self):
       self.is_active = True
       self.name = None
       self.capabilities = None
       self.retry = 0
       self.last_seen = datetime.min

    def update(self, zone):
       self.zone_id = zone.id
       self.api_url = zone.api_url
       self.username = zone.username
       self.password = <PASSWORD>


class ZoneManager(object):
    """Keeps the zone states updated."""
    def __init__(self):
        self.last_zone_db_check = datetime.min
        self.zone_states = {}

    def _refresh_from_db(self, context):
        zones = db.zone_get_all(context)
        existing = self.zone_states.keys()
        for zone in zones:
            if zone.id not in existing:
                self.zone_state[zone.id] = ZoneState()
            self.zone_state[zones.id].update(zone)
 
    def _poll_zones(self, context):
        pass

    def ping(self, context=None):
        """Ping should be called periodically to update zone status."""
        logging.debug("ZoneManager PING")
        diff = datetime.now() - self.last_zone_db_check
        if diff.seconds >=  FLAGS.zone_db_check_interval:
            logging.debug("ZoneManager RECHECKING DB ")
            self.last_zone_db_check = datetime.now()<commit_msg>novatools call to child zones done<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2010 Openstack, LLC.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    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.

"""
Scheduler Service
"""

import functools
import novatools
import thread

from datetime import datetime
from eventlet.greenpool import GreenPool

from nova import db
from nova import flags
from nova import log as logging
from nova import manager
from nova import rpc
from nova import utils

LOG = logging.getLogger('nova.scheduler.manager')
FLAGS = flags.FLAGS
flags.DEFINE_string('scheduler_driver',
                    'nova.scheduler.chance.ChanceScheduler',
                    'Driver to use for the scheduler')
flags.DEFINE_integer('zone_db_check_interval',
                    60,
                    'Seconds between getting fresh zone info from db.')


class ZoneState(object):
    """Holds the state of all connected child zones."""
    def __init__(self):
        self.is_active = True
        self.name = None
        self.capabilities = None
        self.retry = 0
        self.last_seen = datetime.min
 
    def update(self, zone):
        """Update zone credentials from db"""
        self.zone_id = zone.id
        self.api_url = zone.api_url
        self.username = zone.username
        self.password = zone.password
 

def _poll_zone(zone):
    """Eventlet worker to poll a zone."""
    logging.debug("_POLL_ZONE: STARTING")
    os = novatools.OpenStack(zone.username, zone.password, zone.api_url)
    zone_metadata = os.zones.info()
    logging.debug("_POLL_ZONE: GOT %s" % zone_metadata._info)

    # Stuff this in our cache.


class ZoneManager(object):
    """Keeps the zone states updated."""
    def __init__(self):
        self.last_zone_db_check = datetime.min
        self.zone_states = {}

    def _refresh_from_db(self, context):
        """Make our zone state map match the db."""
        # Add/update existing zones ...
        zones = db.zone_get_all(context)
        existing = self.zone_states.keys()
        db_keys = []
        for zone in zones:
            db_keys.append(zone.id)
            if zone.id not in existing:
                self.zone_states[zone.id] = ZoneState()
            self.zone_states[zone.id].update(zone)

        # Cleanup zones removed from db ...
        for zone_id in self.zone_states.keys():
            if zone_id not in db_keys:
                del self.zone_states[zone_id]
 
    def _poll_zones(self, context):
        """Try to connect to each child zone and get update."""

        green_pool = GreenPool()
        green_pool.imap(_poll_zone, self.zone_states.values())

    def ping(self, context=None):
        """Ping should be called periodically to update zone status."""
        logging.debug("ZoneManager PING")
        diff = datetime.now() - self.last_zone_db_check
        if diff.seconds >=  FLAGS.zone_db_check_interval:
            logging.debug("ZoneManager RECHECKING DB ")
            self.last_zone_db_check = datetime.now()
{'fraction_non_alphanumeric': 0.08562548562548562, 'fraction_numerical': 0.005594405594405594, 'mean_word_length': 2.735345327916425, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2234347', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1777, 'n_words': 600}