Beispiel #1
0
def _project_argument():
    tenant_id = collection.get_matcher_argument('project', 'eq')
    if tenant_id is not None:
        return tenant_id, False
    tenants = collection.get_matcher_argument('project', 'in')
    if tenants and len(tenants) == 1:
        return tenants[0], False
    tenant_id = collection.get_matcher_argument('project', 'for',
                                                delete_if_found=True)
    if tenant_id is not None:
        return tenant_id, None
    return None, None
Beispiel #2
0
def _project_argument():
    tenant_id = collection.get_matcher_argument('project', 'eq')
    if tenant_id is not None:
        return tenant_id, False
    tenants = collection.get_matcher_argument('project', 'in')
    if tenants and len(tenants) == 1:
        return tenants[0], False
    tenant_id = collection.get_matcher_argument('project',
                                                'for',
                                                delete_if_found=True)
    if tenant_id is not None:
        return tenant_id, None
    return None, None
Beispiel #3
0
def _servers_for_user():
    project_id = get_matcher_argument("project", "eq")
    if project_id is not None:
        projects = (project_id,)
    else:
        projects = get_matcher_argument("project", "in")

    result = []
    for project_id in current_user_project_ids():
        if projects is None or project_id in projects:
            cs = client_set_for_tenant(project_id)
            result.extend(cs.compute.servers.list())
    return result
Beispiel #4
0
 def test_gets_and_deletes(self):
     value = '42'
     flask.g.filters = {'project': {'for': value}}
     result = get_matcher_argument('project', 'for', delete_if_found=True)
     self.assertEquals(value, result)
     self.assertTrue('for' not in flask.g.filters['project'])
Beispiel #5
0
 def test_gets(self):
     value = '42'
     flask.g.filters = {'project': {'for': value}}
     result = get_matcher_argument('project', 'for')
     self.assertEquals(value, result)
     self.assertEquals(value, flask.g.filters['project'].get('for'))
Beispiel #6
0
 def test_no_match_type(self):
     flask.g.filters = {'project': {'eq': '42'}}
     self.assertEquals(None, get_matcher_argument('project', 'for'))
Beispiel #7
0
 def test_no_matchers(self):
     flask.g.filters = {'some': {'other': 'matcher'}}
     self.assertEquals(None, get_matcher_argument('project', 'for'))
Beispiel #8
0
 def test_none(self):
     flask.g.filters = None
     self.assertEquals(None, get_matcher_argument('project', 'for'))
Beispiel #9
0
 def test_gets_and_deletes(self):
     value = "42"
     flask.g.filters = {"project": {"for": value}}
     result = get_matcher_argument("project", "for", delete_if_found=True)
     self.assertEquals(value, result)
     self.assertTrue("for" not in flask.g.filters["project"])
Beispiel #10
0
 def test_gets(self):
     value = "42"
     flask.g.filters = {"project": {"for": value}}
     result = get_matcher_argument("project", "for")
     self.assertEquals(value, result)
     self.assertEquals(value, flask.g.filters["project"].get("for"))
Beispiel #11
0
 def test_no_match_type(self):
     flask.g.filters = {"project": {"eq": "42"}}
     self.assertEquals(None, get_matcher_argument("project", "for"))
Beispiel #12
0
 def test_no_matchers(self):
     flask.g.filters = {"some": {"other": "matcher"}}
     self.assertEquals(None, get_matcher_argument("project", "for"))
Beispiel #13
0
 def test_none(self):
     flask.g.filters = None
     self.assertEquals(None, get_matcher_argument("project", "for"))