Пример #1
0
 def requestProvider(self, args, template):
     provider = template.getProviders()[0]
     # If there is more than one provider available for the template
     if len(template.getProviders()) == 1:
         COMMANDLINELOGGER.debug(
             "Template has only one providers. It will be used as the default value"
         )
     else:
         if args.provider != None:
             try:
                 provider = Provider.fromString(args.provider)()
             except:
                 raise InvalidCmdLineArgument("provider", args.provider)
         else:
             if args.no_interactive == False:
                 provider = Provider.fromString(
                     RegexedQuestion(
                         "Select a Provider [{0}]".format(",".join(
                             map(str, template.getProviders()))),
                         "Provider must be from {0}".format(",".join(
                             map(str, template.getProviders()))),
                         COMMANDLINELOGGER, "[{0}]".format("\\b|\\b".join(
                             map(str, template.getProviders()))),
                         str(template.getProviders()[0])).ask())()
             else:
                 COMMANDLINELOGGER.debug("Missing provider argument")
                 raise InvalidCmdLineArgument("provider", args.provider)
     return provider
Пример #2
0
 def requestProvider(self, args, template):
     provider = template.getProviders()[0]
     # If there is more than one provider available for the template
     if len(template.getProviders()) == 1:
         COMMANDLINELOGGER.debug("Template has only one providers. It will be used as the default value")
     else:
         if args.provider != None:
             try:
                 provider = Provider.fromString(args.provider)()
             except:
                 raise InvalidCmdLineArgument("provider", args.provider)
         else:
             if args.no_interactive == False:
                 provider = Provider.fromString(
                     RegexedQuestion(
                         "Select a Provider [{0}]".format(",".join(map(str, template.getProviders()))),
                         "Provider must be from {0}".format(",".join(map(str, template.getProviders()))),
                         COMMANDLINELOGGER,
                         "[{0}]".format("\\b|\\b".join(map(str, template.getProviders()))),
                         str(template.getProviders()[0]),
                     ).ask()
                 )()
             else:
                 COMMANDLINELOGGER.debug("Missing provider argument")
                 raise InvalidCmdLineArgument("provider", args.provider)
     return provider
Пример #3
0
    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)
Пример #4
0
    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)