Skip to content

Instantly share code, notes, and snippets.

@omaciel
Created November 26, 2013 23:07
Show Gist options
  • Save omaciel/7667928 to your computer and use it in GitHub Desktop.
Save omaciel/7667928 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: ts=4 sw=4 expandtab ai
from base import Base
from lib.common.helpers import csv_to_dictionary
class Org(Base):
def __init__(self, conn):
self.conn = conn
def create(self, name=None):
"""
Add brief description for method
"""
cmd = "organization create --name='%s'"
if name is None:
name = generate_name()
cmd = cmd % (name)
stdout, stderr = self.execute(cmd)
return False if stderr else True
def delete(self, org_id=None, name=None):
cmd = "organization delete"
if org_id:
cmd += " --id='%s'" % org_id
if name:
cmd += " --name='%s'" % name
stdout, stderr = self.execute(cmd)
return False if stderr else True
def info(self, org_id=None, name=None):
cmd = "organization info"
if org_id:
cmd += " --id='%s'" % org_id
if name:
cmd += " --name='%s'" % name
org = {}
stdout, stderr = self.execute(cmd % name)
if stdout:
org = csv_to_dictionary(stdout)
return org
def list(self):
cmd = "organization list"
orgs = []
stdout, stderr = self.execute(cmd)
org = {}
if stdout:
for entry in stdout:
orgs.append(csv_to_dictionary(stdout))
return orgs
def exists(self, name):
"""
Returns whether or not org exists.
"""
orgs = self.list()
return name in [
org['Name'] for org in orgs
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment