def add_polling_schedules(self): """Add all the relevant cloud polling schedules This method simply adds all relevant polling schedules and sets their default settings. See the `mist.api.tasks.update_poller` task for dynamically adding new polling schedules or updating existing ones. """ # FIXME Imported here due to circular dependency issues. from mist.api.poller.models import ListMachinesPollingSchedule from mist.api.poller.models import ListNetworksPollingSchedule from mist.api.poller.models import ListLocationsPollingSchedule from mist.api.poller.models import ListSizesPollingSchedule # Add machines' polling schedule. ListMachinesPollingSchedule.add(cloud=self.cloud) # Add networks' polling schedule, if applicable. if hasattr(self.cloud.ctl, 'network'): ListNetworksPollingSchedule.add(cloud=self.cloud) # Add extra cloud-level polling schedules with lower frequency. Such # schedules poll resources that should hardly ever change. Thus, we # add the schedules, increase their interval, and forget about them. schedule = ListLocationsPollingSchedule.add(cloud=self.cloud) schedule.set_default_interval(60 * 60 * 24) schedule.save() schedule = ListSizesPollingSchedule.add(cloud=self.cloud) schedule.set_default_interval(60 * 60 * 24) schedule.save()
def set_polling_interval(self, interval): if not isinstance(interval, int): raise BadRequestError("Invalid interval type: %r" % interval) if interval != 0 and not 600 <= interval <= 3600 * 12: raise BadRequestError("Interval must be at least 10 mins " "and at most 12 hours.") self.cloud.polling_interval = interval self.cloud.save() # FIXME: Resolve circular import issues from mist.api.poller.models import ListMachinesPollingSchedule ListMachinesPollingSchedule.add(cloud=self.cloud)
def add_cloud_v_2(owner, title, provider, params): """Add cloud to owner""" # FIXME: Some of these should be explicit arguments, others shouldn't exist fail_on_error = params.pop('fail_on_error', params.pop('remove_on_error', True)) monitoring = params.pop('monitoring', False) params.pop('title', None) params.pop('provider', None) # Find proper Cloud subclass. if not provider: raise RequiredParameterMissingError("provider") log.info("Adding new cloud in provider '%s'", provider) if provider not in cloud_models.CLOUDS: raise BadRequestError("Invalid provider '%s'." % provider) cloud_cls = cloud_models.CLOUDS[provider] # Class of Cloud model. # Add the cloud. cloud = cloud_cls.add(owner, title, fail_on_error=fail_on_error, fail_on_invalid_params=False, **params) ret = {'cloud_id': cloud.id} if provider == 'bare_metal' and monitoring: # Let's overload this a bit more by also combining monitoring. machine = Machine.objects.get(cloud=cloud) ret['monitoring'] = enable_monitoring( owner, cloud.id, machine.machine_id, no_ssh=not (machine.os_type == 'unix' and machine.key_associations)) # SEC owner.mapper.update(cloud) log.info("Cloud with id '%s' added succesfully.", cloud.id) trigger_session_update(owner, ['clouds']) c_count = Cloud.objects(owner=owner, deleted=None).count() if owner.clouds_count != c_count: owner.clouds_count = c_count owner.save() cloud.polling_interval = 1800 # 30 min * 60 sec/min cloud.save() ListMachinesPollingSchedule.add(cloud=cloud) return ret
def add_cloud_v_2(owner, title, provider, params): """Add cloud to owner""" # FIXME: Some of these should be explicit arguments, others shouldn't exist fail_on_error = params.pop('fail_on_error', params.pop('remove_on_error', True)) params.pop('title', None) params.pop('provider', None) # Find proper Cloud subclass. if not provider: raise RequiredParameterMissingError("provider") log.info("Adding new cloud in provider '%s'", provider) if provider not in cloud_models.CLOUDS: raise BadRequestError("Invalid provider '%s'." % provider) cloud_cls = cloud_models.CLOUDS[provider] # Class of Cloud model. # Add the cloud. cloud = cloud_cls.add(owner, title, fail_on_error=fail_on_error, fail_on_invalid_params=False, **params) ret = { 'cloud_id': cloud.id, 'errors': getattr(cloud, 'errors', []), # just an attribute, not a field } log.info("Cloud with id '%s' added succesfully.", cloud.id) c_count = Cloud.objects(owner=owner, deleted=None).count() if owner.clouds_count != c_count: owner.clouds_count = c_count owner.save() cloud.polling_interval = 1800 # 30 min * 60 sec/min cloud.save() # TODO: remove below, most probably doesn't make any difference? ListMachinesPollingSchedule.add(cloud=cloud) ListLocationsPollingSchedule.add(cloud=cloud) ListSizesPollingSchedule.add(cloud=cloud) ListImagesPollingSchedule.add(cloud=cloud) return ret
def update_poller(self): """Increase polling frequency for all clouds""" log.info("Updating poller for %s", self) for cloud in Cloud.objects(owner=self.owner, deleted=None): ListMachinesPollingSchedule.add(cloud=cloud, interval=10, ttl=120)