def check_how(self): """ Decide what to do when HOW is ... does not add anything into Vagrantfile yet """ self.debug('VagrantProvider', 'Checking initial status, setting defaults.') self.set_default('how', 'virtual') self.set_default('image', self.default_image) image = self.data['image'] if self.is_uri(image): self.set_default('box', 'box_' + self.instance_name) if re.search(r"\.box$", image) is None: # an actual box file, Great! pass elif re.search(r"\.qcow2$", image) is None: # do some qcow2 magic self.data['box'] = '...' raise SpecificationError("NYI: QCOW2 image") else: raise SpecificationError( f"Image format not recognized: {image}") else: self.set_default('box', image) self.data['image'] = None for x in ('how', 'box', 'image'): self.info(f' {x}', self.data[x])
def prepare(self, how, what): """ Run prepare phase """ try: self._prepare_map[how](what) except AttributeError as e: raise SpecificationError( f"Prepare method '{how}' is not supported.")
def how_generic(self, how, what): """ Handle a generic 'Prepare', which is relayed to provider's prepare(). """ # Process multiple inputs if type(what) is list: return [self.how_generic(how, w) for w in what] # Try guesssing the path (1) whatpath = os.path.join(self.plan.run.tree.root, what) self.debug('Looking for prepare script in', whatpath) if os.path.exists(whatpath) and os.path.isfile(whatpath): what = whatpath else: # Try guesssing the path (2) whatpath = os.path.join(self.plan.workdir, 'discover', self.data[0]['name'], 'tests', what) self.debug('Looking for prepare script', whatpath) if os.path.exists(whatpath) and os.path.isfile(whatpath): what = whatpath try: self.plan.provision.prepare(how, what) except AttributeError as error: raise SpecificationError( 'NYI: cannot currently run this preparator.')
def how(self): """ Decide what to do when HOW is ... does not add anything into Vagrantfile yet """ self.debug() self.set_default('how', 'virtual') self.set_default('image', self.default_image) image = self.data['image'] try: i = urlparse(image) if not i.schema: raise (i) self.image_uri = i except: pass self.debug('image_uri', self.image_uri) if self.image_uri: self.set_default('box', 'box_' + self.instance_name) if re.search(r"\.box$", image) is None: # an actual box file, Great! pass elif re.search(r"\.qcow2$", image) is None: # do some qcow2 magic self.data['box'] = '...' raise SpecificationError("NYI: QCOW2 image") else: raise SpecificationError( f"Image format not recognized: {image}") else: self.set_default('box', image) for x in ('how', 'box', 'image'): self.debug(x, self.data[x]) # TODO: Dynamic call [switch] to specific how_* return True
def check_input(self): """ Initialize configuration(sets defaults), based on data (how, image). does not create Vagrantfile or add anything into it. """ self.debug('VagrantProvider', 'Checking initial status, setting defaults.') self.set_default('how', 'virtual') self.set_default('image', self.default_image) image = self.data['image'] if self.is_uri(image): self.set_default('box', 'box_' + self.instance_name) if re.search(r"\.box$", image) is None: # an actual box file, Great! pass elif re.search(r"\.qcow2$", image) is None: # do some qcow2 magic self.data['box'] = '...' raise SpecificationError("NYI: QCOW2 image") else: raise SpecificationError( f"Image format not recognized: {image}") else: self.set_default('box', image) self.data['image'] = None self.set_default('memory', self.default_memory) # General ssh config, used for 'managed' as well self.set_default('user', self.default_user) for key, val in self.data.items(): if self.debugon or key in self.display: if not val is None: self.info(f'{key}', val)
def wake(self): """ Wake up the step (process workdir and command line) """ self.super.wake() for i in range(len(self.data)): self.opts(i, 'how', 'script') for alt in ('playbook', 'playbooks'): value = self.alias(i, 'script', alt) how = self.data[i]['how'] if value and how in self.valid_inputs: valid = self.valid_inputs[how] if not alt in valid: raise SpecificationError( f"You cannot specify {alt} for {how}.")
def how_connect(self): """ Defines a connection to guest using managed provider from managed-servers plugin. Recreates Vagrantfile with dummy box. """ name = 'connect' self.debug("generating", name) guest = self.data['guest'] if guest is None: raise SpecificationError('Guest is not specified.') self.debug("guest", guest) self.plugin_install(f"managed-servers") self.data['box'] = self.dummy_image self.create() self.add_provider('managed', self.kve('server', guest))
def save(self): """ Save ProvisionVagrant step """ raise SpecificationError("NYI: cannot save") self.super.save()
def load(self): """ Load ProvisionVagrant step """ raise SpecificationError("NYI: cannot load") self.super.load()
def how_container(self): self.debug("generating", "container") raise SpecificationError('NYI: cannot currently run containers.')
def how_openstack(self): self.debug("generating", "openstack") raise SpecificationError('NYI: cannot currently run on openstack.')
def run_prepare(self, name, path): """ add single 'preparator' and run it """ raise SpecificationError('NYI: cannot currently add preparators.') return self.add_config('provision', name, 'path')
def sync_workdir_from_guest(self): """ sync from guest to host """ raise SpecificationError('NYI: cannot currently sync from guest.')