def requestProvisionner(self, args, template): provisioner = template.getProvisioners()[0] # If there is more than one provisioner available for the template if len(template.getProvisioners()) == 1: COMMANDLINELOGGER.debug("Template has only one provisioner. It will be used as the default value") else: if args.provisioner != None: COMMANDLINELOGGER.debug("A provisioner has been given by the user.") try: provisioner = Provisioner.fromString(args.provisioner)() except: COMMANDLINELOGGER.debug("Given provisioner is not supported by machination.") raise InvalidCmdLineArgument("provisioner", args.provisioner) if provisioner not in template.getProvisioners(): COMMANDLINELOGGER.debug("Given provisioner is not supported by this template.") raise InvalidCmdLineArgument("provisioner", args.provisioner) else: if args.no_interactive == False: COMMANDLINELOGGER.debug("Request a provisioner to the user.") provisioner = Provisioner.fromString( RegexedQuestion( "Select an Provisioner [{0}]".format(",".join(map(str, template.getProvisioners()))), "Provisioner must be from {0}".format(",".join(map(str, template.getProvisioners()))), COMMANDLINELOGGER, "[{0}]".format("\\b|\\b".join(map(str, template.getProvisioners()))), provisioner.name, ).ask() )() else: COMMANDLINELOGGER.debug("Missing provisioner argument") raise InvalidCmdLineArgument("provisioner", args.provisioner) return provisioner
def requestProvisionner(self, args, template): provisioner = template.getProvisioners()[0] # If there is more than one provisioner available for the template if len(template.getProvisioners()) == 1: COMMANDLINELOGGER.debug( "Template has only one provisioner. It will be used as the default value" ) else: if args.provisioner != None: COMMANDLINELOGGER.debug( "A provisioner has been given by the user.") try: provisioner = Provisioner.fromString(args.provisioner)() except: COMMANDLINELOGGER.debug( "Given provisioner is not supported by machination.") raise InvalidCmdLineArgument("provisioner", args.provisioner) if provisioner not in template.getProvisioners(): COMMANDLINELOGGER.debug( "Given provisioner is not supported by this template.") raise InvalidCmdLineArgument("provisioner", args.provisioner) else: if args.no_interactive == False: COMMANDLINELOGGER.debug( "Request a provisioner to the user.") provisioner = Provisioner.fromString( RegexedQuestion( "Select an Provisioner [{0}]".format(",".join( map(str, template.getProvisioners()))), "Provisioner must be from {0}".format(",".join( map(str, template.getProvisioners()))), COMMANDLINELOGGER, "[{0}]".format("\\b|\\b".join( map(str, template.getProvisioners()))), provisioner.name).ask())() else: COMMANDLINELOGGER.debug("Missing provisioner argument") raise InvalidCmdLineArgument("provisioner", args.provisioner) return provisioner
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)