Ejemplo n.º 1
0
 def add_disk_to_vm(self):
     """Add a disk with specs from cfme_data.template_upload
         Generally for database disk
     """
     temp_vm = self.mgmt.get_vm(self.temp_vm_name)
     if temp_vm.get_disks_count() > 1:
         logger.warn(
             '%s Warning: found more than one disk in existing VM (%s).',
             self.provider_key, self.temp_vm_name)
         return
     rhevm_specs = cfme_data.template_upload.template_upload_rhevm
     disk_kwargs = dict(
         storage_domain=self.provider_data.template_upload.sdomain,
         size=rhevm_specs.disk_size,
         interface=rhevm_specs.disk_interface,
         format=rhevm_specs.disk_format)
     temp_vm.add_disk(**disk_kwargs)
     # check, if there are two disks
     if temp_vm.get_disks_count() < 2:
         raise TemplateUploadException(
             '%s disk failed to add with specs: %r', self.provider_key,
             disk_kwargs)
     logger.info('%s:%s Successfully added disk', self.provider_key,
                 self.temp_vm_name)
     return True
Ejemplo n.º 2
0
def get_image_url(stream, upload_url):
    if stream in ALL_STREAMS:
        image_url = ALL_STREAMS[stream]
    elif upload_url:
        image_url = upload_url
    else:
        logger.error('Cannot find image URL for stream: {}'.format(stream))
        raise TemplateUploadException("Cannot find image URL.")
    return image_url
Ejemplo n.º 3
0
 def deploy_vm_from_template(self):
     """Deploy a VM from the raw template with resource limits set from yaml"""
     stream_hardware = cfme_data.template_upload.hardware[self.stream]
     self.mgmt.get_template(self.temp_template_name).deploy(
         vm_name=self.temp_vm_name,
         cluster=self.provider_data.template_upload.cluster,
         cpu=stream_hardware.cores,
         sockets=stream_hardware.sockets,
         ram=int(stream_hardware.memory) * 2**30)  # GB -> B
     # check, if the vm is really there
     if not self.mgmt.does_vm_exist(self.temp_vm_name):
         raise TemplateUploadException(
             'Failed to deploy VM from imported template')
     return True
Ejemplo n.º 4
0
 def templatize_vm(self):
     """Templatizes temporary VM. Result is template with two disks.
     """
     self.mgmt.get_vm(self.temp_vm_name).mark_as_template(
         template_name=self.template_name,
         cluster=self.provider_data.template_upload.cluster,
         delete=False)  # leave vm in place in case it fails, for debug
     # check, if template is really there
     if not self.mgmt.does_template_exist(self.template_name):
         raise TemplateUploadException('%s templatizing %s to %s FAILED',
                                       self.provider_key, self.temp_vm_name,
                                       self.template_name)
     logger.info(":%s successfully templatized %s to %s", self.provider_key,
                 self.temp_vm_name, self.template_name)
     return True
Ejemplo n.º 5
0
def get_stream_from_image_url(image_url, quiet=False):
    """Get default image URL for a given stream name"""
    # strip trailing / from URL, and strip build number or link (5.11.0.1, latest, stable)
    # to get just https://url/builds/[cfme/manageiq]/[build-stream]
    image_base = '/'.join(image_url.strip('/').split('/')[:-1])
    if not quiet:  # don't log (goes to stdout) when just printing name, for Jenkins
        logger.info('Matching stream name based on image_url base: %s', image_base)
    # look for image_base URL component in basic_info dict
    matching_streams = [key for key, value in ALL_STREAMS.items() if image_base in value]
    if matching_streams:
        # sometimes multiple match, use first
        if len(matching_streams) > 1:
            logger.warning('warning: Multiple stream name matches: %s for URL %s, using first',
                           matching_streams, image_url)
        return matching_streams[0]
    else:
        logger.error('Cannot find stream in image url: %s', image_url)
        raise TemplateUploadException("Cannot find stream from image URL.")