本文整理汇总了Python中pyrax.set_default_region函数的典型用法代码示例。如果您正苦于以下问题:Python set_default_region函数的具体用法?Python set_default_region怎么用?Python set_default_region使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_default_region函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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())
示例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")
示例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
示例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)
示例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
示例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
示例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('/')
示例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)
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)