def cli_change_kernel(): """Change the kernel of an image :raises UserWarning: When there is no image with kernel """ # Get all images images_list = ImageManager.get_created_images() # Select only images with kernel attribut images_with_kernel = [] for image in images_list: if hasattr(image, 'kernel'): images_with_kernel.append(image.name) # If there is no image with kernel, raise an exception if not images_with_kernel: raise UserWarning('Not any image with a kernel') # Select the image to change kernel image_name = select_from_list(images_with_kernel) image = ImageManager.get_created_image(image_name) print('\nCurrent kernel is: ' + image.kernel + '\n') # Select an available kernel new_kernel = KernelManager.cli_select_kernel() # Set image kernel by using image method KernelManager.change_kernel(image, new_kernel)
def cli_manage_nodes(): # Get all golden images golden_images = NfsGoldenImage.get_images() if not golden_images: raise UserWarning('No nfs golden image to manage.') # Get golden images names golden_images_names = [golden_image.name for golden_image in golden_images] # Select the golden image to manage from list printc('\n[+] Select the golden image to manage:', Color.GREEN) golden_image_name = select_from_list(golden_images_names) golden_image = ImageManager.get_created_image(golden_image_name) # Choose an action for nodes management printc('\n[+] Manages nodes of image ' + golden_image_name, Color.GREEN) print(' 1 - List nodes with the image') print(' 2 - Add nodes with the image') print(' 3 - Remove nodes with the image') action = input('-->: ') # Print golden image nodes if action == '1': nodeset = golden_image.get_nodes() print(nodeset) printc('\n[OK] Done.', Color.GREEN) # Add some nodes to the image elif action == '2': printc('\n[+] Actual image NodeSet is: ' + str(golden_image.nodes), Color.GREEN) printc('[+] Please enter nodes range to add:', Color.GREEN) nodes_range = input('-->: ').replace(" ", "") # Test if nodes_range is a valid range try: golden_image.add_nodes(nodes_range) printc('\n[OK] Done.', Color.GREEN) except KeyError: raise UserWarning('The Node you have entered is not compliant.') # Delete nodes from image elif action == '3': printc('\n[+] Please enter nodes range to remove:', Color.GREEN) nodes_range = input('-->: ').replace(" ", "") # Test if nodes_range is a valid range try: golden_image.remove_nodes(nodes_range) printc('\n[OK] Done.', Color.GREEN) except KeyError: raise UserWarning('The Node you have entered is not compliant.') else: raise UserWarning('Not a valid entry')
def cli_create_golden_image(): # Get all staging images staging_images = NfsStagingImage.get_images() # Check if there are staging images if not staging_images: raise UserWarning( 'No nfs staging images. Golden image creation require an nfs staging image.' ) # Get staging images names staging_images_names = [ staging_image.name for staging_image in staging_images ] # Select a staging image for golden image creation printc('[+] Select the nfs image to use for golden image creation:', Color.GREEN) staging_image_name = select_from_list(staging_images_names) staging_image = ImageManager.get_created_image(staging_image_name) # Condition to test if image name is compliant while True: printc('\n[+] Give a name for your image', Color.GREEN) # Get new image name selected_image_name = input('-->: ').replace(" ", "") if selected_image_name == '': raise UserWarning('Image name cannot be empty !') if not ImageManager.is_image(selected_image_name): break # Else print('Image ' + selected_image_name + ' already exist, use another image name.') # Confirm image creation printc( '\n[+] Would you like to create a new nfs golden image with the following attributes: (yes/no)', Color.GREEN) print(' ├── Image name: \t\t' + selected_image_name) print(' └── Staging image from: \t' + staging_image.name) confirmation = input('-->: ').replace(" ", "") if confirmation == 'yes': # Create the image object NfsGoldenImage(selected_image_name, staging_image) printc('\n[OK] Done.', Color.GREEN) elif confirmation == 'no': printc('\nImage creation cancelled, return to main menu.', Color.YELLOW) return else: raise UserWarning('\nInvalid confirmation !')
def cli_resize_livenet_image(): # Get list of livenet images livenet_images = LivenetImage.get_images() # Check if there are livenet images if not livenet_images: raise UserWarning('No livenet images.') # Get livenet images names unmounted_images_names = [ livenet_image.name for livenet_image in livenet_images if livenet_image.is_mounted is False ] # Check if there are unmounted images # An image must be unmounted to be resized if not unmounted_images_names: raise UserWarning('No unmounted livenet images.') # Select a livenet to mount printc('[+] Select the livenet image to mount:', Color.GREEN) unmounted_image_name = select_from_list(unmounted_images_names) unmounted_image = ImageManager.get_created_image(unmounted_image_name) # Enter new size printc( 'Please enter your new image size:\n(supported units: M=1024*1024, G=1024*1024*1024)\n(Examples: 5120M or 5G)', Color.GREEN) selected_size = input('-->: ') # Check and convert the size image_size = cli_get_size(selected_size) # Check size compliance with livenet image expected size limits if int(image_size) < (LivenetImage.MIN_LIVENET_SIZE) or int(image_size) > ( LivenetImage.MAX_LIVENET_SIZE): raise UserWarning('\nSize out of limits !') # Confirm image resizing printc( '\n[+] Are you sure you want to resize image \'' + unmounted_image.name + '\' with the following size: (yes/no)', Color.GREEN) print(' └── Image size: ' + selected_size) confirmation = input('-->: ').replace(" ", "") if confirmation == 'yes': # Create the image object unmounted_image.resize(image_size) printc('\n[OK] Done.', Color.GREEN) elif confirmation == 'no': printc('\n[+] Image resizing cancelled, return to main menu.', Color.YELLOW) return
def cli_unmount_livenet_image(): livenet_images = LivenetImage.get_images() # Check if there are staging images if not livenet_images: raise UserWarning('No livenet images.') # Get staging images names mounted_images_names = [livenet_image.name for livenet_image in livenet_images if livenet_image.is_mounted is True] # Check if there unmounted images if not mounted_images_names: raise UserWarning('No mounted livenet images.') # Select a staging image for golden image creation printc('[+] Select the livenet image to unmount:', Color.GREEN) mounted_image_name = select_from_list(mounted_images_names) mounted_image = ImageManager.get_created_image(mounted_image_name) mounted_image.unmount()
# Clear potential previous bad installations before excecuting a main menu action ImageManager.clean_intallations() # With ImageManager.cli_use_modules() we can use all available modules if main_action == '1': ImageManager.cli_use_modules() # Display already created diskless images elif main_action == '2': ImageManager.cli_display_images() printc('\n[OK] Done.', Color.GREEN) # Remove a diskless image elif main_action == '3': # Get image object to remove image = ImageManager.get_created_image( ImageManager.cli_select_created_image()) printc( '\n⚠ Would you realy delete image \'' + image.name + '\' definitively (yes/no) ?', Color.RED) # get confirmation from user confirmation = input('-->: ').replace(" ", "") if confirmation == 'yes': # Remove image ImageManager.remove_image(image) printc('\n[OK] Done.', Color.GREEN) elif confirmation == 'no': printc('\n[+] Image deletion cancelled', Color.YELLOW)