removed zone name, renamed auth_url to api_url, added username/password
This commit is contained in:
parent
637ddefbbe
commit
9034c4618a
@ -483,40 +483,47 @@ class OpenStackShell(object):
|
||||
"""Immediately shut down and delete a server."""
|
||||
self._find_server(args.server).delete()
|
||||
|
||||
@arg('zone', metavar='<zone name>', help='Name of the parent zone')
|
||||
@arg('--name', dest='name', default=None, help='New name.')
|
||||
@arg('--auth_url', dest='auth_url', help='New Auth URL.')
|
||||
# --zone_username is required since --username is already used.
|
||||
@arg('zone', metavar='<zone>', help='Name or ID of the zone')
|
||||
@arg('--api_url', dest='api_url', default=None, help='New URL.')
|
||||
@arg('--zone_username', dest='zone_username', default=None,
|
||||
help='New zone username.')
|
||||
@arg('--password', dest='password', default=None, help='New password.')
|
||||
def do_zone(self, args):
|
||||
"""Show or edit a zone."""
|
||||
zone = self.cs.zones.get(args.zone)
|
||||
|
||||
# If we have some flags, update the zone
|
||||
zone_delta = {}
|
||||
if args.name:
|
||||
zone_delta['name'] = args.name
|
||||
if args.auth_url:
|
||||
zone_delta['auth_url'] = args.auth_url
|
||||
|
||||
if args.api_url:
|
||||
zone_delta['api_url'] = args.api_url
|
||||
if args.zone_username:
|
||||
zone_delta['username'] = args.zone_username
|
||||
if args.password:
|
||||
zone_delta['password'] = args.password
|
||||
if zone_delta:
|
||||
zone.update(**zone_delta)
|
||||
else:
|
||||
print_dict(zone._info)
|
||||
|
||||
@arg('name', metavar='<name>', help='Name for the new child zone')
|
||||
@arg('auth_url', metavar='<auth_url>', help="URL for the Zone's Auth API")
|
||||
@arg('api_url', metavar='<api_url>', help="URL for the Zone's API")
|
||||
@arg('zone_username', metavar='<zone_username>',
|
||||
help='Authentication username.')
|
||||
@arg('password', metavar='<password>', help='Authentication password.')
|
||||
def do_zone_add(self, args):
|
||||
"""Add a new child zone."""
|
||||
zone = self.cs.zones.create(args.name, args.auth_url)
|
||||
zone = self.cs.zones.create(args.api_url, args.zone_username,
|
||||
args.password)
|
||||
print_dict(zone._info)
|
||||
|
||||
@arg('zone', metavar='<zone name>', help='Name of the parent zone')
|
||||
@arg('zone', metavar='<zone name>', help='Name or ID of the zone')
|
||||
def do_zone_delete(self, args):
|
||||
"""Delete a zone."""
|
||||
self.cs.zones.delete(args.zone)
|
||||
|
||||
def do_zone_list(self, args):
|
||||
"""List the children of a zone."""
|
||||
print_list(self.cs.zones.list(), ['ID', 'Name', 'Auth URL'])
|
||||
print_list(self.cs.zones.list(), ['ID', 'API URL', 'Username'])
|
||||
|
||||
def _find_server(self, server):
|
||||
"""Get a server by name or ID."""
|
||||
|
@ -3,7 +3,7 @@ from novatools import base
|
||||
|
||||
class Zone(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Zone: %s>" % self.name
|
||||
return "<Zone: %s>" % self.api_url
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
@ -11,14 +11,15 @@ class Zone(base.Resource):
|
||||
"""
|
||||
self.manager.delete(self)
|
||||
|
||||
def update(self, name=None, auth_url=None):
|
||||
def update(self, api_url=None, username=None, password=None):
|
||||
"""
|
||||
Update the name for this child zone.
|
||||
|
||||
:param name: Update the child zone's name.
|
||||
:param auth_url: Update the child zone's Auth URL.
|
||||
:param api_url: Update the child zone's API URL.
|
||||
:param username: Update the child zone's username.
|
||||
:param password: Update the child zone's password.
|
||||
"""
|
||||
self.manager.update(self, name, auth_url)
|
||||
self.manager.update(self, api_url, username, password)
|
||||
|
||||
|
||||
class ZoneManager(base.ManagerWithFind):
|
||||
@ -40,15 +41,18 @@ class ZoneManager(base.ManagerWithFind):
|
||||
"""
|
||||
return self._list("/zones/detail", "zones")
|
||||
|
||||
def create(self, name, auth_url):
|
||||
def create(self, api_url, username, password):
|
||||
"""
|
||||
Create a new child zone.
|
||||
|
||||
:param name: Something to name the zone.
|
||||
:param api_url: The child zone's API URL.
|
||||
:param username: The child zone's username.
|
||||
:param password: The child zone's password.
|
||||
"""
|
||||
body = {"zone": {
|
||||
"name": name,
|
||||
"auth_url": auth_url,
|
||||
"api_url": api_url,
|
||||
"username": username,
|
||||
"password": password,
|
||||
}}
|
||||
|
||||
return self._create("/zones", body, "zone")
|
||||
@ -59,22 +63,24 @@ class ZoneManager(base.ManagerWithFind):
|
||||
"""
|
||||
self._delete("/zones/%s" % base.getid(zone))
|
||||
|
||||
def update(self, zone, name=None, auth_url=None):
|
||||
def update(self, zone, api_url=None, username=None, password=None):
|
||||
"""
|
||||
Update the name or the auth_url for a zone.
|
||||
Update the name or the api_url for a zone.
|
||||
|
||||
:param zone: The :class:`Zone` (or its ID) to update.
|
||||
:param name: Update the zone's name.
|
||||
:param auth_url: Update the Auth URL.
|
||||
:param api_url: Update the API URL.
|
||||
:param username: Update the username.
|
||||
:param password: Update the password.
|
||||
"""
|
||||
|
||||
if name is None and auth_url is None:
|
||||
return
|
||||
body = {"zone": {}}
|
||||
if name:
|
||||
body["zone"]["name"] = name
|
||||
if auth_url:
|
||||
body["zone"]["auth_url"] = auth_url
|
||||
if api_url:
|
||||
body["zone"]["api_url"] = api_url
|
||||
if username:
|
||||
body["zone"]["username"] = username
|
||||
if password:
|
||||
body["zone"]["password"] = password
|
||||
|
||||
if not len(body["zone"]):
|
||||
return
|
||||
self._update("/zones/%s" % base.getid(zone), body)
|
||||
|
||||
|
||||
|
@ -374,15 +374,17 @@ class FakeClient(OpenStackClient):
|
||||
#
|
||||
def get_zones(self, **kw):
|
||||
return (200, {'zones': [
|
||||
{'id': 1, 'name': 'zone1'},
|
||||
{'id': 2, 'name': 'zone2'},
|
||||
{'id': 1, 'api_url': 'http://foo.com', 'username': 'bob'},
|
||||
{'id': 2, 'api_url': 'http://foo.com', 'username': 'alice'},
|
||||
]})
|
||||
|
||||
|
||||
def get_zones_detail(self, **kw):
|
||||
return (200, {'zones': [
|
||||
{'id': 1, 'name': 'zone1', 'auth_url': 'http://foo.com'},
|
||||
{'id': 2, 'name': 'zone2', 'auth_url': 'http://foo.com'},
|
||||
{'id': 1, 'api_url': 'http://foo.com', 'username': 'bob',
|
||||
'password': 'qwerty'},
|
||||
{'id': 2, 'api_url': 'http://foo.com', 'username': 'alice',
|
||||
'password': 'password'}
|
||||
]})
|
||||
|
||||
def get_zones_1(self, **kw):
|
||||
@ -396,17 +398,16 @@ class FakeClient(OpenStackClient):
|
||||
def post_zones(self, body, **kw):
|
||||
assert_equal(body.keys(), ['zone'])
|
||||
assert_has_keys(body['zone'],
|
||||
required=['name', 'auth_url'],
|
||||
required=['api_url', 'username', 'password'],
|
||||
optional=[])
|
||||
|
||||
return (202, self.get_zones_1()[1])
|
||||
|
||||
def put_zones_1(self, body, **kw):
|
||||
assert_equal(body.keys(), ['zone'])
|
||||
assert_has_keys(body['zone'], optional=['name', 'auth_url'])
|
||||
assert_has_keys(body['zone'], optional=['api_url', 'username',
|
||||
'password'])
|
||||
return (204, None)
|
||||
|
||||
def delete_zones_1(self, **kw):
|
||||
return (202, None)
|
||||
|
||||
|
||||
|
@ -303,17 +303,19 @@ def test_zone():
|
||||
shell('zone 1')
|
||||
assert_called('GET', '/zones/1')
|
||||
|
||||
shell('zone 1 --name zoneA --auth_url http://zzz')
|
||||
shell('zone 1 --api_url=http://zzz --zone_username=frank --password=xxx')
|
||||
assert_called(
|
||||
'PUT', '/zones/1',
|
||||
{'zone': {'name': 'zoneA', 'auth_url': 'http://zzz'}}
|
||||
{'zone': {'api_url': 'http://zzz', 'username': 'frank',
|
||||
'password': 'xxx'}}
|
||||
)
|
||||
|
||||
def test_zone_add():
|
||||
shell('zone-add zone3 http://zzz')
|
||||
shell('zone-add http://zzz frank xxx')
|
||||
assert_called(
|
||||
'POST', '/zones',
|
||||
{'zone': {'name': 'zone3', 'auth_url': 'http://zzz'}}
|
||||
{'zone': {'api_url': 'http://zzz', 'username': 'frank',
|
||||
'password': 'xxx'}}
|
||||
)
|
||||
|
||||
def test_zone_delete():
|
||||
|
@ -18,14 +18,12 @@ def test_get_zone_details():
|
||||
os.assert_called('GET', '/zones/1')
|
||||
assert_isinstance(s, Zone)
|
||||
assert_equal(s.id, 1)
|
||||
assert_equal(s.auth_url, 'http://foo.com')
|
||||
assert_equal(s.api_url, 'http://foo.com')
|
||||
|
||||
|
||||
def test_create_zone():
|
||||
s = os.zones.create(
|
||||
name="My zone",
|
||||
auth_url="http://foo.com"
|
||||
)
|
||||
s = os.zones.create(api_url="http://foo.com", username='bob',
|
||||
password='xxx')
|
||||
os.assert_called('POST', '/zones')
|
||||
assert_isinstance(s, Zone)
|
||||
|
||||
@ -34,20 +32,21 @@ def test_update_zone():
|
||||
s = os.zones.get(1)
|
||||
|
||||
# Update via instance
|
||||
s.update(name='hi')
|
||||
s.update(api_url='http://blah.com')
|
||||
os.assert_called('PUT', '/zones/1')
|
||||
s.update(name='hi', auth_url='there')
|
||||
s.update(api_url='http://blah.com', username='alice', password='xxx')
|
||||
os.assert_called('PUT', '/zones/1')
|
||||
|
||||
# Silly, but not an error
|
||||
s.update()
|
||||
|
||||
# Update via manager
|
||||
os.zones.update(s, name='hi')
|
||||
os.zones.update(s, api_url='http://blah.com')
|
||||
os.assert_called('PUT', '/zones/1')
|
||||
os.zones.update(1, auth_url='there')
|
||||
os.zones.update(1, api_url= 'http://blah.com')
|
||||
os.assert_called('PUT', '/zones/1')
|
||||
os.zones.update(s, name='hi', auth_url='there')
|
||||
os.zones.update(s, api_url='http://blah.com', username='fred',
|
||||
password='zip')
|
||||
os.assert_called('PUT', '/zones/1')
|
||||
|
||||
|
||||
@ -61,13 +60,13 @@ def test_delete_zone():
|
||||
os.assert_called('DELETE', '/zones/1')
|
||||
|
||||
|
||||
def test_find():
|
||||
s = os.zones.find(name='zone2')
|
||||
def test_find_zone():
|
||||
s = os.zones.find(password='qwerty')
|
||||
os.assert_called('GET', '/zones/detail')
|
||||
assert_equal(s.name, 'zone2')
|
||||
assert_equal(s.username, 'bob')
|
||||
|
||||
# Find with multiple results arbitraility returns the first item
|
||||
s = os.zones.find(auth_url='http://foo.com')
|
||||
sl = os.zones.findall(auth_url='http://foo.com')
|
||||
# Find with multiple results returns the first item
|
||||
s = os.zones.find(api_url='http://foo.com')
|
||||
sl = os.zones.findall(api_url='http://foo.com')
|
||||
assert_equal(sl[0], s)
|
||||
assert_equal([s.id for s in sl], [1, 2])
|
||||
|
Loading…
x
Reference in New Issue
Block a user