예제 #1
0
    def list_all_ISO_storage_domains(self):
        """
        List only the ISO storage domains in sorted format.
        """
        def get_name(ary):
            return ary[0]

        dcXML = self._fetch_from_api("/datacenters")
        logging.debug("Returned XML is\n%s" % dcXML)
        dc = api.parseString(dcXML)
        dcAry = dc.get_data_center()
        if dcAry is not None:
            isoAry = []
            for dc in dcAry:
                dcName = dc.get_name()
                domainXml = self._fetch_from_api(
                    "/datacenters/%s/storagedomains" % dc.get_id())
                logging.debug("Returned XML is\n%s" % domainXml)
                sdom = api.parseString(domainXml)
                domainAry = sdom.get_storage_domain()
                if domainAry is not None:
                    for domain in domainAry:
                        if domain.get_type() == 'iso':
                            status = domain.get_status()
                            if status is not None:
                                isoAry.append([
                                    domain.get_name(), dcName,
                                    status.get_state()
                                ])
                            else:
                                logging.debug(
                                    "the storage domain didn't have a satus element."
                                )
                else:
                    logging.debug(
                        _("DC(%s) does not have a storage domain.") % dcName)

            if len(isoAry) > 0:
                isoAry.sort(key=get_name)
                fmt = "%-25s | %-25s | %s"
                print fmt % (_("ISO Storage Domain Name"), _("Datacenter"),
                             _("ISO Domain Status"))
                print "\n".join(fmt % (name, dcName, status)
                                for name, dcName, status in isoAry)
            else:
                ExitCodes.exit_code = ExitCodes.LIST_ISO_ERR
                logging.error(_("There are no ISO storage domains."))
        else:
            ExitCodes.exit_code = ExitCodes.LIST_ISO_ERR
            logging.error(
                _("There are no datacenters with ISO storage domains."))
    def get_host_and_path_from_ISO_domain(self, isodomain):
        """
        Given a valid ISO storage domain, this method will return the
        hostname/IP, UUID, and path to the domain in a 3 tuple.
        Returns:
          (host, id, path)
        """
        query = urllib.quote("name=%s" % isodomain)
        domainXml = self._fetch_from_api("/storagedomains?search=%s" % query)
        logging.debug("Returned XML is\n%s" % domainXml)
        sdom = api.parseString(domainXml)
        #sdom = api.parse('isodomain.xml')
        domainAry = sdom.get_storage_domain()
        if domainAry is not None and len(domainAry) == 1:
            if domainAry[0].get_type() != 'iso':
                raise Exception(_("The %s storage domain supplied is not of type ISO" % (isodomain)))
            address = None
            path = None
            id = domainAry[0].get_id()
            storage = domainAry[0].get_storage()
            if storage is not None:
                address = storage.get_address()
                path = storage.get_path()
            else:
                raise Exception(_("A storage element was not found for the %s ISO domain." % isodomain))

            logging.debug('id=%s address=%s path=%s' % (id, address, path))
            return (id, address, path)
        else:
            raise Exception(_("An ISO storage domain with a name of %s was not found." %
                              isodomain))
    def list_all_ISO_storage_domains(self):
        """
        List only the ISO storage domains in sorted format.
        """
        def get_name(ary):
            return ary[0]

        dcXML = self._fetch_from_api("/datacenters")
        logging.debug("Returned XML is\n%s" % dcXML)
        dc = api.parseString(dcXML)
        dcAry = dc.get_data_center()
        if dcAry is not None:
             isoAry = [ ]
             for dc in dcAry:
                 dcName = dc.get_name()
                 domainXml = self._fetch_from_api("/datacenters/%s/storagedomains" %
                                                  dc.get_id())
                 logging.debug("Returned XML is\n%s" % domainXml)
                 sdom = api.parseString(domainXml)
                 domainAry = sdom.get_storage_domain()
                 if domainAry is not None:
                     for domain in domainAry:
                         if domain.get_type() == 'iso':
                             status = domain.get_status()
                             if status is not None:
                                 isoAry.append([domain.get_name(),
                                                dcName,
                                                status.get_state()])
                             else:
                                 logging.debug("the storage domain didn't have a satus element.")
                 else:
                     logging.debug(_("DC(%s) does not have a storage domain.") % dcName)

             if len(isoAry) > 0:
                isoAry.sort(key=get_name)
                fmt = "%-25s | %-25s | %s"
                print fmt % (_("ISO Storage Domain Name"), _("Datacenter"), _("ISO Domain Status"))
                print "\n".join(fmt % (name, dcName, status)
                                for name, dcName, status in isoAry)
             else:
                ExitCodes.exit_code=ExitCodes.LIST_ISO_ERR
                logging.error(_("There are no ISO storage domains."))
        else:
            ExitCodes.exit_code=ExitCodes.LIST_ISO_ERR
            logging.error(_("There are no datacenters with ISO storage domains."))
예제 #4
0
    def get_host_and_path_from_ISO_domain(self, isodomain):
        """
        Given a valid ISO storage domain, this method will return the
        hostname/IP, UUID, and path to the domain in a 3 tuple.
        Returns:
          (host, id, path)
        """
        query = urllib.quote("name=%s" % isodomain)
        domainXml = self._fetch_from_api("/storagedomains?search=%s" % query)
        logging.debug("Returned XML is\n%s" % domainXml)
        sdom = api.parseString(domainXml)
        #sdom = api.parse('isodomain.xml')
        domainAry = sdom.get_storage_domain()
        if domainAry is not None and len(domainAry) == 1:
            if domainAry[0].get_type() != 'iso':
                raise Exception(
                    _("The %s storage domain supplied is not of type ISO" %
                      (isodomain)))
            address = None
            path = None
            id = domainAry[0].get_id()
            storage = domainAry[0].get_storage()
            if storage is not None:
                address = storage.get_address()
                path = storage.get_path()
            else:
                raise Exception(
                    _("A storage element was not found for the %s ISO domain."
                      % isodomain))

            logging.debug('id=%s address=%s path=%s' % (id, address, path))
            return (id, address, path)
        else:
            raise Exception(
                _("An ISO storage domain with a name of %s was not found." %
                  isodomain))