Example #1
0
def setup():
    default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')

    env = get_config(p, 'rax', 'environment', 'RAX_ENV', None)
    if env:
        pyrax.set_environment(env)

    keyring_username = pyrax.get_setting('keyring_username')

    # Attempt to grab credentials from environment first
    creds_file = get_config(p, 'rax', 'creds_file', 'RAX_CREDS_FILE', None)
    if creds_file is not None:
        creds_file = os.path.expanduser(creds_file)
    else:
        # But if that fails, use the default location of
        # ~/.rackspace_cloud_credentials
        if os.path.isfile(default_creds_file):
            creds_file = default_creds_file
        elif not keyring_username:
            sys.stderr.write('No value in environment variable %s and/or no '
                             'credentials file at %s\n' %
                             ('RAX_CREDS_FILE', default_creds_file))
            sys.exit(1)

    identity_type = pyrax.get_setting('identity_type')
    pyrax.set_setting('identity_type', identity_type or 'rackspace')

    region = pyrax.get_setting('region')

    try:
        if keyring_username:
            pyrax.keyring_auth(keyring_username, region=region)
        else:
            pyrax.set_credential_file(creds_file, region=region)
    except Exception as e:
        sys.stderr.write("%s: %s\n" % (e, e.message))
        sys.exit(1)

    regions = []
    if region:
        regions.append(region)
    else:
        region_list = get_config(p,
                                 'rax',
                                 'regions',
                                 'RAX_REGION',
                                 'all',
                                 islist=True)
        for region in region_list:
            region = region.strip().upper()
            if region == 'ALL':
                regions = pyrax.regions
                break
            elif region not in pyrax.regions:
                sys.stderr.write('Unsupported region %s' % region)
                sys.exit(1)
            elif region not in regions:
                regions.append(region)

    return regions
Example #2
0
 def test_keyring_auth(self):
     class FakeKeyring(object):
         pass
     fake_keyring = FakeKeyring()
     pyrax.keyring = fake_keyring
     fake_keyring.get_password = Mock(return_value="fakeapikey")
     pyrax.keyring_username = "******"
     pyrax.keyring_auth()
     self.assertTrue(pyrax.identity.authenticated)
Example #3
0
def setup():
    default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')

    env = get_config(p, 'rax', 'environment', 'RAX_ENV', None)
    if env:
        pyrax.set_environment(env)

    keyring_username = pyrax.get_setting('keyring_username')

    # Attempt to grab credentials from environment first
    creds_file = get_config(p, 'rax', 'creds_file',
                            'RAX_CREDS_FILE', None)
    if creds_file is not None:
        creds_file = os.path.expanduser(creds_file)
    else:
        # But if that fails, use the default location of
        # ~/.rackspace_cloud_credentials
        if os.path.isfile(default_creds_file):
            creds_file = default_creds_file
        elif not keyring_username:
            sys.stderr.write('No value in environment variable %s and/or no '
                             'credentials file at %s\n'
                             % ('RAX_CREDS_FILE', default_creds_file))
            sys.exit(1)

    identity_type = pyrax.get_setting('identity_type')
    pyrax.set_setting('identity_type', identity_type or 'rackspace')

    region = pyrax.get_setting('region')

    try:
        if keyring_username:
            pyrax.keyring_auth(keyring_username, region=region)
        else:
            pyrax.set_credential_file(creds_file, region=region)
    except Exception as e:
        sys.stderr.write("%s: %s\n" % (e, e.message))
        sys.exit(1)

    regions = []
    if region:
        regions.append(region)
    else:
        region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all',
                                 islist=True)
        for region in region_list:
            region = region.strip().upper()
            if region == 'ALL':
                regions = pyrax.regions
                break
            elif region not in pyrax.regions:
                sys.stderr.write('Unsupported region %s' % region)
                sys.exit(1)
            elif region not in regions:
                regions.append(region)

    return regions
Example #4
0
 def test_keyring_auth(self):
     class FakeKeyring(object):
         pass
     fake_keyring = FakeKeyring()
     pyrax.keyring = fake_keyring
     fake_keyring.get_password = Mock(return_value="fakeapikey")
     pyrax.keyring_username = "******"
     pyrax.keyring_auth()
     self.assertTrue(pyrax.identity.authenticated)
Example #5
0
 def auth(self, region):
     # Make sure that keyring has been set up with the account credentials.
     print("Authenticating for region '%s'..." % region)
     try:
         pyrax.keyring_auth(region=region)
         print("Success!")
     except Exception as e:
         print("FAIL!", e)
         self.failures.append("AUTHENTICATION")
     print()
Example #6
0
 def auth(self, region):
     # Make sure that keyring has been set up with the account credentials.
     print "Authenticating for region '%s'..." % region
     try:
         pyrax.keyring_auth(region=region)
         print "Success!"
     except Exception as e:
         print "FAIL!", e
         self.failures.append("AUTHENTICATION")
     print
Example #7
0
    def __init__(self, db):
        self.db = db

        pyrax.set_setting('identity_type', 'rackspace')
        pyrax.keyring_auth('rackervision')
        pyrax.queues.client_id = _generate_id()

        self.unprocessed_container = pyrax.cloudfiles.get_container("unprocessed")
        self.processed_container = pyrax.cloudfiles.get_container("processed")
        self.queue = pyrax.queues.get("unprocessed")
Example #8
0
def setup_api(api_key, username):
    """
    Setups up the pyrax API with the information required to connect.
    :param api_key: API Key to connect with
    :param username: Username to connect with
    """
    pyrax.set_setting("identity_type", "rackspace")
    keyring.set_password("pyrax", username, api_key)
    print("Authenticating with {username} using API Key".format(
        username=username))
    pyrax.set_setting("identity_type", "rackspace")
    pyrax.set_setting('region', 'LON')
    pyrax.keyring_auth(username)

    # Using keychain with username set in configuration file
    pyrax.keyring_auth(username=username)
Example #9
0
def setup():
    default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')

    env = get_config(p, 'rax', 'environment', 'RAX_ENV', None)
    if env:
        pyrax.set_environment(env)

    keyring_username = pyrax.get_setting('keyring_username')

    # Attempt to grab credentials from environment first
    creds_file = get_config(p, 'rax', 'creds_file',
                            'RAX_CREDS_FILE', None)
    if creds_file is not None:
        creds_file = os.path.expanduser(creds_file)
    else:
        # But if that fails, use the default location of
        # ~/.rackspace_cloud_credentials
        if os.path.isfile(default_creds_file):
            creds_file = default_creds_file
        elif not keyring_username:
            sys.stderr.write('No value in environment variable %s and/or no '
                             'credentials file at %s\n'
                             % ('RAX_CREDS_FILE', default_creds_file))
            sys.exit(1)

    identity_type = pyrax.get_setting('identity_type')
    pyrax.set_setting('identity_type', identity_type or 'rackspace')

    region = pyrax.get_setting('region')

    try:
        if keyring_username:
            pyrax.keyring_auth(keyring_username, region=region)
        else:
            pyrax.set_credential_file(creds_file, region=region)
    except Exception, e:
        sys.stderr.write("%s: %s\n" % (e, e.message))
        sys.exit(1)
Example #10
0
#!/usr/bin/python

'''
Challenge 4: Write a script that uses Cloud DNS to create a new A record
when passed a FQDN and IP address as arguments.
INCOMPLETE
'''

import sys
import pyrax


# SETUP our creds, note this expects your keyring to be setup
pyrax.keyring_auth()
dns = pyrax.cloud_dns

# DNS default adjustment
dns.set_timeout(30)
dns.set_delay(1)

# ERROR if not enough arguments supplied
if len(sys.argv) < 3:
    print '''
    Usage: {0} [FQDN] [IP]

    This script will create a new A record based on the supplied
    FQDN and IP.

    '''.format(sys.argv[0])
    exit()
Example #11
0
  --flavor=<size>     Size of the instance. [default: 512MB]
  --image=<name>      Name of an image to use. [default: CentOS 6.4]
  --public_key=<key>  Path to your SSH public key. [default: ~/.ssh/id_rsa.pub]
  --region=<name>     Region to build in. [default: DFW]
  --tag=<tag>         Tag to append to server's metadata.
  --username=<name>   Keyring username for authentication.

"""
from docopt import docopt
from os.path import expanduser
import pyrax

args = docopt(__doc__, help = True)

pyrax.set_setting('identity_type', 'rackspace')
pyrax.keyring_auth(args['--username'])
cs = pyrax.connect_to_cloudservers(region = args['--region'])

public_key = {'/root/.ssh/authorized_keys': open(expanduser(args['--public_key']))}

image = next(img for img in cs.images.list() if args['--image'] in img.name)
flavor = next(flv for flv in cs.flavors.list() if args['--flavor'] in flv.name)

request = cs.servers.create(args['<name>'], image.id, flavor.id,
  files = public_key)
build = pyrax.utils.wait_for_build(request, verbose=True)
server = cs.servers.get(build.id)

public_ipv4 = next(addr for addr in server.networks['public'] if '.' in addr)

print "--"
Example #12
0
        if os.path.isfile(default_creds_file):
            creds_file = default_creds_file
        elif not keyring_username:
            sys.stderr.write('No value in environment variable %s and/or no '
                             'credentials file at %s\n'
                             % (e.message, default_creds_file))
            sys.exit(1)

    identity_type = pyrax.get_setting('identity_type')
    pyrax.set_setting('identity_type', identity_type or 'rackspace')

    region = pyrax.get_setting('region')

    try:
        if keyring_username:
            pyrax.keyring_auth(keyring_username, region=region)
        else:
            pyrax.set_credential_file(creds_file, region=region)
    except Exception, e:
        sys.stderr.write("%s: %s\n" % (e, e.message))
        sys.exit(1)

    regions = []
    if region:
        regions.append(region)
    else:
        for region in os.getenv('RAX_REGION', 'all').split(','):
            region = region.strip().upper()
            if region == 'ALL':
                regions = pyrax.regions
                break
Example #13
0
        if os.path.isfile(default_creds_file):
            creds_file = default_creds_file
        elif not keyring_username:
            sys.stderr.write('No value in environment variable %s and/or no '
                             'credentials file at %s\n'
                             % (e.message, default_creds_file))
            sys.exit(1)

    identity_type = pyrax.get_setting('identity_type')
    pyrax.set_setting('identity_type', identity_type or 'rackspace')

    region = pyrax.get_setting('region')

    try:
        if keyring_username:
            pyrax.keyring_auth(keyring_username, region=region)
        else:
            pyrax.set_credential_file(creds_file, region=region)
    except Exception, e:
        sys.stderr.write("%s: %s\n" % (e, e.message))
        sys.exit(1)

    regions = []
    if region:
        regions.append(region)
    else:
        for region in os.getenv('RAX_REGION', 'all').split(','):
            region = region.strip().upper()
            if region == 'ALL':
                regions = pyrax.regions
                break
Example #14
0
    parser.add_argument(
        "--regions",
        "-r",
        action="append",
        help="""Regions to run tests against. Can be specified multiple
            times. If not specified, the default of pyrax.regions will be
            used.""")
    parser.add_argument("--env",
                        "-e",
                        help="""Configuration environment to
            use for the test. If not specified, the `default` environment is
            used.""")
    args = parser.parse_args()
    regions = args.regions
    if not regions:
        pyrax.keyring_auth()
        regions = pyrax.regions
    env = args.env
    if env:
        pyrax.set_environment(env)

    start = time.time()
    pyrax.keyring_auth()
    for region in regions:
        print()
        print("=" * 77)
        print("Starting test for region: %s" % region)
        print("=" * 77)
        smoke_tester = SmokeTester(region)
        try:
            smoke_tester.run_tests()
Example #15
0
  --flavor=<size>     Size of the instance. [default: 512MB]
  --image=<name>      Name of an image to use. [default: CentOS 6.4]
  --public_key=<key>  Path to your SSH public key. [default: ~/.ssh/id_rsa.pub]
  --region=<name>     Region to build in. [default: DFW]
  --tag=<tag>         Tag to append to server's metadata.
  --username=<name>   Keyring username for authentication.

"""
from docopt import docopt
from os.path import expanduser
import pyrax

args = docopt(__doc__, help=True)

pyrax.set_setting('identity_type', 'rackspace')
pyrax.keyring_auth(args['--username'])
cs = pyrax.connect_to_cloudservers(region=args['--region'])

public_key = {
    '/root/.ssh/authorized_keys': open(expanduser(args['--public_key']))
}

image = next(img for img in cs.images.list() if args['--image'] in img.name)
flavor = next(flv for flv in cs.flavors.list() if args['--flavor'] in flv.name)

request = cs.servers.create(args['<name>'],
                            image.id,
                            flavor.id,
                            files=public_key)
build = pyrax.utils.wait_for_build(request, verbose=True)
server = cs.servers.get(build.id)
Example #16
0
 def connect(self, client_id):
     pyrax.keyring_auth()
     pyrax.queues.client_id = client_id