Пример #1
0
 def install(self, urls):
     am_installed = 0
     try:
         gclient_v1 = importer.import_module('glanceclient.v1.client')
         gexceptions = importer.import_module('glanceclient.common.exceptions')
         kclient_v2 = importer.import_module('keystoneclient.v2_0.client')
         kexceptions = importer.import_module('keystoneclient.exceptions')
     except RuntimeError as e:
         LOG.exception("Failed at importing required client modules: %s", e)
         return am_installed
     if urls:
         try:
             params = self.params['glance']
             client = gclient_v1.Client(endpoint=params['endpoints']['public']['uri'],
                                        token=self._get_token(kclient_v2))
         except (RuntimeError, gexceptions.ClientException,
                 kexceptions.ClientException) as e:
             LOG.exception('Failed fetching needed clients for image calls due to: %s', e)
             return am_installed
         utils.log_iterable(urls, logger=LOG,
                             header="Attempting to download+extract+upload %s images" % len(urls))
         for url in urls:
             try:
                 (name, img_id) = Image(client, url).install()
                 LOG.info("Installed image named %s with image id %s.", colorizer.quote(name), colorizer.quote(img_id))
                 am_installed += 1
             except (IOError,
                     tarfile.TarError,
                     gexceptions.ClientException,
                     kexceptions.ClientException) as e:
                 LOG.exception('Installing %r failed due to: %s', url, e)
     return am_installed
Пример #2
0
 def install(self, urls):
     am_installed = 0
     try:
         # Done at a function level since this module may be used
         # before these libraries actually exist...
         gclient_v1 = importer.import_module('glanceclient.v1.client')
         gexceptions = importer.import_module(
             'glanceclient.common.exceptions')
         kclient_v2 = importer.import_module('keystoneclient.v2_0.client')
         kexceptions = importer.import_module('keystoneclient.exceptions')
     except RuntimeError as e:
         LOG.exception("Failed at importing required client modules: %s", e)
         return am_installed
     if urls:
         try:
             # Ensure all services ok
             for params in [self.glance_params, self.keystone_params]:
                 utils.wait_for_url(params['endpoints']['public']['uri'])
             g_params = self.glance_params
             client = gclient_v1.Client(
                 endpoint=g_params['endpoints']['public']['uri'],
                 token=self._get_token(kclient_v2))
         except (RuntimeError, gexceptions.ClientException,
                 kexceptions.ClientException, IOError) as e:
             LOG.exception(
                 'Failed fetching needed clients for image calls due to: %s',
                 e)
             return am_installed
         utils.log_iterable(
             urls,
             logger=LOG,
             header="Attempting to download+extract+upload %s images" %
             len(urls))
         for url in urls:
             try:
                 img_handle = Image(client,
                                    url,
                                    is_public=self.is_public,
                                    cache_dir=self.cache_dir)
                 (name, img_id) = img_handle.install()
                 LOG.info("Installed image named %s with image id %s.",
                          colorizer.quote(name), colorizer.quote(img_id))
                 am_installed += 1
             except (IOError, tarfile.TarError, gexceptions.ClientException,
                     kexceptions.ClientException) as e:
                 LOG.exception('Installing %r failed due to: %s', url, e)
     return am_installed
Пример #3
0
 def install(self, urls):
     am_installed = 0
     try:
         gclient_v1 = importer.import_module('glanceclient.v1.client')
         gexceptions = importer.import_module(
             'glanceclient.common.exceptions')
         kclient_v2 = importer.import_module('keystoneclient.v2_0.client')
         kexceptions = importer.import_module('keystoneclient.exceptions')
     except RuntimeError as e:
         LOG.exception("Failed at importing required client modules: %s", e)
         return am_installed
     if urls:
         try:
             # Ensure all services ok
             for n in ['glance', 'keystone']:
                 params = self.params[n]
                 utils.wait_for_url(params['endpoints']['public']['uri'])
             params = self.params['glance']
             client = gclient_v1.Client(
                 endpoint=params['endpoints']['public']['uri'],
                 token=self._get_token(kclient_v2))
         except (RuntimeError, gexceptions.ClientException,
                 kexceptions.ClientException, IOError) as e:
             LOG.exception(
                 'Failed fetching needed clients for image calls due to: %s',
                 e)
             return am_installed
         utils.log_iterable(
             urls,
             logger=LOG,
             header="Attempting to download+extract+upload %s images" %
             len(urls))
         for url in urls:
             try:
                 img_handle = Image(client, url,
                                    self.params.get('public', True))
                 (name, img_id) = img_handle.install()
                 LOG.info("Installed image named %s with image id %s.",
                          colorizer.quote(name), colorizer.quote(img_id))
                 am_installed += 1
             except (IOError, tarfile.TarError, gexceptions.ClientException,
                     kexceptions.ClientException) as e:
                 LOG.exception('Installing %r failed due to: %s', url, e)
     return am_installed
Пример #4
0
 def install(self, urls):
     am_installed = 0
     try:
         # Done at a function level since this module may be used
         # before these libraries actually exist.
         gclient_v1 = importer.import_module('glanceclient.v1.client')
         gexceptions = importer.import_module('glanceclient.common.exceptions')
         kclient_v2 = importer.import_module('keystoneclient.v2_0.client')
         kexceptions = importer.import_module('keystoneclient.exceptions')
     except RuntimeError as e:
         LOG.exception("Failed at importing required client modules: %s", e)
         return am_installed
     if urls:
         try:
             # Ensure all services are up
             for params in (self._glance_params, self._keystone_params):
                 utils.wait_for_url(params['endpoints']['public']['uri'])
             g_params = self._glance_params
             client = gclient_v1.Client(endpoint=g_params['endpoints']['public']['uri'],
                                        token=self._get_token(kclient_v2))
         except (RuntimeError, gexceptions.ClientException,
                 kexceptions.ClientException, IOError) as e:
             LOG.exception('Failed fetching needed clients for image calls due to: %s', e)
             return am_installed
         utils.log_iterable(urls, logger=LOG,
                            header="Attempting to download+extract+upload %s images" % len(urls))
         for url in urls:
             try:
                 img_handle = Image(client, url,
                                    is_public=self._is_public,
                                    cache_dir=self._cache_dir)
                 (name, img_id) = img_handle.install()
                 LOG.info("Installed image %s with id %s.",
                          colorizer.quote(name), colorizer.quote(img_id))
                 am_installed += 1
             except exc.DuplicateException as e:
                 LOG.warning(e)
             except (IOError,
                     tarfile.TarError,
                     gexceptions.ClientException,
                     kexceptions.ClientException) as e:
                 LOG.exception('Installing %r failed due to: %s', url, e)
     return am_installed
Пример #5
0
 def clear_domains(self, virt_type, inst_prefix):
     libvirt = None
     try:
         # A late import is done since this code could be used before libvirt is actually
         # installed, and that will cause the top level python import to fail which will
         # make anvil not work, so import it dynamically to bypass the previous mechanism
         libvirt = importer.import_module('libvirt')
     except RuntimeError as e:
         pass
     if not libvirt:
         LOG.warn(
             "Could not clear out libvirt domains, libvirt not available for python."
         )
         return
     virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
     if not virt_protocol:
         LOG.warn(
             "Could not clear out libvirt domains, no known protocol for virt type: %s",
             colorizer.quote(virt_type))
         return
     with sh.Rooted(True):
         LOG.info(
             "Attempting to clear out leftover libvirt domains using protocol: %s",
             colorizer.quote(virt_protocol))
         try:
             self.restart_service()
             self.wait_active()
         except (excp.StartException, IOError) as e:
             LOG.warn("Could not restart the libvirt daemon due to: %s", e)
             return
         try:
             conn = libvirt.open(virt_protocol)
         except libvirt.libvirtError as e:
             LOG.warn(
                 "Could not connect to libvirt using protocol %s due to: %s",
                 colorizer.quote(virt_protocol), e)
             return
         with contextlib.closing(conn) as ch:
             try:
                 defined_domains = ch.listDefinedDomains()
                 kill_domains = list()
                 for domain in defined_domains:
                     if domain.startswith(inst_prefix):
                         kill_domains.append(domain)
                 if kill_domains:
                     utils.log_iterable(
                         kill_domains,
                         logger=LOG,
                         header="Found %s old domains to destroy" %
                         (len(kill_domains)))
                     for domain in sorted(kill_domains):
                         self._destroy_domain(libvirt, ch, domain)
             except libvirt.libvirtError, e:
                 LOG.warn("Could not clear out libvirt domains due to: %s",
                          e)
Пример #6
0
 def clear_domains(self, virt_type, inst_prefix):
     libvirt = None
     try:
         # A late import is done since this code could be used before libvirt is actually
         # installed, and that will cause the top level python import to fail which will
         # make anvil not work, so import it dynamically to bypass the previous mechanism
         libvirt = importer.import_module('libvirt')
     except RuntimeError as e:
         pass
     if not libvirt:
         LOG.warn("Could not clear out libvirt domains, libvirt not available for python.")
         return
     virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
     if not virt_protocol:
         LOG.warn("Could not clear out libvirt domains, no known protocol for virt type: %s", colorizer.quote(virt_type))
         return
     with sh.Rooted(True):
         LOG.info("Attempting to clear out leftover libvirt domains using protocol: %s", colorizer.quote(virt_protocol))
         try:
             self.restart_service()
             self.wait_active()
         except (excp.StartException, IOError) as e:
             LOG.warn("Could not restart the libvirt daemon due to: %s", e)
             return
         try:
             conn = libvirt.open(virt_protocol)
         except libvirt.libvirtError as e:
             LOG.warn("Could not connect to libvirt using protocol %s due to: %s", colorizer.quote(virt_protocol), e)
             return
         with contextlib.closing(conn) as ch:
             try:
                 defined_domains = ch.listDefinedDomains()
                 kill_domains = list()
                 for domain in defined_domains:
                     if domain.startswith(inst_prefix):
                         kill_domains.append(domain)
                 if kill_domains:
                     utils.log_iterable(kill_domains, logger=LOG,
                         header="Found %s old domains to destroy" % (len(kill_domains)))
                     for domain in sorted(kill_domains):
                         self._destroy_domain(libvirt, ch, domain)
             except libvirt.libvirtError, e:
                 LOG.warn("Could not clear out libvirt domains due to: %s", e)
Пример #7
0
 def clear_domains(self, virt_type, inst_prefix):
     libvirt = None
     try:
         libvirt = importer.import_module('libvirt')
     except RuntimeError as e:
         pass
     if not libvirt:
         LOG.warn("Could not clear out libvirt domains, libvirt not available for python.")
         return
     virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
     if not virt_protocol:
         LOG.warn("Could not clear out libvirt domains, no known protocol for virt type: %s", colorizer.quote(virt_type))
         return
     with sh.Rooted(True):
         LOG.info("Attempting to clear out leftover libvirt domains using protocol: %s", colorizer.quote(virt_protocol))
         try:
             self.restart_service()
         except excp.ProcessExecutionError as e:
             LOG.warn("Could not restart libvirt due to: %s" % (e))
             return
         try:
             conn = libvirt.open(virt_protocol)
         except libvirt.libvirtError as e:
             LOG.warn("Could not connect to libvirt using protocol %s due to: %s", colorizer.quote(virt_protocol), e)
             return
         with contextlib.closing(conn) as ch:
             try:
                 defined_domains = ch.listDefinedDomains()
                 kill_domains = list()
                 for domain in defined_domains:
                     if domain.startswith(inst_prefix):
                         kill_domains.append(domain)
                 if kill_domains:
                     utils.log_iterable(kill_domains, logger=LOG,
                         header="Found %s old domains to destroy" % (len(kill_domains)))
                     for domain in sorted(kill_domains):
                         self._destroy_domain(libvirt, ch, domain)
             except libvirt.libvirtError, e:
                 LOG.warn("Could not clear out libvirt domains due to: %s", e)