Permalink
Browse files

systems cli - actions use new api util method get_system

  • Loading branch information...
1 parent 24b08ed commit 50c20c6cb7b93c85c0e7140bb056a390dc2ada97 @tstrachota committed May 2, 2012
Showing with 131 additions and 155 deletions.
  1. +0 −1 cli/src/katello/client/api/system.py
  2. +26 −7 cli/src/katello/client/api/utils.py
  3. +105 −147 cli/src/katello/client/core/system.py
@@ -14,7 +14,6 @@
# in this software or its documentation.
from katello.client.api.base import KatelloAPI
-from katello.client.api.utils import get_environment
from katello.client.utils.encoding import u_str
class SystemAPI(KatelloAPI):
@@ -28,7 +28,7 @@
from katello.client.api.sync_plan import SyncPlanAPI
from katello.client.api.permission import PermissionAPI
from katello.client.api.filter import FilterAPI
-#from katello.client.api.system import SystemAPI
+from katello.client.api.system import SystemAPI
def get_organization(orgName):
organization_api = OrganizationAPI()
@@ -161,10 +161,29 @@ def get_filter(org_name, name):
print >> sys.stderr, _("Cannot find filter [ %s ]") % (name)
return filter
-def get_system(org_name, name):
+def get_system(org_name, sys_name, env_name=None):
system_api = SystemAPI()
- systems = self.api.systems_by_org(org, {'name': name})
- if systems is None or len(systems) != 1:
- print >> sys.stderr, _("Could not find System [ %s ] in Org [ %s ]") % (name, org_name)
- return None
- return systems[0]
+ if env_name is None:
+ systems = system_api.systems_by_org(org_name, {'name': sys_name})
+ if systems is None:
+ print >> sys.stderr, _("Could not find System [ %s ] in Org [ %s ]") % (sys_name, org_name)
+ return None
+ elif len(systems) != 1:
+ print >> sys.stderr, _("Found ambiguous Systems [ %s ] in Environment [ %s ] in Org [ %s ]") % (name, env_name, org)
+ return None
+
+ else:
+ environment = get_environment(org_name, env_name)
+ if environemnt is None:
+ return None
+ systems = system_api.systems_by_env(org_name, environment["id"], {'name': sys_name})
+ if systems is None:
+ print >> sys.stderr, _("Could not find System [ %s ] in Environment [ %s ] in Org [ %s ]") % (sys_name, env_name, org_name)
+ return None
+ elif len(systems) != 1:
+ print >> sys.stderr, _("Found ambiguous Systems [ %s ] in Org [ %s ], you have to specify the environment") % (name, org)
+ return None
+
+ return system_api.system(systems[0]['uuid'])
+
+
Oops, something went wrong.

0 comments on commit 50c20c6

Please sign in to comment.