def define_box(self): vagrant_boxes = self._action( action="box", action_args=("list",), output=False ).splitlines() if not vagrant_boxes: print ('\nThere are no available Vagrant (base) boxes.') print ('Please search for a suitable one at ' \ 'https://atlas.hashicorp.com/boxes/search.') print ('Once you\'ve chosen the <box> add it using the following cmd:' \ ' \'$ vagrant box add <box>\'.\n') else: playbook = io.input_path('playbook path') hostname = self.fetch_box_hosts(playbook) name = io.input_value('box name', self.suggest_name(hostname)) ip = io.input_value('internal IP') ext = VagrantExt() mem = io.input_value('amount of RAM in GB', 1) ext.set_mem(mem * 1024) ext.set_shares(self._input_shares()) (img, provider) = self._input_img(vagrant_boxes) ext.set_image(img) ext.set_provider(provider) return Box(name, playbook, hostname, ip, self.DEFAULT_USER, self.DEFAULT_PWD, ext)
def define_box(self): playbook = io.input_path('playbook path') hostname = self.fetch_box_hosts(playbook) name = io.input_value('box name', self.suggest_name(hostname)) ip = io.input_value('instance address or inventory') user = io.input_value('remote user', self.active_user) pwd = io.input_value( 'password for the remote user', default_description='ssh key', mandatory=False, hidden=True ) return Box(name, playbook, hostname, ip, user, pwd)
def redefine_box(self, previous_box): playbook = io.input_path('playbook path', previous_box.playbook) hostname = self.fetch_box_hosts(playbook) ip = io.input_value('internal IP', previous_box.ip) ext = VagrantExt() mem = io.input_value('amount of RAM in GB', previous_box.extra.mem / 1024) ext.set_mem(mem * 1024) ext.set_shares(self._input_shares()) ext.set_image(previous_box.extra.image) ext.set_provider(previous_box.extra.provider) return Box(previous_box.name, playbook, hostname, ip, self.DEFAULT_USER, self.DEFAULT_PWD, ext)
def set_vault_password(self): vault_pwd = io.input_value('Ansible vault password', hidden=True) try: # Ansible 2.4 self.loader.set_vault_secrets(vault_pwd) except: # Ansible 2.3 self.loader.set_vault_password(vault_pwd)
def _input_general_env_conf(self): print ('\nThe DigitalOcean API (v2) token is not configured.') print ('If you don\'t have it please visit ' \ 'https://cloud.digitalocean.com/settings/applications and generate one.') api_token = io.input_value('api token') do_general = DOGeneral(api_token) self.env.set_general(do_general) return do_general
def _input_ssh_keys(self, previous=None): all_keys = self.manager.all_ssh_keys() print ('\nAvailable keys: \n%s' % self._print_object_id_name(all_keys)) if not previous: default_keys = ','.join([str(k['id']) for k in all_keys]) else: default_keys = previous return io.input_value('keys', default_keys)
def test_int_input(self): self.assertEqual( io.input_value('int topic', default_value=1, prompt_fn=lambda m: '123'), 123) self.assertRaises(ValueError, io.input_value, 'int topic', default_value=1, prompt_fn=lambda m: 'aaa')
def redefine_box(self, previous_box): playbook = io.input_path('playbook path', previous_box.playbook) hostname = self.fetch_box_hosts(playbook) ip = io.input_value('instance address or inventory', previous_box.ip) user = io.input_value('remote user', previous_box.remote_user) if previous_box.remote_pwd: pwd = io.input_value( 'password for the remote user', default_value=previous_box.remote_pwd, default_description='*****', mandatory=False, hidden=True ) else: pwd = io.input_value( 'password for the remote user', default_description='ssh key', mandatory=False, hidden=True ) return Box(previous_box.name, playbook, hostname, ip, user, pwd)
def _input_shares(): shares = [] loop = True while loop: if io.input_yes_no('share a folder'): src = io.input_path('directory on the HOST machine', is_file=False) if not path.exists(src): raise ValueError("Directory '%s' on the HOST machine doesn't exists." % src) dst = io.input_value('directory on the GUEST machine') shares.append((src, dst)) else: loop = False return shares
def redefine_box(self, previous_box): playbook = io.input_path('playbook path', previous_box.playbook) hostname = self.fetch_box_hosts(playbook) ip = previous_box.ip user = io.input_value('remote user', previous_box.remote_user) if not previous_box.extra.id: ext = DOExt() ext.id = previous_box.extra.id all_images = self.manager.all_images() print ('\nAvailable images: \n%s' % self._print_object_id_name(all_images)) prev_image = next((img for img in all_images if previous_box.extra.image == img['id']), None) if prev_image: prev_image_desc = '{0} - {1} {2}'.format( prev_image['id'], prev_image['distribution'], prev_image['name'] ) ext.image = io.input_value('image', prev_image['id'], prev_image_desc) else: ext.image = io.input_value('image') all_sizes = self.manager.sizes() sizes_slug = [o['slug'] for o in all_sizes] print ('\nAvailable sizes: \n%s' % '\n'.join(sizes_slug)) ext.size = io.input_value('size', previous_box.extra.size) all_regions = self.manager.all_regions() regions_slug = [o['slug'] for o in all_regions] print ('\nAvailable regions: \n%s' % '\n'.join(regions_slug)) ext.region = io.input_value('region', previous_box.extra.region) ext.keys = self._input_ssh_keys(previous_box.extra.keys) else: ext = previous_box.extra return Box(previous_box.name, playbook, hostname, ip, user, extra=ext)
def define_box(self): ip = None ext = DOExt() if io.input_yes_no('register an existing droplet'): droplet_id = io.input_value('droplet id') droplet_info = self.manager.show_droplet(droplet_id) ext.id = droplet_id name = droplet_info['name'] created = droplet_info['created_at'] print ('\nFound droplet \'{0}\' (created {1})'.format(name, created)) ip = io.xstr(droplet_info['ip_address']) print ('IP: %s' % ip) ext.image = droplet_info['image']['id'] print ('Image: %s' % ext.image) ext.size = droplet_info['size']['slug'] print ('Size: %s' % ext.size) ext.region = droplet_info['region']['slug'] print ('Region: %s\n' % ext.region) playbook = io.input_path('playbook path') hostname = self.fetch_box_hosts(playbook) user = io.input_value('remote user', self.active_user) else: playbook = io.input_path('playbook path') hostname = self.fetch_box_hosts(playbook) name = io.input_value('box name', self.suggest_name(hostname)) user = io.input_value('remote user', self.active_user) all_images = self.manager.all_images() print ('\nAvailable images: \n%s' % self._print_object_id_name(all_images)) default_image = next((img for img in all_images if img['slug'] and self.DEFAULT_IMAGE_SLUG in img['slug']), None) if default_image: image_desc = '{0} - {1} {2}'.format( default_image['id'], default_image['distribution'], default_image['name'] ) ext.image = io.input_value('image', default_image['id'], image_desc) else: ext.image = io.input_value('image') all_sizes = self.manager.sizes() sizes_slug = [o['slug'] for o in all_sizes] print ('\nAvailable sizes: \n%s' % '\n'.join(sizes_slug)) ext.size = io.input_choice('size', self.DEFAULT_SIZE_SLUG, choices=sizes_slug) all_regions = self.manager.all_regions() regions_slug = [o['slug'] for o in all_regions] print ('\nAvailable regions: \n%s' % '\n'.join(regions_slug)) ext.region = io.input_choice('region', self.DEFAULT_REGION_SLUG, choices=regions_slug) ext.keys = self._input_ssh_keys() return Box(name, playbook, hostname, ip, user, extra=ext)
def test_value_hidden(self): pwd = 'this is a strong pwd' self.assertEqual( io.input_value('pwd', hidden=True, hidden_prompt_fn=lambda m: pwd), pwd)
def define_box(self): playbook = io.input_path('playbook path') hostname = self.fetch_box_hosts(playbook) name = io.input_value('box name', self.suggest_name(hostname)) return Box(name, playbook, hostname, '127.0.0.1')