本文整理汇总了Python中profitbricks.client.ProfitBricksService.start_server方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.start_server方法的具体用法?Python ProfitBricksService.start_server怎么用?Python ProfitBricksService.start_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.start_server方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestServer
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import start_server [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.server['properties']['ram'], self.resource['server']['ram'])
self.assertIsNone(self.server['properties']['availabilityZone'])
self.assertIsNone(self.server['properties']['vmState'])
def test_create_complex(self):
fwrule = FirewallRule(**self.resource['fwrule'])
nic = NIC(firewall_rules=[fwrule], **self.resource['nic'])
volume = Volume(image=self.image['id'],
image_password='secretpassword123',
ssh_keys=['ssh-rsa AAAAB3NzaC1'],
**self.resource['volume'])
server = Server(
nics=[nic],
create_volumes=[volume],
**self.resource['server'])
composite_server = self.client.create_server(
datacenter_id=self.datacenter['id'],
server=server)
wait_for_completion(self.client, composite_server, 'create_server', wait_timeout=600)
composite_server = self.client.get_server(
datacenter_id=self.datacenter['id'],
server_id=composite_server['id'])
assertRegex(self, composite_server['id'], self.resource['uuid_match'])
self.assertEqual(composite_server['properties']['name'], self.resource['server']['name'])
self.assertEqual(composite_server['properties']['cores'], self.resource['server']['cores'])
self.assertEqual(composite_server['properties']['ram'], self.resource['server']['ram'])
self.assertEqual(composite_server['properties']['availabilityZone'], 'AUTO')
self.assertIn(composite_server['properties']['vmState'], self.resource['vm_states'])
def test_start_server(self):
server = self.client.start_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'])
self.assertTrue(server)
def test_stop_server(self):
server = self.client.stop_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'])
self.assertTrue(server)
def test_reboot_server(self):
server = self.client.reboot_server(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'])
self.assertTrue(server)
def test_get_attached_volumes(self):
servers = self.client.get_attached_volumes(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'])
self.assertGreater(len(servers), 0)
self.assertEqual(servers['items'][0]['id'], self.volume1['id'])
self.assertEqual(servers['items'][0]['properties']['name'], self.resource['volume']['name'])
self.assertEqual(servers['items'][0]['properties']['size'], self.resource['volume']['size'])
self.assertEqual(servers['items'][0]['properties']['bus'], self.resource['volume']['bus'])
self.assertEqual(servers['items'][0]['properties']['type'], self.resource['volume']['type'])
self.assertEqual(servers['items'][0]['properties']['licenceType'], 'UNKNOWN')
示例2: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import start_server [as 别名]
#.........这里部分代码省略.........
required=True, help='what to do with the server')
parser.add_argument('-C', '--command', dest='command', default=None,
help='remote shell command to use for shutdown')
parser.add_argument('-v', '--verbose', dest="verbose", action="count",
help="set verbosity level [default: %(default)s]")
parser.add_argument('-V', '--version', action='version',
version=program_version_message)
# Process arguments
args = parser.parse_args()
global verbose
verbose = args.verbose
dc_id = args.dc_id
if verbose > 0:
print("Verbose mode on")
# normalize action
action = args.action.upper()
actions = set(['POWERON', 'POWEROFF', 'START', 'SHUTOFF'])
if action not in actions:
parser.error("action must be on of {}".format(str(actions)))
if args.serverid is None and args.servername is None:
parser.error("one of 'serverid' or 'name' must be specified")
(user, password) = getLogin(args.loginfile, args.user, args.password)
if user is None or password is None:
raise ValueError("user or password resolved to None")
pbclient = ProfitBricksService(user, password)
server = getServerStates(pbclient, dc_id,
args.serverid, args.servername)
if server is None:
raise Exception(1, "specified server not found")
print("using server {}(id={}) in state {}, {}"
.format(server['name'], server['id'], server['state'],
server['vmstate']))
# !!! stop/start/reboot_server() simply return 'True' !!!
# this implies, that there's NO response nor requestId to track!
if action == 'POWEROFF':
if server['state'] == 'INACTIVE':
print("server is already powered off")
else:
# currently use 'forced' poweroff
if server['vmstate'] != 'SHUTOFF':
print("VM is in state {}, {} may lead to inconsistent state"
.format(server['vmstate'], action))
if args.command is None:
print("no command specified for shutdown of VM")
else:
print("executing {}".format(args.command))
cmdrc = call(args.command, shell=True)
print("executing {} returned {}"
.format(args.command, cmdrc))
pbclient.stop_server(dc_id, server['id'])
server = wait_for_server(pbclient, dc_id, server['id'],
state='INACTIVE', timeout=300)
elif action == 'POWERON':
if server['vmstate'] == 'RUNNING':
print("VM is already up and running")
else:
pbclient.start_server(dc_id, server['id'])
server = wait_for_server(pbclient, dc_id, server['id'],
indicator='vmstate', state='RUNNING',
timeout=300)
elif action == 'START':
# this is the same as POWERON
if server['vmstate'] == 'RUNNING':
print("VM is already up and running")
else:
pbclient.start_server(dc_id, server['id'])
server = wait_for_server(pbclient, dc_id, server['id'],
indicator='vmstate', state='RUNNING',
timeout=300)
elif action == 'SHUTOFF':
if server['vmstate'] == 'SHUTOFF':
print("VM is already shut off")
else:
if args.command is None:
print("no command specified for shutdown of VM")
else:
print("executing {}".format(args.command))
cmdrc = call(args.command, shell=True)
print("executing {} returned {}"
.format(args.command, cmdrc))
server = wait_for_server(pbclient, dc_id, server['id'],
indicator='vmstate',
state='SHUTOFF',
timeout=300)
# end if/else(action)
print("server {}(id={}) now in state {}, {}"
.format(server['name'], server['id'], server['state'],
server['vmstate']))
except KeyboardInterrupt:
# handle keyboard interrupt #
return 0
except Exception:
traceback.print_exc()
sys.stderr.write("\n" + program_name + ": for help use --help\n")
return 2
示例3: TestServer
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import start_server [as 别名]
#.........这里部分代码省略.........
'Ubuntu image description')
self.assertEqual(servers['items'][0]['properties']['location'], 'de/fkb')
self.assertEqual(servers['items'][0]['properties']['imageType'], 'CDROM')
self.assertEqual(servers['items'][0]['properties']['licenceType'], 'UNKNOWN')
self.assertFalse(servers['items'][0]['properties']['public'])
self.assertFalse(servers['items'][0]['properties']['cpuHotPlug'])
self.assertFalse(servers['items'][0]['properties']['cpuHotUnplug'])
self.assertFalse(servers['items'][0]['properties']['ramHotPlug'])
self.assertFalse(servers['items'][0]['properties']['ramHotUnplug'])
self.assertFalse(servers['items'][0]['properties']['nicHotPlug'])
self.assertFalse(servers['items'][0]['properties']['nicHotUnplug'])
self.assertFalse(servers['items'][0]['properties']['discVirtioHotPlug'])
self.assertFalse(servers['items'][0]['properties']['discVirtioHotUnplug'])
self.assertFalse(servers['items'][0]['properties']['discScsiHotPlug'])
self.assertFalse(servers['items'][0]['properties']['discScsiHotUnplug'])
def test_get_attached_cdrom(self):
cdrom_id = '7df81087-5835-41c6-a10b-3e098593bbd2'
server = self.server.get_attached_cdrom(
datacenter_id=datacenter_id,
server_id=server_id,
cdrom_id=cdrom_id)
self.assertEqual(server['id'], cdrom_id)
self.assertEqual(server['properties']['name'], 'Ubuntu 14.04')
self.assertEqual(server['properties']['size'], 28)
self.assertEqual(server['properties']['description'], 'Ubuntu image description')
self.assertEqual(server['properties']['location'], 'de/fkb')
self.assertEqual(server['properties']['imageType'], 'CDROM')
self.assertEqual(server['properties']['licenceType'], 'UNKNOWN')
self.assertFalse(server['properties']['public'])
self.assertFalse(server['properties']['cpuHotPlug'])
self.assertFalse(server['properties']['cpuHotUnplug'])
self.assertFalse(server['properties']['ramHotPlug'])
self.assertFalse(server['properties']['ramHotUnplug'])
self.assertFalse(server['properties']['nicHotPlug'])
self.assertFalse(server['properties']['nicHotUnplug'])
self.assertFalse(server['properties']['discVirtioHotPlug'])
self.assertFalse(server['properties']['discVirtioHotUnplug'])
self.assertFalse(server['properties']['discScsiHotPlug'])
self.assertFalse(server['properties']['discScsiHotUnplug'])
def test_detach_cdrom(self):
cdrom_id = '7df81087-5835-41c6-a10b-3e098593bbd2'
server = self.server.detach_cdrom(
datacenter_id=datacenter_id,
server_id=server_id,
cdrom_id=cdrom_id)
self.assertTrue(server)
def test_attach_cdrom(self):
cdrom_id = '7df81087-5835-41c6-a10b-3e098593bbd2'
server = self.server.attach_cdrom(
datacenter_id=datacenter_id,
server_id=server_id,
cdrom_id=cdrom_id)
self.assertEqual(server['id'], cdrom_id)
self.assertEqual(server['properties']['name'], 'Ubuntu 14.04')
self.assertEqual(server['properties']['size'], 28)
self.assertEqual(server['properties']['description'], 'Ubuntu image description')
self.assertEqual(server['properties']['location'], 'de/fkb')
self.assertEqual(server['properties']['imageType'], 'CDROM')
self.assertEqual(server['properties']['licenceType'], 'UNKNOWN')
self.assertFalse(server['properties']['public'])
self.assertFalse(server['properties']['cpuHotPlug'])
self.assertFalse(server['properties']['cpuHotUnplug'])
self.assertFalse(server['properties']['ramHotPlug'])
self.assertFalse(server['properties']['ramHotUnplug'])
self.assertFalse(server['properties']['nicHotPlug'])
self.assertFalse(server['properties']['nicHotUnplug'])
self.assertFalse(server['properties']['discVirtioHotPlug'])
self.assertFalse(server['properties']['discVirtioHotUnplug'])
self.assertFalse(server['properties']['discScsiHotPlug'])
self.assertFalse(server['properties']['discScsiHotUnplug'])
def test_start_server(self):
server = self.server.start_server(
datacenter_id=datacenter_id,
server_id=server_id)
self.assertTrue(server)
def test_stop_server(self):
server = self.server.stop_server(
datacenter_id=datacenter_id,
server_id=server_id)
self.assertTrue(server)
def test_reboot_server(self):
server = self.server.reboot_server(
datacenter_id=datacenter_id,
server_id=server_id)
self.assertTrue(server)
示例4: ProfitBricksService
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import start_server [as 别名]
response = client.create_server(
datacenter_id=datacenter_id,
server=i)
"""Start Server
"""
from profitbricks.client import ProfitBricksService
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'
client = ProfitBricksService(
username='username', password='password')
server = client.start_server(
datacenter_id=datacenter_id,
server_id=server_id)
"""Stop Server
"""
from profitbricks.client import ProfitBricksService
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'
client = ProfitBricksService(
username='username', password='password')
server = client.stop_server(
datacenter_id=datacenter_id,
server_id=server_id)