def _initialization(self, user_info, **kwargs):
        util.printStep('Initialize the OpenNebula connector.')
        self.user_info = user_info

        if self.is_build_image():
            self.tmp_private_key, self.tmp_public_key = generate_keypair()
            self.user_info.set_private_key(self.tmp_private_key)
    def _initialization(self, user_info):
        util.printStep('Initialize the CloudStack connector.')

        self.user_info = user_info

        if self.is_build_image():
            raise NotImplementedError('The run category "%s" is not yet implemented' % self.run_category)
示例#3
0
    def _initialization(self, user_info, **kwargs):
        util.printStep('Initialize the OpenNebula connector.')
        self.user_info = user_info

        if self.is_build_image():
            self.tmp_private_key, self.tmp_public_key = generate_keypair()
            self.user_info.set_private_key(self.tmp_private_key)
示例#4
0
 def _build_image_on_opennebula(self, user_info, node_instance):
     listener = self._get_listener()
     machine_name = node_instance.get_name()
     vm = self._get_vm(machine_name)
     ip_address = self._vm_get_ip(vm)
     vm_id = int(self._vm_get_id(vm))
     self._wait_vm_in_state(vm_id, 'Active', time_out=300, time_sleep=10)
     self._build_image_increment(user_info, node_instance, ip_address)
     util.printStep('Creation of the new Image.')
     self._rpc_execute('one.vm.action', 'poweroff', vm_id)
     self._wait_vm_in_state(vm_id, 'Poweroff', time_out=300, time_sleep=10)
     listener.write_for(machine_name, 'Saving the image')
     new_image_name = node_instance.get_image_short_name() + time.strftime(
         "_%Y%m%d-%H%M%S")
     new_image_id = int(
         self._rpc_execute('one.vm.disksaveas', vm_id, 0, new_image_name,
                           '', -1))
     self._wait_image_in_state(new_image_id,
                               'Ready',
                               time_out=1800,
                               time_sleep=30)
     listener.write_for(machine_name, 'Image saved !')
     self._rpc_execute('one.vm.action', 'resume', vm_id)
     self._wait_vm_in_state(vm_id, 'Active', time_out=300, time_sleep=10)
     return str(new_image_id)
    def _initialization(self, user_info):
        util.printStep('Initialize the OpenStack connector.')
        self._thread_local.driver = self._get_driver(user_info)

        try:
            self.flavors = self._thread_local.driver.list_sizes()
        except InvalidCredsError as e:
            raise Exceptions.ValidationException("%s: Invalid Cloud credentials. "
                                                 "Please check your Cloud username, password, project name and domain "
                                                 "(if applicable) in your SlipStream user profile."
                                                 % self.get_cloud_service_name())
        except LibcloudError as e:
            if e.message == 'Could not find specified endpoint':
                raise Exceptions.ValidationException("%s: Invalid Cloud configuration. "
                                                     "Please ask your SlipStream administrator to check the region, "
                                                     "service-type and service-name."
                                                     % self.get_cloud_service_name())
            else:
                raise

        if self.is_deployment():
            self._get_iaas_attributes()
            self._import_keypair(user_info)
        elif self.is_build_image():
            self._get_iaas_attributes()
            self._create_keypair_and_set_on_user_info(user_info)
示例#6
0
    def _initialization(self, user_info):
        util.printStep('Initialize the OpenStack connector.')
        self._thread_local.driver = self._get_driver(user_info)

        try:
            self.flavors = self._thread_local.driver.list_sizes()
        except InvalidCredsError as e:
            raise Exceptions.ValidationException("%s: Invalid Cloud credentials. "
                                                 "Please check your Cloud username, password, project name and domain "
                                                 "(if applicable) in your SlipStream user profile."
                                                 % self.get_cloud_service_name())
        except LibcloudError as e:
            if e.message == 'Could not find specified endpoint':
                raise Exceptions.ValidationException("%s: Invalid Cloud configuration. "
                                                     "Please ask your SlipStream administrator to check the region, "
                                                     "service-type and service-name."
                                                     % self.get_cloud_service_name())
            else:
                raise

        if self.is_deployment():
            self._get_iaas_attributes()
            self._import_keypair(user_info)
        elif self.is_build_image():
            self._get_iaas_attributes()
            self._create_keypair_and_set_on_user_info(user_info)
示例#7
0
    def _build_image_on_openstack(self, user_info, node_instance):
        self._thread_local.driver = self._get_driver(user_info)
        listener = self._get_listener()

        if not user_info.get_private_key() and self.tempPrivateKey:
            user_info.set_private_key(self.tempPrivateKey)
        machine_name = node_instance.get_name()

        vm = self._get_vm(machine_name)

        util.printAndFlush("\n  node_instance: %s \n" % str(node_instance))
        util.printAndFlush("\n  VM: %s \n" % str(vm))

        ip_address = self._vm_get_ip(vm)
        vm_id = self._vm_get_id(vm)
        instance = vm['instance']

        self._wait_instance_in_running_state(vm_id)

        self._build_image_increment(user_info, node_instance, ip_address)

        util.printStep('Creation of the new Image.')
        listener.write_for(machine_name, 'Saving the image')
        newImg = self._thread_local.driver.create_image(instance,
                                                        node_instance.get_image_short_name(),
                                                        metadata=None)

        self._wait_image_creation_completed(newImg.id)
        listener.write_for(machine_name, 'Image saved !')

        return newImg.id
    def _execute_target(self, target_name, exports=None, abort_on_err=False, ssdisplay=True, ignore_abort=False):
        target = self.node_instance.get_image_target(target_name)

        display_target_name = {
            'prerecipe': 'Pre-install',
            'recipe': 'Post-install',
            'execute': 'Deployment',
            'report': 'Reporting',
            'onvmadd': 'On VM Add',
            'onvmremove': 'On VM Remove'
        }.get(target_name, target_name)

        if target is None:
            util.printAndFlush('Nothing to do for script: %s' % display_target_name)
            return

        for subtarget in target:
            full_target_name = '%s:%s' % (subtarget.get('module_uri'), display_target_name)

            if target_name in [NodeDecorator.NODE_PRERECIPE, NodeDecorator.NODE_RECIPE] \
                    and not self._need_to_execute_build_step(target, subtarget):
                util.printAndFlush('Component already built. Nothing to do on target: %s' % full_target_name)
                continue

            script = subtarget.get('script')
            if script:
                message = "Executing script '%s'" % full_target_name
                util.printStep(message)
                if ssdisplay:
                    self.wrapper.set_statecustom(message)

                fail_msg = "Failed running '%s' script on '%s'" % (full_target_name, self._get_node_instance_name())
                self._launch_script(script, exports, abort_on_err, ignore_abort, fail_msg, full_target_name)
            else:
                util.printAndFlush('Nothing to do for script: %s' % full_target_name)
    def _build_image_on_openstack(self, user_info, node_instance):
        self._thread_local.driver = self._get_driver(user_info)
        listener = self._get_listener()

        if not user_info.get_private_key() and self.tempPrivateKey:
            user_info.set_private_key(self.tempPrivateKey)
        machine_name = node_instance.get_name()

        vm = self._get_vm(machine_name)

        util.printAndFlush("\n  node_instance: %s \n" % str(node_instance))
        util.printAndFlush("\n  VM: %s \n" % str(vm))

        ip_address = self._vm_get_ip(vm)
        vm_id = self._vm_get_id(vm)
        instance = vm['instance']

        self._wait_instance_in_running_state(vm_id)

        self._build_image_increment(user_info, node_instance, ip_address)

        util.printStep('Creation of the new Image.')
        listener.write_for(machine_name, 'Saving the image')
        newImg = self._thread_local.driver.create_image(instance,
                                                        node_instance.get_image_short_name(),
                                                        metadata=None)

        self._wait_image_creation_completed(newImg.id)
        listener.write_for(machine_name, 'Image saved !')

        return newImg.id
 def _initialization(self, user_info, **kwargs):
     util.printStep('Initialize the Docker connector.')
     self.user_info = user_info
     self.cert_string = user_info.get_cloud(self.CERT_KEY).replace("\\n", "\n")
     self.key_string = user_info.get_cloud(self.KEY_KEY).replace("\\n", "\n")
     self.docker_api = requests.Session()
     self.docker_api.verify = False
     self.docker_api.headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
 def initialization(self, user_info):
     util.printStep('Initialize the OpenStack connector.')
     self._thread_local.driver = self._getDriver(user_info)
     self.flavors = self._thread_local.driver.list_sizes()
     self.images = self._thread_local.driver.list_images()
     
     if self.run_category == RUN_CATEGORY_DEPLOYMENT:
         self._importKeypair(user_info)
     elif self.run_category == RUN_CATEGORY_IMAGE:
         self._createKeypairAndSetOnUserInfo(user_info)
    def updateSlipStreamImage(self):
        util.printStep("Updating SlipStream image run")

        image_info = self.getImageInfo()

        newImageId = self.cloudProxy.getNewImageId()

        if not newImageId:
            return

        self._updateSlipStreamImage(self.cloudProxy.getResourceUri(image_info),
                                    newImageId)
    def initialization(self, user_info):
        util.printStep('Initialize the CloudStack connector.')
        self._thread_local.driver = self._getDriver(user_info)
        self.sizes = self._thread_local.driver.list_sizes()
        self.images = self._thread_local.driver.list_images()
        self.user_info = user_info

        if self.run_category == RUN_CATEGORY_DEPLOYMENT:
            self._importKeypair(user_info)
        elif self.run_category == RUN_CATEGORY_IMAGE:
            #self._createKeypairAndSetOnUserInfo(user_info)
            raise NotImplementedError('The run category "%s" is not yet implemented')
示例#14
0
    def _initialization(self, user_info):
        util.printStep('Initialize the CloudStack connector.')

        self.user_info = user_info

        if self.is_build_image():
            raise NotImplementedError('The run category "%s" is not yet implemented' % self.run_category)
        elif self.is_deployment():
            try:
                self._import_keypair(user_info)
            except Exceptions.ExecutionException as e:
                util.printError(e)
    def onProvisioning(self):
        super(OrchestratorImageBuildExecutor, self).onProvisioning()

        util.printStep('Starting instance')
        try:
            self.wrapper.start_node_instances()
        except Exceptions.AbortException:
            pass
        except Exception as ex:
            util.printError('Error starting instance with error: %s' % ex)
            raise
        finally:
            self._complete_machine_state()
    def onProvisioning(self):
        super(OrchestratorImageBuildExecutor, self).onProvisioning()

        util.printStep('Starting instance')
        try:
            self.wrapper.start_node_instances()
        except Exceptions.AbortException:
            pass
        except Exception as ex:
            util.printError('Error starting instance with error: %s' % ex)
            raise
        finally:
            self._complete_machine_state()
    def onInitializing(self):
        util.printAction('Initializing')
        util.printStep('Starting instances')
        try:
            self.wrapper.startImages()
        except Exceptions.AbortException:
            pass
        except Exception as ex:
            util.printError('Error starting instances with error: %s' % ex)
            raise

        util.printStep('Publishing instance initialization information')
        self.wrapper.publishDeploymentInitializationInfo()
    def onInitializing(self):
        util.printAction('Initializing')

        self._addSshPubkeyIfNeeded()

        util.printStep('Getting deployment targets')

        self.targets = self.wrapper.getTargets()

        util.printDetail('Deployment targets:')
        for target, script in self.targets.items():
            util.printAndFlush('-' * 25)
            util.printDetail('Target: %s' % target)
            util.printDetail('Script:\n%s\n' % script[0])
示例#19
0
 def _run_instances_action(action, action_name):
     """
     :param action: action to run
     :type action: callable
     :param action_name: name of the action
     :type: string
     """
     util.printStep('%s instances' % action_name.capitalize())
     try:
         action()
     except Exceptions.AbortException:
         pass
     except Exception as ex:
         util.printError('Error %s instances: %s' % (action_name, ex))
         raise
示例#20
0
    def _start_image(self, user_info, node_instance, vm_name):
        # Adapt naming convention from IaaS model
        try:
            service = json.loads(node_instance.get_cloud_parameter("service"))
        except ValueError as ve:
            raise ValueError("Requested service is not in JSON format - %s" %
                             ve), None, sys.exc_info()[2]
        except:
            raise

        service_name = service["Name"] if service.has_key("Name") else vm_name

        util.printStep('Deploy service %s to %s' %
                       (service_name, user_info.get_cloud_endpoint()))
        return self._start_container_in_docker(user_info, node_instance,
                                               service_name)
    def onExecuting(self):
        super(OrchestratorImageBuildExecutor, self).onExecuting()
        if self.wrapper.isAbort():
            util.printError('Abort set, skipping Running')
            self._complete_machine_state()
            return

        util.printStep('Building new image')

        try:
            self.wrapper.build_image()
        except KeyboardInterrupt:
            raise
        except Exception as ex:
            self.wrapper.fail(str(ex))
        finally:
            self._complete_machine_state()
    def onExecuting(self):
        super(OrchestratorImageBuildExecutor, self).onExecuting()
        if self.wrapper.isAbort():
            util.printError('Abort set, skipping Running')
            self._complete_machine_state()
            return

        util.printStep('Building new image')

        try:
            self.wrapper.build_image()
        except KeyboardInterrupt:
            raise
        except Exception as ex:
            self.wrapper.fail(str(ex))
        finally:
            self._complete_machine_state()
示例#23
0
    def _initialization(self, user_info):
        util.printStep('Initialize the CloudStack connector.')
        self._thread_local.driver = self._get_driver(user_info)
        self.zones = self._thread_local.driver.list_locations()
        self.zone = self._get_zone(user_info)
        self.sizes = self._thread_local.driver.list_sizes(location=self.zone)
        self.images = self._thread_local.driver.list_images(location=self.zone)

        self.user_info = user_info

        if self.is_build_image():
            raise NotImplementedError('The run category "%s" is not yet implemented' % self.run_category)
        elif self.is_deployment():
            try:
                self._import_keypair(user_info)
            except Exceptions.ExecutionException as e:
                util.printError(e)
    def onTerminal(self):
        util.printAction('Terminating')
        util.printStep('Stopping instances')

        try:
            self.wrapper.stopNodes()
        except Exceptions.AbortException:
            pass
        except Exception as ex:
            util.printError('Error stopping instances: %s' % ex)
            raise

        util.printStep('Publishing instance termination information')
        self.wrapper.publishDeploymentTerminateInfo()

        super(OrchestratorDeploymentExecutor, self).onTerminal()

        self._killItself()
 def _build_image_on_opennebula(self, user_info, node_instance):
     listener = self._get_listener()
     machine_name = node_instance.get_name()
     vm = self._get_vm(machine_name)
     ip_address = self._vm_get_ip(vm)
     vm_id = int(self._vm_get_id(vm))
     self._wait_vm_in_state(vm_id, 'Active', time_out=300, time_sleep=10)
     self._build_image_increment(user_info, node_instance, ip_address)
     util.printStep('Creation of the new Image.')
     self._rpc_execute('one.vm.action', 'poweroff', vm_id)
     self._wait_vm_in_state(vm_id, 'Poweroff', time_out=300, time_sleep=10)
     listener.write_for(machine_name, 'Saving the image')
     new_image_name = node_instance.get_image_short_name() + time.strftime("_%Y%m%d-%H%M%S")
     new_image_id = int(self._rpc_execute(
         'one.vm.disksaveas', vm_id, 0, new_image_name, '', -1))
     self._wait_image_in_state(new_image_id, 'Ready', time_out=1800, time_sleep=30)
     listener.write_for(machine_name, 'Image saved !')
     self._rpc_execute('one.vm.action', 'resume', vm_id)
     self._wait_vm_in_state(vm_id, 'Active', time_out=300, time_sleep=10)
     return str(new_image_id)
    def _install_user_packages(self):
        util.printAndFlush('Installing packages')

        if self.is_image_built():
            util.printAndFlush(
                'Component already built. No packages to install')
            return

        packages = self.node_instance.get_packages()
        if packages:
            message = 'Installing packages: %s' % ', '.join(packages)
            fail_msg = "Failed installing packages on '%s'" % self._get_node_instance_name(
            )
            util.printStep(message)
            self.wrapper.set_statecustom(message)
            cmd = util.get_packages_install_command(
                self.node_instance.get_platform(), packages)
            self._launch_script('#!/bin/sh -xe\n%s' % cmd,
                                fail_msg=fail_msg,
                                name='Install packages')
        else:
            util.printAndFlush('No packages to install')
 def _executeTarget(self, target):
     util.printStep("Executing target '%s'" % target)
     if target in self.targets:
         tmpfilesuffix = ''
         if util.isWindows():
             tmpfilesuffix = '.ps1'
         fn = tempfile.mktemp(suffix=tmpfilesuffix)
         if isinstance(self.targets[target][0], unicode):
             with codecs.open(fn, 'w', 'utf8') as fh:
                 fh.write(self.targets[target][0])
         else:
             with open(fn, 'w') as fh:
                 fh.write(self.targets[target][0])
         os.chmod(fn, 0755)
         currentDir = os.getcwd()
         os.chdir(tempfile.gettempdir() + os.sep)
         try:
             self._executeRaiseOnError(fn)
         finally:
             os.chdir(currentDir)
     else:
         print 'Nothing to do'
    def _buildImageOnOpenStack(self, userInfo, imageInfo):
        self._thread_local.driver = self._getDriver(userInfo)

        vm = self.getVm(NodeDecorator.MACHINE_NAME)

        util.printAndFlush("\n  imageInfo: %s \n" % str(imageInfo))
        util.printAndFlush("\n  VM: %s \n" % str(vm))

        ipAddress = self.vmGetIp(vm)
        self._creatorVmId = self.vmGetId(vm)
        instance = vm['instance']

        self._waitInstanceInRunningState(self._creatorVmId)

        self._buildImageIncrement(userInfo, imageInfo, ipAddress)

        attributes = self.getAttributes(imageInfo)

        util.printStep('Creation of the new Image.')
        newImg = self._thread_local.driver.ex_save_image(instance, attributes['shortName'], metadata=None)

        self._waitImageCreationCompleted(newImg.id)

        self._newImageId = newImg.id
    def _buildImageIncrement(self, user_info, imageInfo, host):
        prerecipe, recipe, packages = self.extractAllTargets(imageInfo)
        try:
            username, password, sshPrivateKeyFile = \
                self._getSshCredentials(imageInfo, user_info,
                                        NodeDecorator.MACHINE_NAME)

            if not self.hasCapability(self.CAPABILITY_CONTEXTUALIZATION) and not sshPrivateKeyFile:
                password = ''
                sshPrivateKeyFile, publicKey = self._getTempPrivateKeyFileNameAndPublicKey()

            self._waitCanConnectWithSshOrAbort(host, username=username,
                                               password=password,
                                               sshKey=sshPrivateKeyFile)

            if prerecipe:
                util.printStep('Running Pre-recipe')
                remoteRunScript(username, host, prerecipe,
                                sshKey=sshPrivateKeyFile, password=password)
            if packages:
                util.printStep('Installing Packages')
                remoteInstallPackages(username, host, packages,
                                      self.getPlatform(imageInfo),
                                      sshKey=sshPrivateKeyFile, password=password)
            if recipe:
                util.printStep('Running Recipe')
                remoteRunScript(username, host, recipe,
                                sshKey=sshPrivateKeyFile, password=password)

            if not self.hasCapability(self.CAPABILITY_CONTEXTUALIZATION):
                self._revertSshSecurity(host, username, sshPrivateKeyFile, publicKey)
        finally:
            try:
                os.unlink(sshPrivateKeyFile)
            except:
                pass
 def _print_step(self, message, write_for=None):
     util.printStep(message)
     if write_for:
         self._get_listener().write_for(write_for, message)
示例#31
0
 def _printStep(self, message):
     util.printStep(message)
示例#32
0
 def _initialization(self, user_info, **kwargs):
     util.printStep('Initialize the Kubernetes connector.')
     self.user_info = user_info
示例#33
0
    def _update_slipstream_image(self, node_instance, new_image_id):
        util.printStep("Updating SlipStream image run")

        url = '%s/%s' % (node_instance.get_image_resource_uri(),
                         self._get_cloud_service_name())
        self._put_new_image_id(url, new_image_id)
 def _add_ssh_pubkey(self, login_user):
     if not util.is_windows():
         util.printStep('Adding the public keys')
         append_ssh_pubkey_to_authorized_keys(self._get_user_ssh_pubkey(),
                                              login_user)
示例#35
0
 def _printStep(self, message):
     util.printStep(message)
示例#36
0
 def _print_step(self, message, write_for=None):
     util.printStep(message)
     if write_for:
         self._get_listener().write_for(write_for, message)
示例#37
0
    def _update_slipstream_image(self, node_instance, new_image_id):
        util.printStep("Updating SlipStream image run")

        url = '%s/%s' % (node_instance.get_image_resource_uri(),
                         self._get_cloud_service_name())
        self._put_new_image_id(url, new_image_id)
 def _addSshPubkey(self):
     util.printStep('Adding the public key')
     appendSshPubkeyToAuthorizedKeys(self._getUserSshPubkey())