def requestArchitecture(self, args, template): arch = template.getArchs()[0] # If there is more than one architecture available for the template # Ask the user to choose if len(template.getArchs()) > 1: if args.arch != None: COMMANDLINELOGGER.debug( "An architecture has been given in by the user.") try: arch = Architecture.fromString(self.args.arch) except: COMMANDLINELOGGER.debug( "Given architecture is not supported by machination.") raise InvalidCmdLineArgument("architecture", self.args.arch) if arch not in self.template.getArchs(): COMMANDLINELOGGER.debug( "Given architecture is not supported by the template (shall be one of %s)." .format(', '.join(template.getArchs()))) raise InvalidCmdLineArgument("architecture", self.args.arch) else: if args.no_interactive == False: COMMANDLINELOGGER.debug("Request an architecture...") arch = Architecture.fromString( RegexedQuestion( "Select an architecture [{0}]".format(",".join( map(str, template.getArchs()))), "Architecture must be from {0}".format(",".join( map(str, template.getArchs()))), COMMANDLINELOGGER, "^[{0}]$".format("\\b|\\b".join( map(str, template.getArchs()))), arch.name).ask()) else: COMMANDLINELOGGER.debug("Missing architecture argument") raise InvalidCmdLineArgument("architecture", args.arch) else: COMMANDLINELOGGER.debug( "Template has only one architecture. It will be used as the default value." ) return arch
def requestArchitecture(self, args, template): arch = template.getArchs()[0] # If there is more than one architecture available for the template # Ask the user to choose if len(template.getArchs()) > 1: if args.arch != None: COMMANDLINELOGGER.debug("An architecture has been given in by the user.") try: arch = Architecture.fromString(self.args.arch) except: COMMANDLINELOGGER.debug("Given architecture is not supported by machination.") raise InvalidCmdLineArgument("architecture", self.args.arch) if arch not in self.template.getArchs(): COMMANDLINELOGGER.debug( "Given architecture is not supported by the template (shall be one of %s).".format( ", ".join(template.getArchs()) ) ) raise InvalidCmdLineArgument("architecture", self.args.arch) else: if args.no_interactive == False: COMMANDLINELOGGER.debug("Request an architecture...") arch = Architecture.fromString( RegexedQuestion( "Select an architecture [{0}]".format(",".join(map(str, template.getArchs()))), "Architecture must be from {0}".format(",".join(map(str, template.getArchs()))), COMMANDLINELOGGER, "^[{0}]$".format("\\b|\\b".join(map(str, template.getArchs()))), arch.name, ).ask() ) else: COMMANDLINELOGGER.debug("Missing architecture argument") raise InvalidCmdLineArgument("architecture", args.arch) else: COMMANDLINELOGGER.debug("Template has only one architecture. It will be used as the default value.") return arch
def from_yaml(cls, loader, node): representation = loader.construct_mapping(node, deep=True) archs = [] # Check if architectures are present in the template if "archs" in representation.keys() and type(representation["archs"]) is list: for p in representation["archs"]: arch = Architecture.fromString(p); archs.append(arch) providers = [] # Check if providers are present in the template if "providers" in representation.keys() and type(representation["providers"]) is list: for p in representation["providers"]: providers.append(Provider.fromString(p)()) provisioners = [] # Check if provisioners are present in the template if "provisioners" in representation.keys() and type(representation["provisioners"]) is list: for p in representation["provisioners"]: provisioners.append(Provisioner.fromString(p)()) osVersions = None # Check if osVersions are present in the template if "os_versions" in representation.keys() and type(representation["os_versions"]) is list: osVersions = representation["os_versions"] guestInterfaces = 0 if "guest_interfaces" in representation.keys(): guestInterfaces = representation["guest_interfaces"] roles = [] if "roles" in representation.keys(): roles = representation["roles"] comments = "" if "comments" in representation.keys(): comments = representation["comments"] return MachineTemplate(loader.stream.name, archs, osVersions, providers, provisioners, guestInterfaces, comments, roles)
def from_yaml(cls, loader, node): representation = loader.construct_mapping(node, deep=True) # Retrieve the elements to create an instance arch = None if "arch" in representation.keys(): arch = Architecture.fromString(representation["arch"]) provider = None if "provider" in representation.keys(): provider = Provider.fromString(representation["provider"])() provisioner = None if "provisioner" in representation.keys(): provisioner = Provisioner.fromString(representation["provisioner"])() name = os.path.basename(os.path.dirname(loader.stream.name)) template = None if "template" in representation.keys(): template = MACHINE_TEMPLATE_REGISTRY.getTemplates()[representation["template"]] osVersion = None if "os_version" in representation.keys(): osVersion = representation["os_version"] guestInterfaces = [] if "guest_interfaces" in representation.keys(): guestInterfaces = representation["guest_interfaces"] sharedFolders = [] if "shared_folders" in representation.keys(): sharedFolders = representation["shared_folders"] return MachineInstance(name, template, arch, osVersion, provider, provisioner, guestInterfaces, sharedFolders)