コード例 #1
0
ファイル: entity.py プロジェクト: jloehel/xii
    def template(self, key):
        """get template
        Get a template which was added to the filesystem in the corresponding
        'templates/' directory.

        Example:
        ::

            # path: components/node/attributes/image/templates/disk.xml
            # in image attribute
            self.template("disk.xml")
            < Template('...') >

            # path: components/node/templates/qemu/simple.xml
            # in node component
            self.template("qemu/simple.xml")
            < Template('...') >

        Args:
            key: Key path to template

        Returns:
            The specified template

        Throws:
            error.Bug if template could not found
        """
        if key not in self._templates:
            raise error.Bug("Could not find template {}".format(key))

        content = util.file_read(self._templates[key])
        return string.Template(content)
コード例 #2
0
ファイル: ip.py プロジェクト: jloehel/xii
    def run(self):
        is_quiet = self.args().quiet
        domain_name = self.domain_name()

        cmpnt = self.get_component(domain_name)
        if not cmpnt:
            raise error.Bug("Could not find `{}`.".format(domain_name))
        ip = cmpnt.domain_get_ip(domain_name, quiet=is_quiet)
        print(ip)
コード例 #3
0
ファイル: entity.py プロジェクト: jloehel/xii
    def parent(self):
        """get parent

        This method should never called on a parent object.

        Returns:
            The parent objecta

        Throws:
            error.Bug is throw if a parent object trys to access it's parent
        """
        if not self.has_parent():
            raise error.Bug("{} is trying to get parent entity, but there "
                            "is none".format(self.entity()))
        return self._parent
コード例 #4
0
ファイル: entity.py プロジェクト: jloehel/xii
    def reorder_childs(self):
        idx = 0
        rounds = 0
        size = len(self._childs)

        while idx != size:
            has_moved = False
            if rounds > size * 2:
                raise error.Bug("Cyclic dependencies.")

            for requirement in self._childs[idx].requires:
                move = self.child_index(requirement)
                if move is None:
                    continue

                if move > idx:
                    self._childs.insert(idx, self._childs.pop(move))
                    has_moved = True
            if not has_moved:
                idx += 1
            rounds += 1
コード例 #5
0
ファイル: node.py プロジェクト: jloehel/xii
    def destroy(self):
        self.say("destroying...")
        domain = self.get_domain(self.entity(), raise_exception=False)

        if not domain:
            self.warn("does not exist")
            return

        if domain_has_state(domain, libvirt.VIR_DOMAIN_PAUSED):
            domain.resume()

        if domain_has_state(domain, libvirt.VIR_DOMAIN_RUNNING):
            self._stop_domain(domain, force=True)

        if domain.isActive():
            raise error.Bug("Could not remove running "
                            "domain {}".format(self.ident()))

        self.each_child("destroy", reverse=True)
        domain.undefine()
        self.success("removed!")
        self.each_child("after_destroy", reverse=True)
コード例 #6
0
ファイル: attribute.py プロジェクト: jloehel/xii
    def settings(self, key=None, default=None):
        """return validated settings

        This function will return the searched key or all settings if
        not `key` is specified.

        Args:
            key: Search key eg. "settingsdict/key1" or "foo" or None
            default: If key is not found in settings default is returned

        Returns:
            Value specified in `default` or None
        """
        if self.store().has_key(self.atype):
            s = self.store().derive(self.atype)
        elif self.has_defaults():
            s = Store(parent=self.defaults)
        else:
            raise error.Bug("Try to get default settings for {} but "
                            "no defaults are defined".format(self.entity()))
        if key is None:
            return s.values()
        return s.get(key, default)