コード例 #1
0
    def __deploy_async(self, name, values):
        values = dbus_to_python(values)
        name = dbus_to_python(name)
        log.debug1("role.%s.deploy('%s', %s)", self._escaped_name, name,
                   values)

        # limit role instances to max instances per role
        if len(self._instances) >= self._role._MAX_INSTANCES:
            raise RolekitError(TOO_MANY_INSTANCES, "> %d" % \
                               self._role._MAX_INSTANCES)

        # TODO: lock

        # create name if empty
        if not name:
            id = 1
            while str(id) in self._instances:
                id += 1
            name = str(id)

        # create escaped name and check if it is already in use
        instance_escaped_name = dbus_label_escape(name)
        if instance_escaped_name in self._instances:
            raise RolekitError(NAME_CONFLICT, instance_escaped_name)

        settings = RoleSettings(self._name, name)
        try:
            settings.read()
        except ValueError as e:
            raise RolekitError(NAME_CONFLICT, settings.filename)
        except IOError as e:
            pass
        else:
            raise RolekitError(NAME_CONFLICT, settings.filename)

        # create role
        role = self._role(
            self,
            name,
            self._name,
            self._directory,
            settings,
            self._path,
            "%s/%s/%s" %
            (DBUS_PATH_ROLES, self._escaped_name, instance_escaped_name),
            persistent=self.persistent)
        self._instances[instance_escaped_name] = role
        self.InstanceAdded(instance_escaped_name)

        # TODO: unlock

        # deploy role, lock in role now
        result = yield async .call_future(role.deploy_async(values))
        yield result
コード例 #2
0
ファイル: dbusrole.py プロジェクト: hguemar/rolekit
    def __deploy_async(self, name, values):
        values = dbus_to_python(values)
        name = dbus_to_python(name)
        log.debug1("role.%s.deploy('%s', %s)", self._escaped_name, name, values)

        # limit role instances to max instances per role
        if len(self._instances) >= self._role._MAX_INSTANCES:
            raise RolekitError(TOO_MANY_INSTANCES, "> %d" % self._role._MAX_INSTANCES)

        # TODO: lock

        # create name if empty
        if not name:
            id = 1
            while str(id) in self._instances:
                id += 1
            name = str(id)

        # create escaped name and check if it is already in use
        instance_escaped_name = dbus_label_escape(name)
        if instance_escaped_name in self._instances:
            raise RolekitError(NAME_CONFLICT, instance_escaped_name)

        settings = RoleSettings(self._name, name)
        try:
            settings.read()
        except ValueError as e:
            raise RolekitError(NAME_CONFLICT, settings.filename)
        except IOError as e:
            pass
        else:
            raise RolekitError(NAME_CONFLICT, settings.filename)

        # create role
        role = self._role(
            self,
            name,
            self._name,
            self._directory,
            settings,
            self._path,
            "%s/%s/%s" % (DBUS_PATH_ROLES, self._escaped_name, instance_escaped_name),
            persistent=self.persistent,
        )
        self._instances[instance_escaped_name] = role
        self.InstanceAdded(instance_escaped_name)

        # TODO: unlock

        # deploy role, lock in role now
        result = yield async.call_future(role.deploy_async(values))
        yield result
コード例 #3
0
    def __init__(self, role, name, directory, *args, **kwargs):
        """The DBUS_INTERFACE_ROLE implementation

        :param role: RoleBase descendant
        :param name: Role name
        :param directory: FIXME: unused???
        :param path: (Implicit in *args) FIXME: unused???
        """
        super(DBusRole, self).__init__(*args, **kwargs)
        self._path = args[0]
        self._role = role
        self._name = name
        self._escaped_name = dbus_label_escape(name)
        self._directory = directory
        self._instances = {}

        # create instances for stored instance settings

        path = "%s/%s" % (ETC_ROLEKIT_ROLES, self._name)
        if os.path.exists(path) and os.path.isdir(path):
            for name in sorted(os.listdir(path)):
                if not name.endswith(".json"):
                    continue
                instance = name[:-5]
                log.debug1("Loading '%s' instance '%s'", self._name, instance)

                settings = RoleSettings(self._name, instance)
                try:
                    settings.read()
                except ValueError as e:
                    log.error("Failed to load '%s' instance '%s': %s",
                              self._name, instance, e)
                    continue

                instance_escaped_name = dbus_label_escape(instance)
                if instance_escaped_name in self._instances:
                    raise RolekitError(NAME_CONFLICT, instance_escaped_name)

                role = self._role(self,
                                  instance,
                                  self._name,
                                  self._directory,
                                  settings,
                                  self._path,
                                  "%s/%s/%s" %
                                  (DBUS_PATH_ROLES, self._escaped_name,
                                   instance_escaped_name),
                                  persistent=self.persistent)
                self._instances[instance_escaped_name] = role

        self.timeout_restart()
コード例 #4
0
ファイル: dbusrole.py プロジェクト: hguemar/rolekit
    def __init__(self, role, name, directory, *args, **kwargs):
        """The DBUS_INTERFACE_ROLE implementation

        :param role: RoleBase descendant
        :param name: Role name
        :param directory: FIXME: unused???
        :param path: (Implicit in *args) FIXME: unused???
        """
        super(DBusRole, self).__init__(*args, **kwargs)
        self._path = args[0]
        self._role = role
        self._name = name
        self._escaped_name = dbus_label_escape(name)
        self._directory = directory
        self._instances = {}

        # create instances for stored instance settings

        path = "%s/%s" % (ETC_ROLEKIT_ROLES, self._name)
        if os.path.exists(path) and os.path.isdir(path):
            for name in sorted(os.listdir(path)):
                if not name.endswith(".json"):
                    continue
                instance = name[:-5]
                log.debug1("Loading '%s' instance '%s'", self._name, instance)

                settings = RoleSettings(self._name, instance)
                try:
                    settings.read()
                except ValueError as e:
                    log.error("Failed to load '%s' instance '%s': %s", self._name, instance, e)
                    continue

                instance_escaped_name = dbus_label_escape(instance)
                if instance_escaped_name in self._instances:
                    raise RolekitError(NAME_CONFLICT, instance_escaped_name)

                role = self._role(
                    self,
                    instance,
                    self._name,
                    self._directory,
                    settings,
                    self._path,
                    "%s/%s/%s" % (DBUS_PATH_ROLES, self._escaped_name, instance_escaped_name),
                    persistent=self.persistent,
                )
                self._instances[instance_escaped_name] = role

        self.timeout_restart()
コード例 #5
0
ファイル: dbusrole.py プロジェクト: immanetize/rolekit
    def __deploy_async(self, name, values):
        values = dbus_to_python(values)
        name = dbus_to_python(name)
        log.debug1("%s.deploy('%s', %s)", self._log_prefix, name, values)

        # limit role instances to max instances per role
        if len(self._instances) >= self._role._MAX_INSTANCES:
            raise RolekitError(TOO_MANY_INSTANCES, "> %d" % \
                               self._role._MAX_INSTANCES)

        # TODO: lock

        # Create the settings object. If no name has been passed in,
        # this function will create one from the next available value.
        # Note: this isn't protected by a lock, so name-generation
        # might be racy.
        settings = RoleSettings(self.get_name(), name)

        # create escaped name and check if it is already in use
        instance_escaped_name = dbus_label_escape(settings.get_name())
        if instance_escaped_name in self._instances:
            raise RolekitError(NAME_CONFLICT, instance_escaped_name)

        try:
            settings.read()
        except ValueError:
            raise RolekitError(NAME_CONFLICT, settings.filename)
        except IOError:
            pass
        else:
            raise RolekitError(NAME_CONFLICT, settings.filename)

        # create role
        role = self._role(self, settings.get_name(), self.get_name(),
                          self._directory, settings, self.busname,
                          "%s/%s/%s" % (DBUS_PATH_ROLES, self._escaped_name,
                                        instance_escaped_name),
                          persistent=self.persistent)
        self._instances[instance_escaped_name] = role
        self.InstanceAdded(instance_escaped_name)

        # TODO: unlock

        # deploy role, lock in role now
        result = yield async.call_future(role.deploy_async(values))
        yield result
コード例 #6
0
    def __deploy_async(self, name, values):
        values = dbus_to_python(values)
        name = dbus_to_python(name)
        log.debug1("%s.deploy('%s', %s)", self._log_prefix, name, values)

        # limit role instances to max instances per role
        if len(self._instances) >= self._role._MAX_INSTANCES:
            raise RolekitError(TOO_MANY_INSTANCES, "> %d" % \
                               self._role._MAX_INSTANCES)

        # TODO: lock

        # Create the settings object. If no name has been passed in,
        # this function will create one from the next available value.
        # Note: this isn't protected by a lock, so name-generation
        # might be racy.
        settings = RoleSettings(self.get_name(), name)

        # create escaped name and check if it is already in use
        instance_escaped_name = dbus_label_escape(settings.get_name())
        if instance_escaped_name in self._instances:
            raise RolekitError(NAME_CONFLICT, instance_escaped_name)

        try:
            settings.read()
        except ValueError:
            raise RolekitError(NAME_CONFLICT, settings.filename)
        except IOError:
            pass
        else:
            raise RolekitError(NAME_CONFLICT, settings.filename)

        # create role
        role = self._role(
            self,
            settings.get_name(),
            self.get_name(),
            self._directory,
            settings,
            self.busname,
            "%s/%s/%s" %
            (DBUS_PATH_ROLES, self._escaped_name, instance_escaped_name),
            persistent=self.persistent)
        self._instances[instance_escaped_name] = role
        self.InstanceAdded(instance_escaped_name)

        # TODO: unlock

        # deploy role, lock in role now
        result = yield async .call_future(role.deploy_async(values))
        yield result
コード例 #7
0
ファイル: dbusrole.py プロジェクト: immanetize/rolekit
    def __init__(self, role, name, directory, *args, **kwargs):
        """The DBUS_INTERFACE_ROLE implementation

        :param role: RoleBase descendant
        :param name: Role name
        :param directory: FIXME: unused???
        :param path: (Implicit in *args) FIXME: unused???
        """
        super(DBusRole, self).__init__(*args, **kwargs)
        self.busname = args[0]
        self.path = args[1]
        self._role = role
        self._name = name
        self._escaped_name = dbus_label_escape(name)
        self._log_prefix = "role.%s" % self._escaped_name
        self._directory = directory
        self._instances = { }

        # create instances for stored instance settings

        path = "%s/%s" % (ETC_ROLEKIT_ROLES, self.get_name())
        if os.path.exists(path) and os.path.isdir(path):
            for name in sorted(os.listdir(path)):
                if not name.endswith(".json"):
                    continue
                instance = name[:-5]
                log.debug1("Loading '%s' instance '%s'", self.get_name(),
                           instance)

                settings = RoleSettings(self.get_name(), instance)
                try:
                    settings.read()
                except ValueError as e:
                    log.error("Failed to load '%s' instance '%s': %s",
                              self.get_name(), instance, e)
                    continue

                instance_escaped_name = dbus_label_escape(instance)
                if instance_escaped_name in self._instances:
                    raise RolekitError(NAME_CONFLICT, instance_escaped_name)

                role = self._role(self, instance, self.get_name(),
                                  self._directory, settings, self.busname,
                                  "%s/%s/%s" % (DBUS_PATH_ROLES,
                                                self._escaped_name,
                                                instance_escaped_name),
                                  persistent=self.persistent)

                # During roled startup (the only time this function should be
                # called), if any role is in a transitional state, it can only
                # mean that roled was terminated while it was still supposed
                # to be doing something.
                # Always set the state to ERROR here if it's in a transitional state,
                # otherwise we won't be able to clean it up.
                if role._settings["state"] in TRANSITIONAL_STATES:
                    role.change_state(state=ERROR,
                                      write=True,
                                      error="roled terminated unexpectedly")

                self._instances[instance_escaped_name] = role

        self.timeout_restart()
コード例 #8
0
    def __init__(self, role, name, directory, *args, **kwargs):
        """The DBUS_INTERFACE_ROLE implementation

        :param role: RoleBase descendant
        :param name: Role name
        :param directory: FIXME: unused???
        :param path: (Implicit in *args) FIXME: unused???
        """
        super(DBusRole, self).__init__(*args, **kwargs)
        self.busname = args[0]
        self.path = args[1]
        self._role = role
        self._name = name
        self._escaped_name = dbus_label_escape(name)
        self._log_prefix = "role.%s" % self._escaped_name
        self._directory = directory
        self._instances = {}

        # create instances for stored instance settings

        path = "%s/%s" % (ETC_ROLEKIT_ROLES, self.get_name())
        if os.path.exists(path) and os.path.isdir(path):
            for name in sorted(os.listdir(path)):
                if not name.endswith(".json"):
                    continue
                instance = name[:-5]
                log.debug1("Loading '%s' instance '%s'", self.get_name(),
                           instance)

                settings = RoleSettings(self.get_name(), instance)
                try:
                    settings.read()
                except ValueError as e:
                    log.error("Failed to load '%s' instance '%s': %s",
                              self.get_name(), instance, e)
                    continue

                instance_escaped_name = dbus_label_escape(instance)
                if instance_escaped_name in self._instances:
                    raise RolekitError(NAME_CONFLICT, instance_escaped_name)

                role = self._role(self,
                                  instance,
                                  self.get_name(),
                                  self._directory,
                                  settings,
                                  self.busname,
                                  "%s/%s/%s" %
                                  (DBUS_PATH_ROLES, self._escaped_name,
                                   instance_escaped_name),
                                  persistent=self.persistent)

                # During roled startup (the only time this function should be
                # called), if any role is in a transitional state, it can only
                # mean that roled was terminated while it was still supposed
                # to be doing something.
                # Always set the state to ERROR here if it's in a transitional state,
                # otherwise we won't be able to clean it up.
                if role._settings["state"] in TRANSITIONAL_STATES:
                    role.change_state(state=ERROR,
                                      write=True,
                                      error="roled terminated unexpectedly")

                self._instances[instance_escaped_name] = role

        self.timeout_restart()