Mgmt Instances.

This commit is contained in:
Sudarshan Acharya
2012-06-18 12:26:34 -05:00
committed by Nirmal Ranganathan
parent 79ecd5c077
commit 773590df6a
3 changed files with 64 additions and 14 deletions

View File

@@ -30,10 +30,10 @@ class Interrogator(base.ManagerWithFind):
Manager class for Interrogator resource
"""
resource_class = Diagnostics
url = "/mgmt/instances/%s/diagnostics"
def get(self, instance_id):
def get(self, instance):
"""
Get the diagnostics of the guest on the instance.
"""
return self._get(self.url % base.getid(instance_id), "diagnostics")
return self._get("/mgmt/instances/%s/diagnostics" % base.getid(instance),
"diagnostics")

View File

@@ -14,8 +14,11 @@
# under the License.
from novaclient import base
import urlparse
from reddwarfclient.common import check_for_exceptions
from reddwarfclient.common import limit_url
from reddwarfclient.common import Paginated
from reddwarfclient.instances import Instance
@@ -31,11 +34,21 @@ class Management(base.ManagerWithFind):
"""
resource_class = Instance
def _list(self, url, response_key):
resp, body = self.api.client.get(url)
def _list(self, url, response_key, limit=None, marker=None):
resp, body = self.api.client.get(limit_url(url, limit, marker))
if not body:
raise Exception("Call to " + url + " did not return a body.")
return self.resource_class(self, body[response_key])
links = body.get('links', [])
next_links = [link['href'] for link in links if link['rel'] == 'next']
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
instances = body[response_key]
instances = [self.resource_class(self, res) for res in instances]
return Paginated(instances, next_marker=next_marker, links=links)
def show(self, instance):
"""
@@ -44,10 +57,10 @@ class Management(base.ManagerWithFind):
:rtype: :class:`Instance`.
"""
return self._list("/mgmt/instances/%s" % base.getid(instance),
'instance')
return self._get("/mgmt/instances/%s" % base.getid(instance),
'instance')
def index(self, deleted=None):
def index(self, deleted=None, limit=None, marker=None):
"""
Show an overview of all local instances.
Optionally, filter by deleted status.
@@ -62,11 +75,7 @@ class Management(base.ManagerWithFind):
form = "?deleted=false"
url = "/mgmt/instances%s" % form
resp, body = self.api.client.get(url)
if not body:
raise Exception("Call to " + url + " did not return a body.")
return [self.resource_class(self, instance)
for instance in body['instances']]
return self._list(url, "instances", limit, marker)
def root_enabled_history(self, instance):
"""

View File

@@ -101,6 +101,46 @@ class AccountCommands(object):
print sys.exc_info()[1]
class InstanceCommands(object):
"""List details about an instance."""
def __init__(self):
pass
def get(self, id):
"""List details for the instance."""
dbaas = common.get_client()
try:
result = dbaas.management.show(id)
_pretty_print(result._info)
except:
print sys.exc_info()[1]
def list(self, deleted=None, limit=None, marker=None):
"""List all instances for account"""
dbaas = common.get_client()
if limit:
limit = int(limit, 10)
try:
instances = dbaas.management.index(deleted, limit, marker)
for instance in instances:
_pretty_print(instance._info)
if instances.links:
for link in instances.links:
_pretty_print(link)
except:
print sys.exc_info()[1]
def diagnostic(self, id):
"""List diagnostic details about an instance."""
dbaas = common.get_client()
try:
result = dbaas.diagnostics.get(id)
_pretty_print(result._info)
except:
print sys.exc_info()[1]
def config_options():
global oparser
oparser.add_option("-u", "--url", default="http://localhost:5000/v1.1",
@@ -110,6 +150,7 @@ def config_options():
COMMANDS = {'account': AccountCommands,
'host': HostCommands,
'instance': InstanceCommands,
'root': RootCommands,
}