Ejemplo n.º 1
0
  parser = argparse.ArgumentParser()
  parser.add_argument("FQDN", help="FQDN for the new website")
  parser.add_argument("--htmlfile", 
                      help="Local file containing new site's content", 
                      default=False)
  parser.add_argument("--container", 
                      help="CloudFiles container name to create",
                      default=False)
  parser.add_argument("--region", default='DFW',
                      help="Region in which to create site (DFW or ORD)")
  args = parser.parse_args()

  credential_file=os.path.expanduser("~/.rackspace_cloud_credentials")
  pyrax.set_credential_file(credential_file)
  if c1.is_valid_region(args.region, 'object_store'):
    cf = pyrax.connect_to_cloudfiles(region=args.region)
    dns = pyrax.connect_to_cloud_dns(region=args.region)
  else:
    print "The region you requested is not valid: %s" % args.region
    sys.exit(2)

  if not c4.is_valid_hostname(args.FQDN):
    print "This does not appear to be a valid host name: %s" % args.FQDN
    sys.exit(3)

  if args.htmlfile:
    indexFileName = os.path.expanduser(args.htmlfile)
    if os.path.isfile(indexFileName):
      indexFileContents = open(indexFileName, 'r').read()
    else:
Ejemplo n.º 2
0
if __name__ == "__main__":
  print "Challenge2 - Write a script that clones a server (takes an image and"
  print "deploys the image as a new server).\n\n" 

  # unbuffer stdout for pretty output
  sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

  parser = argparse.ArgumentParser()
  parser.add_argument("SourceServer", help="UUID of the server to clone")
  parser.add_argument("--region", default='DFW',
                      help="Region in which to create servers (DFW or ORD)")
  args = parser.parse_args()

  credential_file=os.path.expanduser("~/.rackspace_cloud_credentials")
  pyrax.set_credential_file(credential_file)
  if c1.is_valid_region(args.region, 'compute'):
    cs = pyrax.connect_to_cloudservers(region=args.region)
  else:
    print "The region you requested is not valid: %s" % args.region
    sys.exit(2)

  try:
    cs.servers.find(id=args.SourceServer)
  except:
    print "The source server UUID you specified was not found"
    print "in region %s : %s" % (args.region, args.SourceServer)
    print "Perhaps it is in a different region?"
    print "Aborting...."
    sys.exit(2)

  newserver = clone_server(cs, args.SourceServer);
Ejemplo n.º 3
0
  parser = argparse.ArgumentParser()
  parser.add_argument("Instance", 
                      help="Name of CloudDatabase Instance to create")
  parser.add_argument("Schema", help="Name of database schema to create") 
  parser.add_argument("User", help="Username for database access")
  parser.add_argument("--flavor", default=1, 
                      help="Flavor of CloudDatabase to create")
  parser.add_argument("--volumesize", default=1, type=int,
                      help="Size of database volume (GB)")
  parser.add_argument("--region", default='DFW',
                      help="Region in which to create database (DFW or ORD)")
  args = parser.parse_args()

  credential_file = os.path.expanduser("~/.rackspace_cloud_credentials")
  pyrax.set_credential_file(credential_file)
  if c1.is_valid_region(args.region, 'database'):
    cdb = pyrax.connect_to_cloud_databases(region=args.region)
  else:
    print "The region you requested is not valid: %s" % args.region
    sys.exit(2)

  if not is_valid_db_flavor(cdb, args.flavor):
    print "This is not a valid CloudDatabase flavor-id: %s" % args.flavor
    sys.exit(3)

  if args.volumesize < 1 or args.volumesize > 150:
    print "The requested volume size is not valid: %d" % args.volumesize
    sys.exit(4)

  # unbuffer stdout for pretty output
  sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
Ejemplo n.º 4
0
                      help="Name to give to new Cloud Network")
  parser.add_argument("--networknet", default='192.168.99.0/24',
                      help="CIDR network address to use on new network")
  parser.add_argument("--sslcertfile", default=False,
                      help="File containing ssl certificate")
  parser.add_argument("--sslkeyfile", default=False,
                      help="file containing ssl private key")
  parser.add_argument("--lbname", default=False,
                      help="Name of Loadbalancer to create")
  parser.add_argument("--region", default='DFW',
                      help="Region in which to create devices (DFW or ORD)")
  args = parser.parse_args()

  credential_file=os.path.expanduser("~/.rackspace_cloud_credentials")
  pyrax.set_credential_file(credential_file)
  if (c1.is_valid_region(args.region, 'compute') and
      c1.is_valid_region(args.region, 'load_balancer') and
      c1.is_valid_region(args.region, 'volume')):
    cs = pyrax.connect_to_cloudservers(region=args.region)
    dns = pyrax.connect_to_cloud_dns(region=args.region)
    clb = pyrax.connect_to_cloud_loadbalancers(region=args.region)
    cn = pyrax.connect_to_cloud_networks(region=args.region)
    cbs = pyrax.connect_to_cloud_blockstorage(region=args.region)
  else:
    print "The region you requested is not valid: %s" % args.region
    sys.exit(2)

  if not args.sslcertfile or not args.sslkeyfile:
    print "You didn't supply an SSL certificate and key.",
    print "No worries! We'll create one for you...\n"
    (cert, key) = create_self_signed_cert(args.FQDN) 
Ejemplo n.º 5
0
    print "FQDN, image, and flavor it creates a server of the specified image"
    print "and flavor with the same name as the fqdn, and creates a DNS entry"
    print "for the fqdn pointing to the server's public IP.\n\n"

    parser = argparse.ArgumentParser()
    parser.add_argument("FQDN", help="FQDN for the new CloudServer")
    parser.add_argument(
        "--image", help="Image from which to create server", default="c195ef3b-9195-4474-b6f7-16e5bd86acd0"
    )
    parser.add_argument("--flavor", default=2, help="Flavor of server to create")
    parser.add_argument("--region", default="DFW", help="Region in which to create server (DFW or ORD)")
    args = parser.parse_args()

    credential_file = os.path.expanduser("~/.rackspace_cloud_credentials")
    pyrax.set_credential_file(credential_file)
    if c1.is_valid_region(args.region, "compute"):
        cs = pyrax.connect_to_cloudservers(region=args.region)
        dns = pyrax.connect_to_cloud_dns(region=args.region)
    else:
        print "The region you requested is not valid: %s" % args.region
        sys.exit(2)

    # unbuffer stdout for pretty output
    sys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)

    if not c4.is_valid_hostname(args.FQDN):
        print "This does not appear to be a valid host name: %s" % args.FQDN
        sys.exit(2)
    if not c1.is_valid_image(cs, args.image):
        print "This does not appear to be a valid image-uuid: %s" % args.image
        sys.exit(3)
Ejemplo n.º 6
0
    parser.add_argument("sshkeyfile", help="File containing public ssh-key")
    parser.add_argument("errorpage", help="File containing error page html")
    parser.add_argument(
        "--image", help="Image from which to create servers", default="c195ef3b-9195-4474-b6f7-16e5bd86acd0"
    )
    parser.add_argument("--flavor", default=2, help="Flavor of servers to create")
    parser.add_argument("--numservers", default=2, type=int, help="Number of servers to create")
    parser.add_argument("--lbname", default=False, help="Name of Loadbalancer to create")
    parser.add_argument("--container", default=False, help="Cloudfiles container to copy error page file to")
    parser.add_argument("--region", default="DFW", help="Region in which to create devices (DFW or ORD)")
    args = parser.parse_args()

    credential_file = os.path.expanduser("~/.rackspace_cloud_credentials")
    pyrax.set_credential_file(credential_file)
    if (
        c1.is_valid_region(args.region, "compute")
        and c1.is_valid_region(args.region, "object_store")
        and c1.is_valid_region(args.region, "load_balancer")
    ):
        cs = pyrax.connect_to_cloudservers(region=args.region)
        dns = pyrax.connect_to_cloud_dns(region=args.region)
        clb = pyrax.connect_to_cloud_loadbalancers(region=args.region)
        cf = pyrax.connect_to_cloudfiles(region=args.region)
    else:
        print "The region you requested is not valid: %s" % args.region
        sys.exit(2)

    # unbuffer stdout for pretty output
    sys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)

    sshkeyFile = os.path.expanduser(args.sshkeyfile)
Ejemplo n.º 7
0
    parser.add_argument("--dryrun", action="store_true", help="Do not actually perform deletes")
    parser.add_argument("--all", action="store_true", help="Delete ALL cloud resources in account")
    parser.add_argument("--skipservers", action="store_true", help="Skip the deletion of servers")
    parser.add_argument("--skipimages", action="store_true", help="Skip the deletion of images")
    parser.add_argument("--skipfiles", action="store_true", help="Skip the deletion of cloudfiles")
    parser.add_argument("--skipdatabases", action="store_true", help="Skip the deletion of databases")
    parser.add_argument("--skipnetworks", action="store_true", help="Skip the deletion of networks")
    parser.add_argument("--skipblockstorage", action="store_true", help="Skip the deletion of block storage")
    parser.add_argument("--skipdns", action="store_true", help="Skip the deletion of any DNS")
    parser.add_argument("--skiploadbalancers", action="store_true", help="Skip the deletion of loadbalancers")
    args = parser.parse_args()

    credential_file = os.path.expanduser("~/.rackspace_cloud_credentials")
    pyrax.set_credential_file(credential_file)

    if args.region != "all" and not c1.is_valid_region(args.region, "load_balancer"):
        print "The region you requested is not valid: %s" % args.region
        sys.exit(2)
    if not args.prefix and not args.all:
        print "You must either specify a --prefix OR",
        print "to delete everything specify --all"
        sys.exit(3)
    if args.prefix and args.all:
        print "You cannot specify both a prefix and --all",
        print "If you want to delete everything, do not provide a prefix."
        sys.exit(4)

    if args.region == "all":
        deleteFromRegions = c1.valid_regions("load_balancer")
    else:
        deleteFromRegions = [args.region]