Merge pull request #19 from Cerberus98/instance_for_accounts
Instance for accounts
This commit is contained in:
commit
4417c96e1e
@ -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):
|
||||
"""
|
||||
|
15
novaclient/accounts.py
Normal file
15
novaclient/accounts.py
Normal file
@ -0,0 +1,15 @@
|
||||
from novaclient import base
|
||||
|
||||
class Account(base.Resource):
|
||||
pass
|
||||
|
||||
class AccountManager(base.BootingManagerWithFind):
|
||||
resource_class = Account
|
||||
|
||||
def create_instance_for(self, account_id, name, image, flavor,
|
||||
ipgroup=None, meta=None, files=None, zone_blob=None,
|
||||
reservation_id=None):
|
||||
resource_url = "/accounts/%s/create_instance" % account_id
|
||||
return self._boot(resource_url, "server", name, image, flavor,
|
||||
ipgroup=ipgroup, meta=meta, files=files,
|
||||
zone_blob=zone_blob, reservation_id=reservation_id)
|
@ -320,6 +320,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>',
|
||||
|
@ -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])
|
||||
|
22
tests/test_accounts.py
Normal file
22
tests/test_accounts.py
Normal file
@ -0,0 +1,22 @@
|
||||
import StringIO
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from fakeserver import FakeServer
|
||||
from novaclient import Account
|
||||
|
||||
cs = FakeServer()
|
||||
|
||||
def test_instance_creation_for_account():
|
||||
s = cs.accounts.create_instance_for(
|
||||
account_id='test_account',
|
||||
name="My server",
|
||||
image=1,
|
||||
flavor=1,
|
||||
meta={'foo': 'bar'},
|
||||
ipgroup=1,
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': StringIO.StringIO('data') # a stream
|
||||
})
|
||||
cs.assert_called('POST', '/accounts/test_account/create_instance')
|
Loading…
x
Reference in New Issue
Block a user