Ejemplo n.º 1
0
 def _checkImageExists(self, imageId):
     self.printDetail('Checking image availability.')
     if self.noCheckImageUrl:
         printWarning('Image availability check is disabled.')
         return
     imageObject = Image(self.configHolder)
     imageObject.checkImageExists(imageId)
Ejemplo n.º 2
0
 def _setInboundPorts(self):
     if Image.isImageId(self.vm_image):
         image = Image(self.configHolder)
         try:
             self.inboundPorts = image.getInboundPortsByImageId(self.vm_image)
         except Exceptions.ExecutionException:
             pass
Ejemplo n.º 3
0
 def _setDiskImageFormat(self):
     useQcowDiskFormat = getattr(self, 'useQcowDiskFormat', False)
     # if image ID was provided extract disk driver type from manifest
     if self.vm_image:
         if not useQcowDiskFormat and Image.isImageId(self.vm_image):
             image = Image(self.configHolder)
             self.disk_driver = image.getImageFormatByImageId(self.vm_image)
             return
     self.disk_driver = (useQcowDiskFormat and 'qcow2') or 'raw'
Ejemplo n.º 4
0
    def _setDisksBusType(self):
        if self.vmDisksBus:
            disks_bus = self.vmDisksBus
        else:
            if Image.isImageId(self.vm_image):
                image = Image(self.configHolder)
                disks_bus = image.getImageDisksBusTypeByImageId(self.vm_image)
            else:
                return

        try:
            self.vm_disks_prefix = Runner.DISKS_BUS_PREFIX_MAP[disks_bus]
        except KeyError:
            raise Exception('Unknown disks bus type %s' % disks_bus)
Ejemplo n.º 5
0
    def _checkMessageAndImageid(self):
        if len(self.args) != 0:
            self.msg_message = self.args[0]
        else:
            self.printError("Message should be set as first argument")

        if self.options.imageid:
            if not Image.isImageId(self.options.imageid):
                raise ValidationException("Marketplace image ID is expected.")
Ejemplo n.º 6
0
 def __init__(self, message, image_id, configHolder):
     """message - empty string or JSON representation of a map 
     (can be base64 encoded).
     image_id - Marketplace image ID
     """
     super(ImageIdPublisher, self).__init__(message, configHolder)
     if not Image.isImageId(image_id):
         raise InputException('Marketplace image ID is expected.')
     self.message = self._set_imageid_on_message(self.message, image_id)
Ejemplo n.º 7
0
    def runInstance(self, details=False):
        self._printContacting()

        if Image.isImageId(self.vm_image):
            self._checkImageExists(self.vm_image)
            self.vm_image = self._prependMarketplaceUrlIfImageId(self.vm_image)
        elif Image.isDiskId(self.vm_image):
            self.vm_image = self._createDiskUrlIfDiskId(self.vm_image)
        elif self._isAliasUrl(self.vm_image):
            self.vm_image = self._resolveUrl(self.vm_image)
        else:
            raise Exceptions.ValidationException('Image reference must be an '
                                                 'Alias URL, Marketplace Image ID or Disk ID:  %s' %
                                                 self.vm_image)

        printAction('Starting machine(s)')

        self.printDetail('Using VM template file: %s' % self.vmTemplateFile)

        vmTpl = self._buildVmTemplate(self.vmTemplateFile)

        label = (self.instanceNumber > 1) and 'machines' or 'machine'

        printStep('Starting %s %s' % (self.instanceNumber, label))

        self.printDetail('on endpoint: %s' % self.endpoint, Util.VERBOSE_LEVEL_DETAILED)
        self.printDetail('with template:\n%s' % vmTpl, Util.VERBOSE_LEVEL_DETAILED)

        for vmNb in range(self.instanceNumber):
            vmId = self.cloud.vmStart(vmTpl)
            self.vmIds.append(vmId)
            networkName, ip = self.getNetworkDetail(vmId)
            self.vmIdsAndNetwork.append((vmId, networkName, ip))
            vmIpPretty = '\t%s ip: %s' % (networkName.title(), ip)
            printStep('Machine %s (vm ID: %s)\n%s' % (vmNb + 1, vmId, vmIpPretty))
            self.instancesDetail.append({'id': vmId, 'ip': ip, 'networkName': networkName})
        self._saveVmIds()

        printStep('Done!')

        if not details:
            return self.vmIds
        else:
            return self.vmIdsAndNetwork
Ejemplo n.º 8
0
    def _calculateCheckSums(self):
        checkSumNames = ManifestInfo.CHECKSUM_NAMES
        # checksums to do if we were not given any
        checkSums = dict([(x, getattr(self.options, x, '')) for x in checkSumNames])
        checkSumsToDo = [k for k, v in checkSums.items() if not v]
        # remove the ones we told not to do
        for c in checkSumsToDo[:]:
            if getattr(self.options, 'no%s' % c.title(), False):
                checkSumsToDo.remove(c)
        if not checkSumsToDo and not self.options.sha1:
            checkSumsToDo = ManifestInfo.MANDATORY_CHECKSUMS

        bytes, chksums = Image.checksumImage(self.image, checkSumsToDo)

        self.options.__dict__.update({'bytes': bytes})
        self.options.__dict__.update(chksums)
Ejemplo n.º 9
0
 def _checkImageExists(self):
     image = Image(self.configHolder)
     image.checkImageExists(self.image)
Ejemplo n.º 10
0
            msg = "Image creation failed. Instance final state '%s'. Error: %s" % (
                vm_state,
                info_attributes.get("template_error_message", "not set"),
            )
            self.fail(msg)

        # Assert new image.
        # Assuming we are running on FE and can access VM log file.
        vm_id = creator.getVmId()
        mp_and_id = ""
        for line in open("/var/log/one/%s.log" % vm_id).readlines():
            if re.search("MARKETPLACE_AND_IMAGEID", line):
                mp_and_id = line.split()
                break
        image_id = mp_and_id[-1].strip("'")
        if not Image.isImageId(image_id):
            self.fail("Failed to obtain new image ID.")
        marketplace_url = mp_and_id[-2].strip("'")
        if not Util.isValidNetLocation(marketplace_url):
            self.fail("Failed to get marketplace endpoint.")

        self.configHolder.marketplaceEndpoint = marketplace_url
        ManifestDownloader(self.configHolder).getManifestInfo(image_id)

        self.image = image_id
        self.oneUsername = self.testUsername
        self.proxyOneadminPassword = self.testPassword
        cmds = ['python -c "import dirq"', "ls -l %s" % remote_test_file]

        self.marketplaceEndpoint = marketplace_url
        self._runInstanceTest(cmdToRun=cmds)
Ejemplo n.º 11
0
 def _createDiskUrlIfDiskId(self, image):
     if Image.isDiskId(image):
         self.pdiskEndpointHostname = VolumeManager.getFQNHostname(self.pdiskEndpoint)
         return "pdisk:%s/%s" % (self.pdiskEndpoint.rstrip('/'), image)
     else:
         return image
Ejemplo n.º 12
0
 def _prependMarketplaceUrlIfImageId(self, image):
     if Image.isImageId(image):
         return MarketplaceUtil.metadataUrl(self.marketplaceEndpoint, image)
     else:
         return image
Ejemplo n.º 13
0
def _vm_get_root_disk_size_from_marketplace(disk_source, config_holder):
    image = Image(config_holder)
    image_id = _disk_source_get_image_id(disk_source)
    size_bytes = image._getImageElementValue('bytes', image_id)
    # NB! PDisk "rounds" the required volume size before creation by adding 1GB.
    return 1 + int(size_bytes) / 1024 ** 3