def update_volumes(cls, instance): """Update volumes for Node instance. Adds pending "disks" changes for Cluster which Node belongs to :param instance: Node instance :returns: None """ attrs = instance.attributes if not attrs: attrs = cls.create_attributes(instance) try: attrs.volumes = instance.volume_manager.gen_volumes_info() except Exception as exc: msg = (u"Failed to generate volumes " u"info for node '{0}': '{1}'").format( instance.name or instance.mac or instance.id, str(exc) or "see logs for details") logger.warning(traceback.format_exc()) Notification.create({ "topic": "error", "message": msg, "node_id": instance.id }) if instance.cluster_id: Cluster.add_pending_changes(instance.cluster, "disks", node_id=instance.id) db().add(attrs) db().flush()
def update_volumes(cls, instance): attrs = instance.attributes if not attrs: attrs = cls.create_attributes(instance) try: attrs.volumes = instance.volume_manager.gen_volumes_info() except Exception as exc: msg = ( u"Failed to generate volumes " u"info for node '{0}': '{1}'" ).format( instance.name or instance.mac or instance.id, str(exc) or "see logs for details" ) logger.warning(traceback.format_exc()) Notification.create({ "topic": "error", "message": msg, "node_id": instance.id }) if instance.cluster_id: Cluster.add_pending_changes( instance.cluster, "disks", node_id=instance.id ) db().add(attrs) db().flush()
def set_error_status_and_file_notification(cls, instance, etype, emessage): instance.status = consts.NODE_STATUSES.error instance.error_type = etype instance.error_msg = emessage db().flush() Notification.create( {"topic": consts.NOTIFICATION_TOPICS.error, "message": instance.error_msg, "node_id": instance.id} )
def set_error_status_and_file_notification(cls, instance, etype, emessage): instance.status = consts.NODE_STATUSES.error instance.error_type = etype instance.error_msg = emessage db().flush() Notification.create({ "topic": consts.NOTIFICATION_TOPICS.error, "message": instance.error_msg, "node_id": instance.id })
def set_default_node_volumes(cls, node): from .objects.volumes import VolumeObject try: VolumeObject.set_default_node_volumes(node) except Exception as exc: logger.exception(exc) msg = "Failed to generate volumes for node '{0}': '{1}'".format( node.human_readable_name, six.text_type(exc) ) Notification.create({"topic": "error", "message": msg, "node_id": node.id}) if node.cluster_id: Node.add_pending_change(node, "disks")
def set_default_node_volumes(cls, node): from .objects.volumes import VolumeObject try: VolumeObject.set_default_node_volumes(node) except Exception as exc: logger.exception(exc) msg = "Failed to generate volumes for node '{0}': '{1}'".format( node.human_readable_name, six.text_type(exc)) Notification.create({ 'topic': 'error', 'message': msg, 'node_id': node.id}) if node.cluster_id: Node.add_pending_change(node, 'disks')
def update_volumes(cls, instance): """Update volumes for Node instance. Adds pending "disks" changes for Cluster which Node belongs to :param instance: Node instance :returns: None """ attrs = instance.attributes if not attrs: attrs = cls.create_attributes(instance) try: # TODO(eli): update volumes method should be moved # into an extension # Should be done as a part of blueprint: # https://blueprints.launchpad.net/fuel/+spec # /volume-manager-refactoring from nailgun.extensions.volume_manager.extension \ import VolumeManagerExtension VolumeManagerExtension.set_volumes( instance, instance.volume_manager.gen_volumes_info()) except Exception as exc: msg = ( u"Failed to generate volumes " u"info for node '{0}': '{1}'" ).format( instance.name or instance.mac or instance.id, str(exc) or "see logs for details" ) logger.warning(traceback.format_exc()) Notification.create({ "topic": "error", "message": msg, "node_id": instance.id }) if instance.cluster_id: Cluster.add_pending_changes( instance.cluster, "disks", node_id=instance.id ) db().add(attrs) db().flush()
def create_discover_notification(cls, instance): """Create notification about discovering new Node :param instance: Node instance :returns: None """ try: # we use multiplier of 1024 because there are no problems here # with unfair size calculation ram = str(round(float( instance.meta['memory']['total']) / 1073741824, 1)) + " GB RAM" except Exception: logger.warning(traceback.format_exc()) ram = "unknown RAM" try: # we use multiplier of 1000 because disk vendors specify HDD size # in terms of decimal capacity. Sources: # http://knowledge.seagate.com/articles/en_US/FAQ/172191en # http://physics.nist.gov/cuu/Units/binary.html hd_size = round( float( sum( [d["size"] for d in instance.meta["disks"]] ) / 1000000000 ), 1 ) # if HDD > 100 GB we show it's size in TB if hd_size > 100: hd_size = str(hd_size / 1000) + " TB HDD" else: hd_size = str(hd_size) + " GB HDD" except Exception: logger.warning(traceback.format_exc()) hd_size = "unknown HDD" cores = str(instance.meta.get('cpu', {}).get('total', "unknown")) Notification.create({ "topic": "discover", "message": u"New node is discovered: " u"{0} CPUs / {1} / {2} ".format(cores, ram, hd_size), "node_id": instance.id })
def create_discover_notification(cls, instance): """Create notification about discovering new Node :param instance: Node instance :returns: None """ try: # we use multiplier of 1024 because there are no problems here # with unfair size calculation ram = str( round(float(instance.meta['memory']['total']) / 1073741824, 1)) + " GB RAM" except Exception: logger.warning(traceback.format_exc()) ram = "unknown RAM" try: # we use multiplier of 1000 because disk vendors specify HDD size # in terms of decimal capacity. Sources: # http://knowledge.seagate.com/articles/en_US/FAQ/172191en # http://physics.nist.gov/cuu/Units/binary.html hd_size = round( float( sum([d["size"] for d in instance.meta["disks"]]) / 1000000000), 1) # if HDD > 100 GB we show it's size in TB if hd_size > 100: hd_size = str(hd_size / 1000) + " TB HDD" else: hd_size = str(hd_size) + " GB HDD" except Exception: logger.warning(traceback.format_exc()) hd_size = "unknown HDD" cores = str(instance.meta.get('cpu', {}).get('total', "unknown")) Notification.create({ "topic": "discover", "message": u"发现一个新的节点: " u"{0} CPUs / {1} / {2} ".format(cores, ram, hd_size), "node_id": instance.id })
def update_volumes(cls, instance): """Update volumes for Node instance. Adds pending "disks" changes for Cluster which Node belongs to :param instance: Node instance :returns: None """ attrs = instance.attributes if not attrs: attrs = cls.create_attributes(instance) try: # TODO(eli): update volumes method should be moved # into an extension # Should be done as a part of blueprint: # https://blueprints.launchpad.net/fuel/+spec # /volume-manager-refactoring from nailgun.extensions.volume_manager.extension \ import VolumeManagerExtension VolumeManagerExtension.set_volumes( instance, instance.volume_manager.gen_volumes_info()) except Exception as exc: msg = (u"Failed to generate volumes " u"info for node '{0}': '{1}'").format( instance.name or instance.mac or instance.id, str(exc) or "see logs for details") logger.warning(traceback.format_exc()) Notification.create({ "topic": "error", "message": msg, "node_id": instance.id }) if instance.cluster_id: Cluster.add_pending_changes(instance.cluster, "disks", node_id=instance.id) db().add(attrs) db().flush()