Ejemplo n.º 1
0
def deploy(params, extraParams="", cache_only=None):
    """start and connect a local image with SUSE Manager"""

    urlParts = params["downloadURL"].split('/')
    studioArchiveFileName = urlParts[-1]
    checksum = urlParts[-2]

    # studioArchiveFileName = workshop_test_sles11sp1.i686-0.0.1.vmx.tar.gz
    # studioArchiveFileName = Just_enough_OS_openSUSE_12.1.x86_64-0.0.1.xen.tar.gz
    m = re.search('(.*)\.(x86_64|i\d86)-(\d+\.\d+\.\d+)\.(xen|vmx|qcow2)',
                  studioArchiveFileName)

    imageName = m.group(1)
    imageArch = m.group(2)
    imageVersion = m.group(3)
    imageType = m.group(4)
    studioImageDiskFileName = imageName + "." + imageArch + "-" + imageVersion

    try:
        connection = _connect_to_hypervisor()
    except Exception:
        e = sys.exc_info()[1]
        return (1, "%s" % e, {})

    # if we got an explicit name, we'll use it
    if "domainName" in params and params["domainName"] != "":
        imageName = params["domainName"]
    # if not, we'll try to find a free name
    elif (_domainExists(imageName, connection)):
        for i in itertools.count(1):
            newImageName = ("%s-%i" % (imageName, i))
            if not _domainExists(newImageName, connection):
                log.log_debug("free domain found")
                imageName = newImageName
                break
    log.log_debug("name=%s arch=%s ver=%s type=%s" %
                  (imageName, imageArch, imageVersion, imageType))

    if len(imageName) < 1 or len(imageArch) < 1:
        log.log_debug("invalid image name or arch")
        return (1,
                "invalid image name or arch: name=%s arch=%s ver=%s type=%s" %
                (imageName, imageArch, imageVersion, imageType), {})

    httpResponseCode = -1
    if not _fileExists("%s/%s" %
                       (IMAGE_BASE_PATH, studioArchiveFileName), checksum):
        try:
            httpResponseCode = _downloadFile(studioArchiveFileName,
                                             params["downloadURL"],
                                             params["proxySettings"])
            if not _fileExists(
                    "%s/%s" %
                (IMAGE_BASE_PATH, studioArchiveFileName), checksum):
                log.log_debug(
                    "downloading image file failed. HTTP Code is: %s" %
                    httpResponseCode)
                return (
                    1, "downloading image file failed: %s/%s (%s)" %
                    (IMAGE_BASE_PATH, studioArchiveFileName, httpResponseCode),
                    {})
        except Exception:
            e = sys.exc_info()[1]
            return (1, "getting the image failed with: %s" % e)
    if cache_only:
        return (0, "image fetched and cached for later deployment", {})
    try:
        targetDir = _createTargetDir("%s/%s" % (IMAGE_BASE_PATH, imageName))
        _extractImage("%s/%s" % (IMAGE_BASE_PATH, studioArchiveFileName),
                      targetDir, imageType)
    except Exception:
        e = sys.exc_info()[1]
        return (1, "extracting the image tarball failed with: %s" % e, {})

    # image exists in $IMAGE_BASE_PATH/$imageName now

    uuid = generate_uuid()
    # FIXME: check for the extensions. There might be more
    studioFileExtension = "vmdk"
    if imageType == "xen":
        studioFileExtension = "raw"
    elif imageType == "qcow2":
        studioFileExtension = "qcow2"
    extractedImagePath = "%s/%s.%s" % (targetDir, studioImageDiskFileName,
                                       studioFileExtension)
    log.log_debug("working on image in %s" % extractedImagePath)
    if not os.path.exists(extractedImagePath):
        return (1, "extracted image not found at %s" % extractedImagePath, {})
    if imageArch in ('i386', 'i486', 'i568'):
        imageArch = 'i686'

    create_params = {
        'name': imageName,
        'arch': imageArch,
        'extra': extraParams,
        'mem_kb': params["memKB"],
        'vcpus': params["vCPUs"],
        'uuid': uuid,
        'disk': extractedImagePath,
        'imageType': imageType,
        'virtBridge': params["virtBridge"],
    }
    create_xml = _generateXML(create_params)
    domain = None
    try:
        domain = connection.defineXML(create_xml)
    except Exception:
        e = sys.exc_info()[1]
        return (1, "failed to pass XML to libvirt: %s" % e, {})

    domain.create()
    virt_support.refresh()

    return (0, "image '%s' deployed and started" % imageName, {})
Ejemplo n.º 2
0
def deploy(params, extra_params="", cache_only=None):
    """Download and start a new image."""

    image_filename  = params["downloadURL"].split('/')[-1]
    domain_name, image_extension = os.path.splitext(image_filename)
    if not image_extension or image_extension != ".qcow2":
        return (1, "image type is not qcow2: %s" % image_filename, {})
    image_arch = platform.machine() or 'x86_64'

    try:
        connection = _connect_to_hypervisor()
    except Exception as e:
        return (1, "%s" % e, {})

    # If we got an explicit domain name then use it and update the filename
    if "domainName" in params and params["domainName"] != "":
        domain_name = params["domainName"]
    image_filename = domain_name + image_extension

    # If domain or file exists try to find a free name for both
    if _domain_exists(domain_name, connection) or _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
        for i in itertools.count(1):
            new_domain_name = ("%s-%i" % (domain_name, i))
            image_filename = new_domain_name + image_extension
            if not _domain_exists(new_domain_name, connection) and not _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
                log.log_debug("free domain and matching filename found")
                domain_name = new_domain_name
                break

    log.log_debug("filename=%s domain=%s arch=%s" % (image_filename, domain_name, image_arch))

    if not domain_name or image_arch not in ['x86_64', 'i686', 'ppc64le', 's390x']:
        log.log_debug("invalid domain name or arch")
        return (1, "invalid domain name or arch: domain=%s arch=%s" % (domain_name, image_arch), {})

    http_response_code = -1
    try:
        http_response_code = _download_file(image_filename, params["downloadURL"], params["proxySettings"])
        if not _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
            log.log_debug("downloading image file failed, HTTP return code: %s" % http_response_code)
            return (1, "downloading image file failed: %s/%s (%s)" % (IMAGE_BASE_PATH, image_filename, http_response_code), {})
    except Exception as e:
        return (1, "getting the image failed with: %s" % e, {})
    if cache_only:
        return (0, "image fetched and cached for later deployment", {})

    image_path = "%s/%s" % (IMAGE_BASE_PATH, image_filename)
    if not os.path.exists(image_path):
        return (1, "image not found at %s" % image_path, {})
    log.log_debug("working on image in %s" % image_path)

    create_params = { 'name'           : domain_name,
                      'arch'           : image_arch,
                      'extra'          : extra_params,
                      'mem_kb'         : params["memKB"],
                      'vcpus'          : params["vCPUs"],
                      'uuid'           : generate_uuid(),
                      'disk'           : image_path,
                      'imageType'      : 'qcow2',
                      'virtBridge'     : params["virtBridge"],
                    }
    create_xml = _generate_xml(create_params)
    domain = None
    try:
        domain = connection.defineXML(create_xml)
    except Exception as e:
        return (1, "failed to pass XML to libvirt: %s" % e, {})

    domain.create()
    virt_support.refresh()

    return (0, "image '%s' deployed and started" % domain_name, {})
Ejemplo n.º 3
0
            if not _fileExists("%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), checksum):
                log.log_debug("downloading image file failed. HTTP Code is: %s" % httpResponseCode)
                return (1, "downloading image file failed: %s/%s (%s)" % (IMAGE_BASE_PATH, studioArchiveFileName,httpResponseCode), {})
        except Exception, e:
            return ( 1, "getting the image failed with: %s" % e )
    if cache_only:
        return (0, "image fetched and cached for later deployment", {})
    try:
        targetDir = _createTargetDir( "%s/%s" % (IMAGE_BASE_PATH, imageName) )
        _extractImage( "%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), targetDir, imageType )
    except Exception, e:
        return (1, "extracting the image tarball failed with: %s" % e, {})

    # image exists in $IMAGE_BASE_PATH/$imageName now

    uuid = generate_uuid()
    # FIXME: check for the extensions. There might be more
    studioFileExtension = "vmdk"
    if imageType == "xen":
        studioFileExtension = "raw"
    elif imageType == "qcow2":
        studioFileExtension = "qcow2"
    extractedImagePath = "%s/%s.%s" % (targetDir,studioImageDiskFileName,studioFileExtension)
    log.log_debug("working on image in %s" % extractedImagePath)
    if not os.path.exists( extractedImagePath ):
        return (1, "extracted image not found at %s" % extractedImagePath, {})
    if imageArch in ( 'i386', 'i486', 'i568' ):
        imageArch = 'i686'

    create_params = { 'name'           : imageName,
                      'arch'           : imageArch,
Ejemplo n.º 4
0
Archivo: image.py Proyecto: m47ik/uyuni
def deploy(params, extra_params="", cache_only=None):
    """Download and start a new image."""

    image_filename  = params["downloadURL"].split('/')[-1]
    domain_name, image_extension = os.path.splitext(image_filename)
    if not image_extension or image_extension != ".qcow2":
        return (1, "image type is not qcow2: %s" % image_filename, {})
    image_arch = platform.machine() or 'x86_64'

    try:
        connection = _connect_to_hypervisor()
    except Exception as e:
        return (1, "%s" % e, {})

    # If we got an explicit domain name then use it and update the filename
    if "domainName" in params and params["domainName"] != "":
        domain_name = params["domainName"]
    image_filename = domain_name + image_extension

    # If domain or file exists try to find a free name for both
    if _domain_exists(domain_name, connection) or _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
        for i in itertools.count(1):
            new_domain_name = ("%s-%i" % (domain_name, i))
            image_filename = new_domain_name + image_extension
            if not _domain_exists(new_domain_name, connection) and not _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
                log.log_debug("free domain and matching filename found")
                domain_name = new_domain_name
                break

    log.log_debug("filename=%s domain=%s arch=%s" % (image_filename, domain_name, image_arch))

    if not domain_name or image_arch not in ['x86_64', 'i686', 'ppc64le', 's390x']:
        log.log_debug("invalid domain name or arch")
        return (1, "invalid domain name or arch: domain=%s arch=%s" % (domain_name, image_arch), {})

    http_response_code = -1
    try:
        http_response_code = _download_file(image_filename, params["downloadURL"], params["proxySettings"])
        if not _file_exists("%s/%s" % (IMAGE_BASE_PATH, image_filename)):
            log.log_debug("downloading image file failed, HTTP return code: %s" % http_response_code)
            return (1, "downloading image file failed: %s/%s (%s)" % (IMAGE_BASE_PATH, image_filename, http_response_code), {})
    except Exception as e:
        return (1, "getting the image failed with: %s" % e, {})
    if cache_only:
        return (0, "image fetched and cached for later deployment", {})

    image_path = "%s/%s" % (IMAGE_BASE_PATH, image_filename)
    if not os.path.exists(image_path):
        return (1, "image not found at %s" % image_path, {})
    log.log_debug("working on image in %s" % image_path)

    create_params = { 'name'           : domain_name,
                      'arch'           : image_arch,
                      'extra'          : extra_params,
                      'mem_kb'         : params["memKB"],
                      'vcpus'          : params["vCPUs"],
                      'uuid'           : generate_uuid(),
                      'disk'           : image_path,
                      'imageType'      : 'qcow2',
                      'virtBridge'     : params["virtBridge"],
                    }
    create_xml = _generate_xml(create_params)
    domain = None
    try:
        domain = connection.defineXML(create_xml)
    except Exception as e:
        return (1, "failed to pass XML to libvirt: %s" % e, {})

    domain.create()
    virt_support.refresh()

    return (0, "image '%s' deployed and started" % domain_name, {})
Ejemplo n.º 5
0
def deploy(params, extraParams="",cache_only=None):
    """start and connect a local image with SUSE Manager"""

    urlParts  = params["downloadURL"].split('/')
    studioArchiveFileName  = urlParts[-1]
    checksum  = urlParts[-2]

    # studioArchiveFileName = workshop_test_sles11sp1.i686-0.0.1.vmx.tar.gz
    # studioArchiveFileName = Just_enough_OS_openSUSE_12.1.x86_64-0.0.1.xen.tar.gz
    m = re.search( '(.*)\.(x86_64|i\d86)-(\d+\.\d+\.\d+)\.(xen|vmx|qcow2)', studioArchiveFileName )

    imageName    = m.group(1)
    imageArch    = m.group(2)
    imageVersion = m.group(3)
    imageType    = m.group(4)
    studioImageDiskFileName = imageName+"."+imageArch+"-"+imageVersion

    try:
        connection = _connect_to_hypervisor()
    except Exception:
        e = sys.exc_info()[1]
        return (1, "%s" % e, {})

    # if we got an explicit name, we'll use it
    if "domainName" in params and params["domainName"] != "":
        imageName = params["domainName"]
    # if not, we'll try to find a free name
    elif( _domainExists(imageName, connection) ):
        for i in itertools.count(1):
            newImageName = ("%s-%i" % (imageName,i))
            if not _domainExists(newImageName, connection):
                log.log_debug("free domain found")
                imageName = newImageName
                break
    log.log_debug( "name=%s arch=%s ver=%s type=%s" % (imageName,imageArch,imageVersion,imageType) )

    if len(imageName) < 1 or len(imageArch) < 1:
        log.log_debug("invalid image name or arch")
        return (1, "invalid image name or arch: name=%s arch=%s ver=%s type=%s" % (imageName,imageArch,imageVersion,imageType), {})

    httpResponseCode = -1
    if not _fileExists("%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), checksum):
        try:
            httpResponseCode = _downloadFile(studioArchiveFileName,params["downloadURL"],params["proxySettings"])
            if not _fileExists("%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), checksum):
                log.log_debug("downloading image file failed. HTTP Code is: %s" % httpResponseCode)
                return (1, "downloading image file failed: %s/%s (%s)" % (IMAGE_BASE_PATH, studioArchiveFileName,httpResponseCode), {})
        except Exception:
            e = sys.exc_info()[1]
            return ( 1, "getting the image failed with: %s" % e )
    if cache_only:
        return (0, "image fetched and cached for later deployment", {})
    try:
        targetDir = _createTargetDir( "%s/%s" % (IMAGE_BASE_PATH, imageName) )
        _extractImage( "%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), targetDir, imageType )
    except Exception:
        e = sys.exc_info()[1]
        return (1, "extracting the image tarball failed with: %s" % e, {})

    # image exists in $IMAGE_BASE_PATH/$imageName now

    uuid = generate_uuid()
    # FIXME: check for the extensions. There might be more
    studioFileExtension = "vmdk"
    if imageType == "xen":
        studioFileExtension = "raw"
    elif imageType == "qcow2":
        studioFileExtension = "qcow2"
    extractedImagePath = "%s/%s.%s" % (targetDir,studioImageDiskFileName,studioFileExtension)
    log.log_debug("working on image in %s" % extractedImagePath)
    if not os.path.exists( extractedImagePath ):
        return (1, "extracted image not found at %s" % extractedImagePath, {})
    if imageArch in ( 'i386', 'i486', 'i568' ):
        imageArch = 'i686'

    create_params = { 'name'           : imageName,
                      'arch'           : imageArch,
                      'extra'          : extraParams,
                      'mem_kb'         : params["memKB"],
                      'vcpus'          : params["vCPUs"],
                      'uuid'           : uuid,
                      'disk'           : extractedImagePath,
                      'imageType'      : imageType,
                      'virtBridge'     : params["virtBridge"],
                    }
    create_xml = _generateXML( create_params )
    domain = None
    try:
        domain = connection.defineXML(create_xml)
    except Exception:
        e = sys.exc_info()[1]
        return (1, "failed to pass XML to libvirt: %s" % e, {})

    domain.create()
    virt_support.refresh()

    return (0, "image '%s' deployed and started" % imageName, {})