示例#1
0
    def __init__(self, jid, password, configuration):
        """
        This is the constructor of the class.
        @type jid: string
        @param jid: the jid of the hypervisor
        @type password: string
        @param password: the password associated to the JID
        """
        TNArchipelEntity.__init__(self, jid, password, configuration,
                                  "central-agent")
        self.log.info("Starting Archipel central agent")

        self.xmppserveraddr = self.jid.getDomain()
        self.entity_type = "central-agent"
        self.default_avatar = self.configuration.get(
            "CENTRALAGENT", "central_agent_default_avatar")
        self.libvirt_event_callback_id = None
        self.vcard_infos = {}

        self.vcard_infos["TITLE"] = "Central agent"

        self.log.info("Server address defined as %s" % self.xmppserveraddr)

        # module inits
        self.initialize_modules('archipel.plugin.core')
        self.initialize_modules('archipel.plugin.centralagent')

        # action on auth
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED",
                           method=self.hook_xmpp_authenticated)

        self.central_agent_jid_val = None

        self.xmpp_authenticated = False
        self.is_central_agent = False
        self.salt = random.random()
        self.random_wait = random.random()
        self.database = sqlite3.connect(self.configuration.get(
            "CENTRALAGENT", "database"),
                                        check_same_thread=False)
        self.database.row_factory = sqlite3.Row

        # defining the structure of the keepalive pubsub event
        self.keepalive_event = xmpp.Node("event",
                                         attrs={
                                             "type": "keepalive",
                                             "jid": self.jid
                                         })
        self.last_keepalive_heard = datetime.datetime.now()
        self.last_hyp_check = datetime.datetime.now()
        self.required_stats_xml = None

        # start the permission center
        self.permission_db_file = self.configuration.get(
            "CENTRALAGENT", "centralagent_permissions_database_path")
        self.permission_center.start(database_file=self.permission_db_file)
        self.init_permissions()

        module_platformrequest = self.configuration.get(
            "MODULES", "platformrequest")

        if module_platformrequest:

            required_stats = self.get_plugin(
                "platformrequest").computing_unit.required_stats
            self.required_stats_xml = xmpp.Node("required_stats")

            for stat in required_stats:

                self.log.debug("CENTRALAGENT: stat : %s" % stat)
                self.required_stats_xml.addChild("stat", attrs=stat)

            self.keepalive_event.addChild(node=self.required_stats_xml)
示例#2
0
    def __init__(self, jid, password, configuration, name, database_file="./database.sqlite3"):
        """
        This is the constructor of the class.
        @type jid: string
        @param jid: the jid of the hypervisor
        @type password: string
        @param password: the password associated to the JID
        @type name: string
        @param name: the name of the hypervisor
        @type database_file: string
        @param database_file: the sqlite3 file to store existing VM for persistance
        """
        TNArchipelEntity.__init__(self, jid, password, configuration, name)
        self.log.info("starting archipel-agent")
        archipelLibvirtEntity.TNArchipelLibvirtEntity.__init__(self, configuration)

        self.virtualmachines            = {}
        self.database_file              = database_file
        self.xmppserveraddr             = self.jid.getDomain()
        self.entity_type                = "hypervisor"
        self.default_avatar             = self.configuration.get("HYPERVISOR", "hypervisor_default_avatar")
        self.libvirt_event_callback_id  = None
        self.vcard_infos                = {}

        # start the permission center
        self.permission_db_file = self.configuration.get("HYPERVISOR", "hypervisor_permissions_database_path")
        self.permission_center.start(database_file=self.permission_db_file)
        self.init_permissions()

        # libvirt connection
        self.connect_libvirt()

        if (self.configuration.has_section("VCARD")):
            for key in ("orgname", "orgunit", "userid", "locality", "url", "categories"):
                if self.configuration.has_option("VCARD", key):
                    self.vcard_infos[key.upper()] = self.configuration.get("VCARD", key)
        self.vcard_infos["TITLE"] = "Hypervisor (%s)" % self.current_hypervisor()

        names_file = open(self.configuration.get("HYPERVISOR", "name_generation_file"), 'r')
        self.generated_names = names_file.readlines()
        names_file.close()
        self.number_of_names = len(self.generated_names) - 1

        self.log.info("Server address defined as %s" % self.xmppserveraddr)

        # hooks
        self.create_hook("HOOK_HYPERVISOR_ALLOC")
        self.create_hook("HOOK_HYPERVISOR_SOFT_ALLOC")
        self.create_hook("HOOK_HYPERVISOR_FREE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_LEAVE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_ARRIVE")
        self.create_hook("HOOK_HYPERVISOR_CLONE")
        self.create_hook("HOOK_HYPERVISOR_VM_WOKE_UP")
        self.create_hook("HOOK_HYPERVISOR_WOKE_UP")

        # vocabulary
        self.init_vocabulary()

        # module inits
        self.initialize_modules('archipel.plugin.core')
        self.initialize_modules('archipel.plugin.hypervisor')

        if self.is_hypervisor((archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_QEMU, archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_XEN)):
            try:
                self.libvirt_event_callback_id = self.libvirt_connection.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self.hypervisor_on_domain_event, None)
            except libvirt.libvirtError:
                self.log.error("We are sorry. But your hypervisor doesn't support libvirt virConnectDomainEventRegisterAny. And this really bad. I'm sooo sorry.")
        else:
            self.log.warning("Your hypervisor doesn't support libvirt eventing. Using fake event loop.")
        self.capabilities = self.get_capabilities()

        # action on auth
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.manage_vcard_hook)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.wake_up_virtual_machines_hook, oneshot=True)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.update_presence)
    def __init__(self, jid, password, configuration, name, database_file="./database.sqlite3"):
        """
        this is the constructor of the class.
        @type jid: string
        @param jid: the jid of the hypervisor
        @type password: string
        @param password: the password associated to the JID
        @type name: string
        @param name: the name of the hypervisor
        @type database_file: string
        @param database_file: the sqlite3 file to store existing VM for persistance
        """
        TNArchipelEntity.__init__(self, jid, password, configuration, name)
        archipelLibvirtEntity.TNArchipelLibvirtEntity.__init__(self, configuration)

        self.virtualmachines = {}
        self.database_file = database_file
        self.xmppserveraddr = self.jid.getDomain()
        self.entity_type = "hypervisor"
        self.default_avatar = self.configuration.get("HYPERVISOR", "hypervisor_default_avatar")
        self.libvirt_event_callback_id = None

        # permissions
        permission_db_file = self.configuration.get("HYPERVISOR", "hypervisor_permissions_database_path")
        permission_admin_name = self.configuration.get("GLOBAL", "archipel_root_admin")
        self.permission_center = TNArchipelPermissionCenter(permission_db_file, permission_admin_name)
        self.init_permissions()

        names_file = open(self.configuration.get("HYPERVISOR", "name_generation_file"), "r")
        self.generated_names = names_file.readlines()
        names_file.close()
        self.number_of_names = len(self.generated_names) - 1

        self.log.info("server address defined as %s" % self.xmppserveraddr)

        # hooks
        self.create_hook("HOOK_HYPERVISOR_ALLOC")
        self.create_hook("HOOK_HYPERVISOR_FREE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_LEAVE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_ARRIVE")
        self.create_hook("HOOK_HYPERVISOR_CLONE")

        # vocabulary
        self.init_vocabulary()

        # module inits
        self.initialize_modules("archipel.plugin.core")
        self.initialize_modules("archipel.plugin.hypervisor")

        # # libvirt connection
        self.connect_libvirt()

        if self.is_hypervisor(
            (archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_QEMU, archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_XEN)
        ):
            try:
                self.libvirt_event_callback_id = self.libvirt_connection.domainEventRegisterAny(
                    None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self.hypervisor_on_domain_event, None
                )
            except libvirt.libvirtError:
                self.log.error(
                    "we are sorry. but your hypervisor doesn't support libvirt virConnectDomainEventRegisterAny. And this really bad. I'm sooo sorry"
                )
        else:
            self.log.warning("your hypervisor doesn't support libvirt eventing. using fake event loop.")
        self.capabilities = self.get_capabilities()

        # persistance
        self.manage_persistance()

        # action on auth
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.manage_vcard_hook)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.update_presence)
示例#4
0
    def __init__(self, jid, password, configuration):
        """
        This is the constructor of the class.
        @type jid: string
        @param jid: the jid of the hypervisor
        @type password: string
        @param password: the password associated to the JID
        """
        TNArchipelEntity.__init__(self, jid, password, configuration, "central-agent")
        self.log.info("Starting Archipel central agent")

        self.xmppserveraddr            = self.jid.getDomain()
        self.entity_type               = "central-agent"
        self.default_avatar            = self.configuration.get("CENTRALAGENT", "central_agent_default_avatar")
        self.libvirt_event_callback_id = None
        self.vcard_infos               = {}

        self.vcard_infos["TITLE"]      = "Central agent"

        self.log.info("Server address defined as %s" % self.xmppserveraddr)

        # start the permission center
        self.permission_db_file = self.configuration.get("CENTRALAGENT", "centralagent_permissions_database_path")
        self.permission_center.start(database_file=self.permission_db_file)
        self.init_permissions()

        # action on auth
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.hook_xmpp_authenticated)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.manage_vcard_hook)

        # create hooks
        self.create_hook("HOOK_CENTRALAGENT_VM_REGISTERED")
        self.create_hook("HOOK_CENTRALAGENT_VM_UNREGISTERED")
        self.create_hook("HOOK_CENTRALAGENT_HYP_REGISTERED")
        self.create_hook("HOOK_CENTRALAGENT_HYP_UNREGISTERED")


        self.central_agent_jid_val = None

        self.xmpp_authenticated   = False
        self.is_central_agent     = False
        self.salt                 = random.random()
        self.random_wait          = random.random()
        self.database             = sqlite3.connect(self.configuration.get("CENTRALAGENT", "database"), check_same_thread=False)
        self.database.row_factory = sqlite3.Row

        # defining the structure of the keepalive pubsub event
        self.keepalive_event      = xmpp.Node("event",attrs={"type":"keepalive","jid":self.jid})
        self.last_keepalive_heard = datetime.datetime.now()
        self.last_hyp_check       = datetime.datetime.now()
        self.required_stats_xml   = None

        # module inits
        self.initialize_modules('archipel.plugin.core')
        self.initialize_modules('archipel.plugin.centralagent')

        module_platformrequest    = self.configuration.get("MODULES", "platformrequest")

        if module_platformrequest:

            required_stats = self.get_plugin("platformrequest").computing_unit.required_stats
            self.required_stats_xml = xmpp.Node("required_stats")

            for stat in required_stats:

                self.log.debug("CENTRALAGENT: stat : %s" % stat)
                self.required_stats_xml.addChild("stat", attrs=stat)

            self.keepalive_event.addChild(node = self.required_stats_xml)
示例#5
0
    def __init__(self,
                 jid,
                 password,
                 configuration,
                 name,
                 database_file="./database.sqlite3"):
        """
        This is the constructor of the class.
        @type jid: string
        @param jid: the jid of the hypervisor
        @type password: string
        @param password: the password associated to the JID
        @type name: string
        @param name: the name of the hypervisor
        @type database_file: string
        @param database_file: the sqlite3 file to store existing VM for persistance
        """
        TNArchipelEntity.__init__(self, jid, password, configuration, name)
        self.log.info("starting archipel-agent")
        archipelLibvirtEntity.TNArchipelLibvirtEntity.__init__(
            self, configuration)

        self.virtualmachines = {}
        self.database_file = database_file
        self.xmppserveraddr = self.jid.getDomain()
        self.entity_type = "hypervisor"
        self.default_avatar = self.configuration.get(
            "HYPERVISOR", "hypervisor_default_avatar")
        self.libvirt_event_callback_id = None

        # start the permission center
        self.permission_db_file = self.configuration.get(
            "HYPERVISOR", "hypervisor_permissions_database_path")
        self.permission_center.start(database_file=self.permission_db_file)
        self.init_permissions()

        # libvirt connection
        self.connect_libvirt()

        self.vcard_infos = {}
        if (self.configuration.has_section("VCARD")):
            for key in ("orgname", "userid", "locality", "url"):
                if self.configuration.has_option("VCARD", key):
                    self.vcard_infos[key.upper()] = self.configuration.get(
                        "VCARD", key)
        self.vcard_infos[
            "TITLE"] = "Hypervisor (%s)" % self.current_hypervisor()

        names_file = open(
            self.configuration.get("HYPERVISOR", "name_generation_file"), 'r')
        self.generated_names = names_file.readlines()
        names_file.close()
        self.number_of_names = len(self.generated_names) - 1

        self.log.info("Server address defined as %s" % self.xmppserveraddr)

        # hooks
        self.create_hook("HOOK_HYPERVISOR_ALLOC")
        self.create_hook("HOOK_HYPERVISOR_SOFT_ALLOC")
        self.create_hook("HOOK_HYPERVISOR_FREE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_LEAVE")
        self.create_hook("HOOK_HYPERVISOR_MIGRATEDVM_ARRIVE")
        self.create_hook("HOOK_HYPERVISOR_CLONE")
        self.create_hook("HOOK_HYPERVISOR_VM_WOKE_UP")
        self.create_hook("HOOK_HYPERVISOR_WOKE_UP")

        # vocabulary
        self.init_vocabulary()

        # module inits
        self.initialize_modules('archipel.plugin.core')
        self.initialize_modules('archipel.plugin.hypervisor')

        if self.is_hypervisor(
            (archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_QEMU,
             archipelLibvirtEntity.ARCHIPEL_HYPERVISOR_TYPE_XEN)):
            try:
                self.libvirt_event_callback_id = self.libvirt_connection.domainEventRegisterAny(
                    None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                    self.hypervisor_on_domain_event, None)
            except libvirt.libvirtError:
                self.log.error(
                    "We are sorry. But your hypervisor doesn't support libvirt virConnectDomainEventRegisterAny. And this really bad. I'm sooo sorry."
                )
        else:
            self.log.warning(
                "Your hypervisor doesn't support libvirt eventing. Using fake event loop."
            )
        self.capabilities = self.get_capabilities()

        # action on auth
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED",
                           method=self.manage_vcard_hook)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED",
                           method=self.wake_up_virtual_machines_hook,
                           oneshot=True)
        self.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED",
                           method=self.update_presence)