docs: def main(cls, args, settings=None, userdata=None): # pylint: disable=too-many-branches,too-many-statements
          """Main entry point of this module.
          """
          # Packet Configuration
          logger.info('Using Packet configuration from %s', Focus.info(args.conf.name))
          try:
              conf = json.loads(args.conf.read())
          except ValueError as msg:
              logger.error('Unable to parse %s: %s', args.conf.name, msg)
              return 1
  
          # Handle Tags
          if args.tags and (args.create_spot or args.create_demand):
              logger.info('Assigning the following tags to the instance: %r', args.tags)
  
          if args.only:
              try:
                  args.only = UserData.parse_only_criterias(args.only)
              except ValueError:
                  logger.error('-only requires format of: name=value')
                  return 1
              logging.info('Using filter %r to return only matching devices.', args.only)
  
          # Packet Manager
          try:
              cluster = PacketManager(conf)
          except PacketManagerException as msg:
              logger.error(msg)
              return 1
          project = cluster.conf.get('projects').get(args.project)
  
          # List Operations
          if args.list_projects:
              cluster.print_projects(cluster.list_projects())
  
          if args.list_plans:
              cluster.print_plans(cluster.list_plans())
  
          if args.list_spot_prices:
              cluster.print_spot_prices(cluster.list_spot_prices())
  
          if args.list_operating_systems:
              cluster.print_operating_systems(cluster.list_operating_systems())
  
          if args.list_facilities:
              cluster.print_facilities(cluster.list_facilities())
  
          if args.list_devices and args.project:
              cluster.print_devices(cluster.list_devices(project, conditions=args.only))
  
          if args.create_volume:
              if len(args.create_volume) < 4:
                  logger.error('Not enough arguments for creating a volume storage.')
                  return 1
              [plan, size, region, label] = args.create_volume
              try:
                  cluster.create_volume(project, plan, size, region, label)
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          # Device Pre-Checks
          if (args.create_spot or args.create_demand) \
                  and (args.region and args.plan):
              logging.info('Validating requested remote capacities ...')
              try:
                  status = cluster.validate_capacity([
                      [args.region, args.plan, str(args.count)]
                  ])
                  if status:
                      logger.info('Requested capacities are available.')
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          # Device Creation
          if args.create_spot \
                  and args.region \
                  and args.plan \
                  and args.max_spot_price \
                  and args.os:
              try:
                  devices = cluster.create_spot(project_id=project,
                                                facility=args.region,
                                                plan=args.plan,
                                                operating_system=args.os,
                                                spot_price_max=args.max_spot_price,
                                                tags=args.tags,
                                                userdata=userdata,
                                                count=args.count)
                  cluster.print_devices(devices)
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          if args.create_demand \
                  and args.region \
                  and args.plan \
                  and args.os:
              try:
                  devices = cluster.create_demand(project_id=project,
                                                  facility=args.region,
                                                  plan=args.plan,
                                                  tags=args.tags,
                                                  operating_system=args.os,
                                                  userdata=userdata,
                                                  count=args.count)
                  cluster.print_devices(devices)
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          # Device Operations
          if args.reboot:
              try:
                  cluster.reboot(cluster.list_devices(project, conditions=args.only))
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          if args.stop:
              try:
                  cluster.stop(cluster.list_devices(project, conditions=args.only))
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          if args.terminate:
              try:
                  cluster.terminate(cluster.list_devices(project, conditions=args.only))
              except PacketManagerException as msg:
                  logger.error(msg)
                  return 1
  
          return 0