本文整理汇总了Python中pyrax.connect_to_cloudservers函数的典型用法代码示例。如果您正苦于以下问题:Python connect_to_cloudservers函数的具体用法?Python connect_to_cloudservers怎么用?Python connect_to_cloudservers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect_to_cloudservers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_current_server_networks
def set_current_server_networks(self):
cs_dfw = pyrax.connect_to_cloudservers(region="ORD")
cs_ord = pyrax.connect_to_cloudservers(region="DFW")
dfw_servers = cs_dfw.servers.list()
ord_servers = cs_ord.servers.list()
self.servers = dfw_servers + ord_servers
for server in self.servers:
if server.name == self.server_name:
self.network = server.networks
示例2: get_servers
def get_servers(location = 'all'):
region_list = {}
if location == 'all':
for temp_reg in pyrax.regions:
for server in pyrax.connect_to_cloudservers(region=temp_reg).servers.list():
region_list[server.name] = [ server.name, server.id, server.status, temp_reg ]
else:
for server in pyrax.connect_to_cloudservers(region=location).servers.list():
region_list[server.name] = [ server.name, server.id, server.status, location ]
return region_list
示例3: build_server
def build_server(build_queue):
# create list of server information to keep each build contained to it's own thread
build_details = []
try:
print "Getting job from queue..."
server_name = build_queue.get()
if ssh_auth == "y":
print "Connecting to cloud to build server %s" % server_name
server = pyrax.connect_to_cloudservers(region=region).servers.create(server_name, server_id, server_flv_id, ssh_auth)
print "%s has started building" % server_name
#pass
else:
server = pyrax.connect_to_cloudservers(region=region).servers.create(server_name, server_id, server_flv_id)
#pass
build_details.append(breakpoint)
build_details.append("Name: " + server.name)
build_details.append("ID: " + server.id)
build_details.append("Region: " + region)
build_details.append("Admin Password: " + server.adminPass)
if wait_for_build == True:
try:
#Pass tuple of server status, not list
#pyrax.utils.wait_until(server, "status", ["ACTIVE", "ERROR"], interval=5, callback=None, attempts=0, verbose=False, verbose_atts="progress")
pyrax.utils.wait_until(server, 'status', ('ACTIVE', 'ERROR'), interval=5, attempts=wait_timeout/5)
build_details.append("Network information:")
for i in server.networks.get(u'public'):
build_details.append("Public IP: " + i)
#build_details.append("Public IP: " + server.networks.get(u'public')[0])
build_details.append("Private IP: " + server.networks.get(u'private')[0])
except:
print "Pyrax wait for build unsuccessful. Please reference your cloud panel for server IP's"
print breakpoint
server_info.write(breakpoint)
for info in build_details:
print info
server_info.write(info + "\n")
print breakpoint
server_info.write(breakpoint)
#server_info.write(build_details)
#print build_details
build_queue.task_done()
print "%s has finished, ending thread" % server_name
except nexc.BadRequest as e:
print "Bad image/flavor combination. Please try again. (wah wah wah)\n"
exit()
示例4: listservers
def listservers():
'''Print out servers in account'''
auth()
fields = ['Name', 'DC', 'Status', 'Date Created', 'Server ID']
servdata = []
dfwservers = pyrax.connect_to_cloudservers(region='DFW')
ordservers = pyrax.connect_to_cloudservers(region='ORD')
for server in dfwservers.servers.list():
servdata.append((server.name, 'DFW', server.status, server.created,
server.id))
for server in ordservers.servers.list():
servdata.append((server.name, 'ORD', server.status, server.created,
server.id))
printhortable(fields, servdata)
示例5: minions_up
def minions_up(key_name, credential_file="~/.rackspace_cloud_credentials",
layout=default_layout, region="IAD"):
'''
Creates a specific build of machines and bootstraps salt.
The credential file can be set via keyword credential_file, and defaults
to ~/.rackspace_cloud_credentials
'''
# Authenticate with Rackspace, use credential file
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credential_file(os.path.expanduser(credential_file))
# Shorthand
cs = pyrax.connect_to_cloudservers(region=region)
minions = []
for minion in layout["minions"]:
minions.append(cs.servers.create(minion["hostname"],
minion["image"],
minion["flavor"],
key_name=key_name))
# Make sure all the minions are done before we move on to fabric runs
minions = [pyrax.utils.wait_for_build(minion, verbose=True)
for minion in minions]
env.hosts = [str(minion.accessIPv4) for minion in minions]
print(env.hosts)
示例6: __init__
def __init__(self, task_kwargs=None, json_config_file=None):
json_config_file = json_config_file or './deploy_settings.json'
self.cloudservers = None
self.settings = AttributeDict({})
self.fabric_env_servers = []
self.created_servers = []
task_kwargs = task_kwargs or {}
settings = self.read_settings_file(json_config_file)
for key in self.SETTINGS_KEYS:
try:
self.settings[key] = task_kwargs[key]
except KeyError:
try:
self.settings[key] = environ[key]
except KeyError:
try:
self.settings[key] = settings[key]
except KeyError:
pass
self.settings.server_count = int(self.settings.server_count)
self.settings.setdefault('ssh_user', 'root')
self.settings.setdefault('git_branch', 'master')
self.ensure_settings('rackspace_username', 'rackspace_apikey')
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials(
self.settings.rackspace_username,
self.settings.rackspace_apikey)
self.cloudservers = pyrax.connect_to_cloudservers()
self.loadbalancers = pyrax.connect_to_cloud_loadbalancers()
示例7: flv_selection
def flv_selection():
#Displays a list of all available flavors, allows the user to select one, and performs input validation.
flvs = pyrax.connect_to_cloudservers(region=region).list_flavors()
count = 1
for flv in flvs:
print count, ")", flv.name
count += 1
total_count = len(flvs)
while True:
server_flv = raw_input("\nSelect the server that you want to create by entering a number between 1 and %s.%s" % (total_count, prompt))
try:
server_flv = int(server_flv)
if server_flv < 1 or server_flv > total_count:
print "Selection out of range."
else:
break
except ValueError:
print "Not a valid selection."
count = 1
for flv in flvs:
if count != server_flv:
count += 1
else:
server_flv_type = flv.name
server_flv_id = flv.id
break
return (server_flv_type, server_flv_id)
示例8: server_selection
def server_selection():
#Displays a list of all available images, allows the user to select one, and performs input validation.
imgs = pyrax.connect_to_cloudservers(region=region).images.list()
count = 1
for img in imgs:
print count, ")", img.name
count += 1
total_count = len(imgs)
while True:
server = raw_input("\nSelect the server that you want to create by entering a number between 1 and %s.%s" % (total_count, prompt))
try:
server = int(server)
if server < 1 or server > total_count:
print "Selection out of range."
else:
break
except ValueError:
print "Not a valid selection."
count = 1
for img in imgs:
if count != server:
count += 1
else:
server_type = img.name
server_id = img.id
break
return (server_type, server_id)
示例9: server_info
def server_info(id, dc):
cs = pyrax.connect_to_cloudservers(region=dc)
server = cs.servers.get(id)
print "Server Name: ", server.name
print "Server ID: ", server.id
print "Public IP: ", server.accessIPv4
print "Private IP :", server.addresses['private'][0]['addr']
示例10: sync_vagrant_rackspace_environment
def sync_vagrant_rackspace_environment():
pyrax_login()
# iterate over all of the cloud servers to identify those that are
# already running.
# https://github.com/rackspace/pyrax/blob/master/docs/cloud_servers.md
cs = pyrax.connect_to_cloudservers(region="ORD")
for server in cs.servers.list():
# if the cloud server is already running and managed by
# vagrant (in env.hosts), then let's make sure the id file is
# set correctly
server_configured = False
filename = vagrant_id_filename(server.name, "rackspace")
if server.name in env.hosts:
if os.path.exists(filename):
with open(filename, 'r') as stream:
if server.id == stream.read():
server_configured = True
# if the server is not configured on the local machine, just
# need to create the file with the server.id in it
if server.name in env.hosts and not server_configured:
if not os.path.exists(os.path.dirname(filename)):
local("mkdir -p %s" % os.path.dirname(filename))
with open(filename, 'w') as stream:
stream.write(server.id)
示例11: main
def main():
pyrax.set_setting("identity_type", "rackspace")
creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')
pyrax.set_credential_file(creds_file)
available_regions = pyrax.regions
print "Regions Available:", " ".join(list(available_regions))
region = ""
while region not in pyrax.regions:
region = raw_input("Select region: ")
cs = pyrax.connect_to_cloudservers(region)
servers = cs.servers.list()
srv_dict = {}
print "Select a server from which an image will be created."
for pos, srv in enumerate(servers):
print "%s: %s" % (pos, srv.name)
srv_dict[str(pos)] = srv.id
selection = None
while selection not in srv_dict:
if selection is not None:
print " -- Invalid choice"
selection = raw_input("Enter the number for your choice: ")
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)
示例12: test_connect_to_cloudservers
def test_connect_to_cloudservers(self):
pyrax.cloudservers = None
sav = pyrax.connect_to_cloudservers
pyrax.connect_to_cloudservers = self.orig_connect_to_cloudservers
pyrax.cloudservers = pyrax.connect_to_cloudservers()
self.assertIsNotNone(pyrax.cloudservers)
pyrax.connect_to_cloudservers = sav
示例13: master_up
def master_up(key_name, credential_file="~/.rackspace_cloud_credentials",
image=default_layout["master"]["image"],
flavor=default_layout["master"]["flavor"],
name=default_layout["master"]["hostname"],
region="IAD"):
'''
Create a salt-master on Rackspace
Alternatively create the master using nova
'''
# Authenticate with Rackspace, use credential file
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credential_file(os.path.expanduser(credential_file))
# Shorthand
cs = pyrax.connect_to_cloudservers(region=region)
master = cs.servers.create(name, image, flavor, key_name=key_name)
master = pyrax.utils.wait_for_build(master, verbose=True)
env.hosts = [master.accessIPv4]
print(master.networks)
print("Master IP: {}".format(master.accessIPv4))
return master.accessIPv4
示例14: main
def main():
pyrax.set_setting("identity_type", "rackspace")
creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')
pyrax.set_credential_file(creds_file)
available_regions = pyrax.regions
print "Regions Available:", " ".join(list(available_regions))
region = ""
while region not in available_regions:
region = raw_input("Select Region: ")
cs = pyrax.connect_to_cloudservers(region)
available_images = cs.images.list()
available_flavors = cs.flavors.list()
image = make_choice(images, "Select an image: ")
flavor = make_choice(flavors, "Select a flavor: ")
base_name = raw_input('Base server name': )
server_count = int(raw_input('Number of servers to build: '))
print "Building {} servers with base name '{}', flavor '{}', and image "
"'{}'.".format(server_count, base_name, flavor.name, image.name)
示例15: list_servers
def list_servers(dc):
cs = pyrax.connect_to_cloudservers(region=dc)
for server in cs.servers.list():
print "Server Name: ", server.name
print "Server Status: ", server.status
print "Server ID: ", server.id
print "Public IP: ", server.accessIPv4
print "Private IP: ", server.addresses['private'][0]['addr']