Add list function to client

This commit is contained in:
Andrew Hutchings
2012-10-13 11:36:51 +01:00
parent 7c4891c53d
commit e6f59f5533
2 changed files with 18 additions and 5 deletions

View File

@@ -24,6 +24,6 @@ def main():
args.os_auth_url, args.os_region_name)
if args.command == 'list':
api.get('/devices')
api.list_lb()
return 0

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import prettytable
from novaclient import client
@@ -26,14 +27,26 @@ class LibraAPI(object):
service_type='libra'
)
def get(self, url, **kwargs):
def list_lb(self):
resp, body = self._get('/loadbalaners')
columns = ['Name', 'ID', 'Protocol', 'Port', 'Algorithm', 'Status',
'Created', 'Updated']
self._render(columns, body, 'loadbalancers')
def _render(self, columns, data, row_item):
table = prettytable.PrettyTable(columns)
for item in data[row_item]:
table.add_row(item)
print table
def _get(self, url, **kwargs):
return self.nova.get(url, **kwargs)
def post(self, url, **kwargs):
def _post(self, url, **kwargs):
return self.nova.post(url, **kwargs)
def put(self, url, **kwargs):
def _put(self, url, **kwargs):
return self.nova.put(url, **kwargs)
def delete(self, url, **kwargs):
def _delete(self, url, **kwargs):
return self.nova.delete(url, **kwargs)