• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyrax.set_default_region函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyrax.set_default_region函数的典型用法代码示例。如果您正苦于以下问题:Python set_default_region函数的具体用法?Python set_default_region怎么用?Python set_default_region使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了set_default_region函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: load

def load(context, path, callback):
    key = (
            context.config.RACKSPACE_PYRAX_REGION, 
            context.config.get('RACKSPACE_PYRAX_IDENTITY_TYPE','rackspace'),
            context.config.RACKSPACE_PYRAX_CFG,
            context.config.RACKSPACE_PYRAX_PUBLIC,
            context.config.RACKSPACE_LOADER_CONTAINER
        )

    if key not in CONNECTIONS:
        if(context.config.RACKSPACE_PYRAX_REGION):
            pyrax.set_default_region(context.config.RACKSPACE_PYRAX_REGION)
        pyrax.set_setting('identity_type', context.config.get('RACKSPACE_PYRAX_IDENTITY_TYPE','rackspace'))
        pyrax.set_credential_file(expanduser(context.config.RACKSPACE_PYRAX_CFG))
        cf = pyrax.connect_to_cloudfiles(public=context.config.RACKSPACE_PYRAX_PUBLIC)
        CONNECTIONS[key] = cf.get_container(context.config.RACKSPACE_LOADER_CONTAINER)

    cont = CONNECTIONS[key]
    file_abspath = normalize_path(context, path)
    logger.debug("[LOADER] getting from %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath))
    try:
        obj = cont.get_object(file_abspath)
        if obj:
            logger.debug("[LOADER] Found object at %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath))
        else:
            logger.warning("[LOADER] Unable to find object %s/%s" % (context.config.RACKSPACE_LOADER_CONTAINER, file_abspath ))
    except:
        callback(None)
    else:
        callback(obj.get())
开发者ID:Superbalist,项目名称:thumbor_rackspace,代码行数:30,代码来源:cloudfiles_loader.py


示例2: rack_creds

def rack_creds():
  pyrax.set_setting("identity_type", "rackspace")
  pyrax.set_default_region("DFW")
  if os.path.isfile(os.path.expanduser("~/.rackspace_cloud_credentials")):
    creds_file = os.path.expanduser("~/.rackspace_cloud_credentials")
    pyrax.set_credential_file(creds_file)
  else:
    print("unable to locate rackspace cloud credentials file")
开发者ID:chorejasbob,项目名称:spinheads,代码行数:8,代码来源:challenge_1.py


示例3: _connect_to_rackspace

 def _connect_to_rackspace(self):
     """ returns a connection object to Rackspace  """
     pyrax.set_setting('identity_type', 'rackspace')
     pyrax.set_default_region(self.state.region)
     pyrax.set_credentials(self.config.access_key_id,
                           self.config.secret_access_key)
     nova = pyrax.connect_to_cloudservers(region=self.state.region)
     return nova
开发者ID:ClusterHQ,项目名称:bookshelf,代码行数:8,代码来源:rackspace.py


示例4: __init__

    def __init__(self, context):
        self.context = context
        if(self.context.config.RACKSPACE_PYRAX_REGION):
            pyrax.set_default_region(self.context.config.RACKSPACE_PYRAX_REGION)

        pyrax.set_credential_file(expanduser(self.context.config.RACKSPACE_PYRAX_CFG))

        self.cloudfiles = pyrax.connect_to_cloudfiles(public=self.context.config.RACKSPACE_PYRAX_PUBLIC)
开发者ID:ettoredn,项目名称:thumbor_rackspace,代码行数:8,代码来源:cloudfile_storage.py


示例5: connect_to_rackspace

def connect_to_rackspace():
    """ returns a connection object to Rackspace  """
    import pyrax

    pyrax.set_setting('identity_type', env.os_auth_system)
    pyrax.set_default_region(env.os_region_name)
    pyrax.set_credentials(env.os_username, env.os_password)
    nova = pyrax.connect_to_cloudservers(region=env.os_region_name)
    return nova
开发者ID:Azulinho,项目名称:fabric-collections,代码行数:9,代码来源:api.py


示例6: connect_to_rackspace

def connect_to_rackspace(region,
                         access_key_id,
                         secret_access_key):
    """ returns a connection object to Rackspace  """
    pyrax.set_setting('identity_type', 'rackspace')
    pyrax.set_default_region(region)
    pyrax.set_credentials(access_key_id, secret_access_key)
    nova = pyrax.connect_to_cloudservers(region=region)
    return nova
开发者ID:ClusterHQ,项目名称:bookshelf,代码行数:9,代码来源:rackspace.py


示例7: __init__

    def __init__(self, region, user_name, api_key, container_name, **kwargs):
        """
        Init adapter
        :param access_key: str
        :param secret_key: str
        :param bucket_name: str
        """
        pyrax.set_setting("identity_type", "rackspace")
        pyrax.set_default_region(region)
        pyrax.set_credentials(user_name, api_key)

        self.cf_conn = pyrax.cloudfiles
        self.container = self.cf_conn.get_container(container_name)

        self.cache_folder = kwargs.get('cache_folder', 'cache').strip('/')
开发者ID:FlaskGuys,项目名称:Flask-Imagine-RackspaceAdapter,代码行数:15,代码来源:__init__.py


示例8: main

def main():
    parser = argparse.ArgumentParser(description="Rackspace server creation/deletion")
    parser.add_argument("action", choices=['create', 'delete'], help='Action to be perfromed')
    parser.add_argument("-n", "--count", help='Number of machines')
    parser.add_argument("--region", help='Region to launch the machines', default='ORD')
    args = parser.parse_args()
    count = args.count
    region = args.region

    # configuration of cloud service provider
    pyrax.set_setting('identity_type', 'rackspace')
    pyrax.set_default_region(region)
    pyrax.set_credentials(os.environ.get('USERNAME'),os.environ.get('PASSWORD'))
    nova_obj = pyrax.cloudservers

    if (args.action == 'create'):
        create_node(nova_obj, count)
    elif (args.action == 'delete'):
        delete_node(nova_obj)
开发者ID:gluster,项目名称:glusterfs-patch-acceptance-tests,代码行数:19,代码来源:rackspace-server-manager.py


示例9: __init__

    def __init__(self, document_url, document_hash, cloudfiles_location=None):
        self.document_url = document_url
        self.document_hash = document_hash

        if cloudfiles_location is None:
            cloudfiles_location = CLOUDFILES_DEFAULT_REGION

        pyrax.set_default_region(cloudfiles_location)
        pyrax.set_credentials(CLOUDFILES_USERNAME, CLOUDFILES_API_KEY,
                              region=cloudfiles_location)
        self.paths = {}

        self.client = pyrax.connect_to_cloudfiles(
            cloudfiles_location, public=not CLOUDFILES_SERVICENET)
        if self.client is None:
            err_msg = ('Error during connection to cloudfiles, region {0} is'
                       ' likely to be wrong.'.format(cloudfiles_location))
            raise PreviewException(err_msg)
        self.container = self.client.create_container(CLOUDFILES_COUNTAINER)
开发者ID:peopledoc,项目名称:insight-reloaded,代码行数:19,代码来源:cloudfiles.py


示例10: _get_client

    def _get_client(self):
        username = self.config['username']
        api_key = self.config['api_key']

        # Needs to be extracted to per-action
        region = self.config['region'].upper()

        pyrax.set_setting('identity_type', 'rackspace')
        pyrax.set_default_region(region)
        pyrax.set_credentials(username, api_key)

        debug = self.config.get('debug', False)
        if debug:
            pyrax.set_http_debug(True)

        pyrax.cloudservers = pyrax.connect_to_cloudservers(region=region)
        pyrax.cloud_loadbalancers = pyrax.connect_to_cloud_loadbalancers(region=region)
        pyrax.cloud_dns = pyrax.connect_to_cloud_dns(region=region)

        return pyrax
开发者ID:AlexeyDeyneko,项目名称:st2contrib,代码行数:20,代码来源:action.py


示例11: print

server_id = srv_dict[selection]
print()
nm = raw_input("Enter a name for the image: ")

img_id = cs.servers.create_image(server_id, nm)

print("Image '%s' is being created. Its ID is: %s" % (nm, img_id))
img = pyrax.cloudservers.images.get(img_id)
while img.status != "ACTIVE":
     time.sleep(60)
     img = pyrax.cloudservers.images.get(img_id)
     print ("...still waiting")

print("Image created.")

pyrax.set_default_region("DFW")
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credential_file("/root/.rackspace_cloud_credentials")

cf_dfw = pyrax.connect_to_cloudfiles("DFW")

cont = cf_dfw.create_container("Export")

cf_dfw.make_container_public("Export", ttl=900)

pyrax.set_default_region("IAD")

cf_iad = pyrax.connect_to_cloudfiles("IAD")

cont = cf_iad.create_container("Import")
cf_iad.make_container_public("Import", ttl=900)
开发者ID:shterrel,项目名称:Pyrax-Dev,代码行数:31,代码来源:create_image-export.py


示例12: ID

import pyrax, time, uuid

# RAX account info
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region('IAD')
pyrax.set_credentials(os.environ['RAX_ID'], os.environ['RAX_KEY'])	

#assign generated client ID (see authentication section)
MY_CLIENT_ID = str(uuid.uuid4())

while True:
	# Connect to RAX Cloud Queues
	pyrax.queues.client_id = MY_CLIENT_ID
	queue = pyrax.queues.get("sample_queue")
	msg_body = "Generated at: %s" % time.strftime("%c")
	queue.post_message(msg_body, ttl=300)
	print msg_body
	time.sleep(5)
开发者ID:keithhigbee,项目名称:mesos-scratch,代码行数:18,代码来源:msg-generator-envs.py


示例13: len

#ARG parsing
if len(sys.argv[1:]) == 2 :
	index_file_path, container_name = sys.argv[1:]
else:
	usage()

#Validations
if not os.access(index_file_path, os.F_OK):
	sys.exit("Path non existent. Please verify the index file path : " + index_file)

file_name=string.rsplit(index_file_path,'/',1)[-1]

	
##Auth	
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region('SYD')
pyrax.set_credentials('denzelfernando', 'blah')

#cloud file handler
cf = pyrax.cloudfiles

#create the container (will create if does not exist
container = cf.create_container(container_name)

#Make CDN
container.make_public(ttl=900)

#Set meta data (set the uploaded file name as the index)
#X-Container-Meta-Web-Index
container.set_metadata({'Web-Index' : file_name},clear = False, prefix = None)
开发者ID:denzelfernando,项目名称:rax,代码行数:30,代码来源:ch8.py


示例14: main

def main():

    # Parse the command line arguments
    parser = argparse.ArgumentParser(
        description="Image a server and create a clone from the image",
        prog='cs_create_image_and_clone_server.py')
    parser.add_argument(
        '--region', help='Region(default: DFW)', default='DFW')
    parser.add_argument(
        '--flavor',
        help='flavor id or name (default: original server flavor)')
    parser.add_argument(
        '--server_name', help='Server name to create image from',
        required=True)
    parser.add_argument(
        '--image_name', help='Name of new image',
        required=True)
    parser.add_argument(
        '--clone_name', help='Name of your new clone created from image',
        required=True)
    args = parser.parse_args()

    # Set the region
    pyrax.set_default_region(args.region)

    # Authenticate using a credentials file: "~/.rackspace_cloud_credentials"
    cred_file = "%s/.rackspace_cloud_credentials" % (os.environ['HOME'])
    print "Setting authentication file to %s" % (cred_file)
    pyrax.set_credential_file(cred_file)

    # Instantiate a cloudservers object
    print "Instantiating cloudservers object"
    csobj = pyrax.cloudservers

    # Get the server id
    servers = csobj.servers.list()
    found = 0
    for server in servers:
        if server.name == args.server_name:
            found = 1
            curserver = server

    if not found:
        print "Server by the name of " + args.server_name + \
              " doesn't exist"
        sys.exit(1)

    # Get the flavor id
    if args.flavor:
        flavor_id = get_flavor_id(csobj, args.flavor)
        print "Using flavor id of " + flavor_id + \
              " from provided arg of " + args.flavor
    else:
        flavor_id = curserver.flavor['id']
        print "Using flavor id of " + flavor_id + " from orig server"

    # Create an image of the original server
    image_obj = create_image_from_server(csobj, curserver.id,
                                         args.image_name)

    # Wait for active image
    wait_for_active_image(csobj, image_obj.id)

    # Create a new server from the image just created
    cloned_server = create_server(csobj, args.clone_name, flavor_id,
                                  image_obj.id)

    # Wait for the server to complete and get data
    print "Wating on clone to finish building\n"
    updated_cloned_server = pyrax.utils.wait_until(cloned_server, "status",
                                                   ["ACTIVE", "ERROR"],
                                                   attempts=0)

    # Print the data
    print_server_data(image_obj, updated_cloned_server,
                      cloned_server.adminPass)
开发者ID:javiergayala,项目名称:cloud_code_samples,代码行数:76,代码来源:cs_create_image_and_clone_server.py


示例15: main

def main():

    # Parse the command line arguments
    parser = argparse.ArgumentParser(
        description="Create Multiple Webheads",
        prog='cf_create_multiple_webheads.py')
    parser.add_argument(
        '--image', help='image id or name (default: CentOS 6.3)',
        default='CentOS 6.3')
    parser.add_argument(
        '--flavor',
        help='flavor id or name (default: 512MB Standard Instance)',
        default='512MB Standard Instance')
    parser.add_argument(
        '--webhead_count', help='Number of webheads to create(default: 3)',
        default=3)
    parser.add_argument(
        '--webhead_prefix', help='webhead prefix(default: web)',
        default='web')
    parser.add_argument(
        '--region', help='Region(default: DFW)', default='DFW')
    args = parser.parse_args()

    # Set the region
    pyrax.set_default_region(args.region)

    # Server Data Dictionary
    server_data = dict()

    # Authenticate using a credentials file: "~/.rackspace_cloud_credentials"
    cred_file = "%s/.rackspace_cloud_credentials" % (os.environ['HOME'])
    print "Setting authentication file to %s" % (cred_file)
    pyrax.set_credential_file(cred_file)

    # Instantiate a cloudservers object
    print "Instantiating cloudservers object"
    csobj = pyrax.cloudservers

    # Get the flavor id
    flavor_id = get_flavor_id(csobj, args.flavor)

    # Get the image id
    image_id = get_image_id(csobj, args.image)

    # Create the servers by server_count
    for webhead_num in range(1, args.webhead_count + 1):
        webhead_name = "%s%d" % (args.webhead_prefix, webhead_num)
        new_server = create_webhead(csobj, webhead_name, flavor_id, image_id)
        try:
            new_server.adminPass
        except AttributeError:
            print "%s existed, so password can't be pulled" % (webhead_name)
            server_data[webhead_name] = {'password': 'not_available',
                                         'ipaddr': '0',
                                         'id': new_server.id}
        else:
            print new_server.adminPass
            server_data[webhead_name] = {'password': new_server.adminPass,
                                         'ipaddr': '0',
                                         'id': new_server.id}

    # Call function to wait on ip addresses to be assigned and
    # update server_data
    updated_server_data = wait_and_update(csobj, server_data)

    # Print the data
    print_server_data(updated_server_data)
开发者ID:javiergayala,项目名称:cloud_code_samples,代码行数:67,代码来源:cs_create_multiple_webheads.py


示例16:

parser.add_argument('--loadbalancer', '-l', dest='loadbalancer', required=True,
                    help='loadbalancer to edit.')
parser.add_argument('--ip_address', '-i', dest="ip", required=True,
                    help='ip address to add.')
parser.add_argument('--region', '-r', dest="region", required=True,
                    help='The rackspace region for the the request.')
parser.add_argument('--username', '-u', dest="username", required=True,
                    help='Rackspace Username.')
parser.add_argument('--api-key', '-k', dest="api_key", required=True,
                    help='Rackspace API Key.')
parser.add_argument('--remove', '-d', dest="remove", action='store_true',
                    help='remove the specified node from the loadbalancer.')
args = parser.parse_args()

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region(args.region)
pyrax.set_credentials(
    args.username,
    args.api_key
)

clb = pyrax.connect_to_cloud_loadbalancers(args.region.upper())

lb = clb.get(args.loadbalancer)
if args.remove:
    try:
        node = [node for node in lb.nodes
                if node.address == args.ip]
        node.delete()
    except Exception as e:
        msg = "Failed to remove instance {0} from LB {1}: {2}"
开发者ID:donthack-me,项目名称:donthackme_scripts,代码行数:31,代码来源:lb_add_remove.py


示例17: spinup

import ConfigParser
import pyrax
import time
import datetime

settings = ConfigParser.ConfigParser()
settings.read('.spinconfig')

# set defaults for execution
username = settings.get('credentials', 'RAX_USERNAME')
apikey = settings.get('credentials', 'RAX_API_KEY')
datacenter = settings.get('credentials', 'RAX_REGION')

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region(datacenter)
pyrax.set_credentials(username, apikey)

cs = pyrax.cloudservers

# define spinup() function

def spinup():
	imgs = cs.images.list()
	for img in imgs:
	    print img.name, " -- ID:", img.id

	print "\nWhat is the ID of the image you want to spin up from?\n"
	image_name = raw_input("ID: ")

	flvs = cs.list_flavors()
	for flv in flvs:
开发者ID:moderndynamo,项目名称:spinupdown.py,代码行数:31,代码来源:spinupdown.py


示例18:

# Create compute node
import pyrax

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region('{region}')
pyrax.set_credentials(file)

cs = pyrax.cloudservers

image = pyrax.images.get('88928a0a-f94c-47e3-ad7d-27b735af1a15')

flavor = cs.flavors.get('performance2-30')

server = cs.servers.create('transcoder', image.id, flavor.id)

pyrax.utils.wait_for_build(server, verbose=True)

# Build script to Install HandbrakeCLI

pacman -Sy handbrake-cli --no-prompt

# Delete node
开发者ID:Alibloke,项目名称:beetlejuice,代码行数:22,代码来源:compute.py


示例19: setUp

 def setUp(self):
     pyrax.set_setting('identity_type', 'rackspace')
     pyrax.set_default_region(RACKSPACE_REGION)
     pyrax.set_credentials(RACKSPACE_USERNAME, RACKSPACE_API_KEY)
     self.container = pyrax.cloudfiles.create_container(self.container_name)
     self.container.delete_all_objects()
开发者ID:boilerroomtv,项目名称:datastore.cloudfiles,代码行数:6,代码来源:test.py


示例20: handle

    def handle(self, *args, **options):
        pyrax.set_setting("identity_type", "rackspace")
        pyrax.set_default_region('DFW')
        account = options["account"] or get_config('rackspace', 'username')
        api_key = options["api_key"] or get_config('rackspace', 'api_key')

        if not account:
            print("Please provide your username by using --account or in DEPLOY_CONFIG['rackspace']['username']")
            return

        if not api_key:
            print("Please provide your username by using --api-key or in DEPLOY_CONFIG['rackspace']['api_key']")
            return

        pyrax.set_credentials(account, api_key)

        server_name = options["server"]
        if not server_name:
            print("Please provide a server name with --server")
            return

        print("Contacting Rackspace")
        cs = pyrax.cloudservers
        servers = cs.list()

        for server in servers:
            if server.name == server_name:
                print("Nothing to do, %s already exists" % server_name)
                return 

        # Create the server
        default_image = options["image"] or get_config('rackspace', 'default_image')
        default_flavor = options["flavor"] or get_config('rackspace', 'default_flavor')

        if not default_image:
            print "Select an image"
            images = sorted(cs.list_images(), key=lambda image: image.name)
            for i in range(len(images)):
                image = images[i]
                print " %s. %s (%s)" % (i+1, image.name, image.id)

            selected_image_index = input("Which image should we build? ")
            selected_image = images[selected_image_index - 1]

            print("")
            print("Will build image: %s" % selected_image.name)
            print("")
        else:
            selected_image = cs.images.get(default_image)

        if not default_flavor:
            print "Select flavor"
            flavors = sorted(cs.list_flavors(), key=lambda flavor: flavor.name)

            for i in range(len(flavors)):
                flavor = flavors[i]
                print " %s. %s (%s)" % (i+1, flavor.name, flavor.id)

            selected_flavor_index = input("Which flavor should we build? ")
            selected_flavor = flavors[selected_flavor_index - 1]

            print("")
            print("Will build flavor: %s" % selected_flavor.name)
            print("")
        else:
            selected_flavor = cs.flavors.get(default_flavor)


        confirmation = unicode(raw_input("Go ahead and build %s %s? [Y/n] " % (selected_image.name, selected_flavor.name))) or ""
        if confirmation.lower() in ["n", "no"]:
            print("Exiting ...")
            return

        print("")
        print("............................")
        print("Building the server")
        server = cs.servers.create(server_name, selected_image.id, selected_flavor.id, 
            key=api_key)
        admin_psw = server.adminPass
        pyrax.utils.wait_for_build(server)

        print("Server is ready!")
        server = cs.servers.get(server.id)
        ips = [ ip for ip in server.networks.get("public") if ip.count(".") == 3 ]
        ip = ips[0]

        print("Writing credentials file")
        # write it to a file 
        self.save_credentials(server_name, "root", admin_psw, ip)

        print("All done")
开发者ID:codedbyjay,项目名称:django-deployment,代码行数:91,代码来源:create_rackspace_server.py



注:本文中的pyrax.set_default_region函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyrax.set_setting函数代码示例发布时间:2022-05-27
下一篇:
Python pyrax.set_credentials函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap