Added a method to create instances on behalf of an account via the admin API methods for openstack

This commit is contained in:
Matt Dietz 2011-06-13 15:13:33 -05:00
parent 7a9e006a2f
commit 129d56611c
3 changed files with 65 additions and 0 deletions

View File

@ -20,6 +20,7 @@ novaclient module.
__version__ = '2.4'
from novaclient.accounts import Account, AccountManager
from novaclient.backup_schedules import (
BackupSchedule, BackupScheduleManager,
BACKUP_WEEKLY_DISABLED, BACKUP_WEEKLY_SUNDAY, BACKUP_WEEKLY_MONDAY,
@ -70,6 +71,7 @@ class OpenStack(object):
self.ipgroups = IPGroupManager(self)
self.servers = ServerManager(self)
self.zones = ZoneManager(self)
self.accounts = AccountManager(self)
def authenticate(self):
"""

View File

@ -318,6 +318,55 @@ class OpenStackShell(object):
files=files)
print_dict(server._info)
@arg('--flavor',
default=None,
metavar='<flavor>',
help="Flavor ID (see 'novaclient flavors'). "\
"Defaults to 256MB RAM instance.")
@arg('--image',
default=None,
metavar='<image>',
help="Image ID (see 'novaclient images'). "\
"Defaults to Ubuntu 10.04 LTS.")
@arg('--ipgroup',
default=None,
metavar='<group>',
help="IP group name or ID (see 'novaclient ipgroup-list').")
@arg('--meta',
metavar="<key=value>",
action='append',
default=[],
help="Record arbitrary key/value metadata. "\
"May be give multiple times.")
@arg('--file',
metavar="<dst-path=src-path>",
action='append',
dest='files',
default=[],
help="Store arbitrary files from <src-path> locally to <dst-path> "\
"on the new server. You may store up to 5 files.")
@arg('--key',
metavar='<path>',
nargs='?',
const=AUTO_KEY,
help="Key the server with an SSH keypair. "\
"Looks in ~/.ssh for a key, "\
"or takes an explicit <path> to one.")
@arg('account', metavar='<account>', help='Account to build this'\
'server for')
@arg('name', metavar='<name>', help='Name for the new server')
def do_boot_for_account(self, args):
"""Boot a new server in an account."""
name, image, flavor, ipgroup, metadata, files, reservation_id = \
self._boot(args)
server = self.cs.accounts.create_instance_for(args.account, args.name,
image, flavor,
ipgroup=ipgroup,
meta=metadata,
files=files)
print_dict(server._info)
@arg('--flavor',
default=None,
metavar='<flavor>',

View File

@ -434,3 +434,17 @@ class FakeClient(OpenStackClient):
def delete_zones_1(self, **kw):
return (202, None)
#
# Accounts
#
def post_accounts_test_account_create_instance(self, body, **kw):
assert_equal(body.keys(), ['server'])
assert_has_keys(body['server'],
required=['name', 'imageId', 'flavorId'],
optional=['sharedIpGroupId', 'metadata',
'personality'])
if 'personality' in body['server']:
for pfile in body['server']['personality']:
assert_has_keys(pfile, required=['path', 'contents'])
return (202, self.get_servers_1234()[1])