~santhoshkumar/network-service/quantum_testing_framework

« back to all changes in this revision

Viewing changes to quantum/db/api.py

  • Committer: Santhosh
  • Date: 2011-06-08 10:21:47 UTC
  • Revision ID: santhom@thoughtworks.com-20110608102147-0eyu3phhp8acjjfw
Santhosh/Vinkesh | Fixed all the pep8 violations. Modified the 'req' to 'request' across all the services and wsgi so that it's consistent with other projects

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
_MAKER = None
26
26
BASE = models.BASE
27
27
 
 
28
 
28
29
def configure_db(options):
29
30
    """
30
31
    Establish the database, create an engine if needed, and
40
41
                                pool_recycle=3600)
41
42
        register_models()
42
43
 
 
44
 
43
45
def get_session(autocommit=True, expire_on_commit=False):
44
46
    """Helper method to grab session"""
45
47
    global _MAKER, _ENGINE
50
52
                              expire_on_commit=expire_on_commit)
51
53
    return _MAKER()
52
54
 
 
55
 
53
56
def register_models():
54
57
    """Register Models and create properties"""
55
58
    global _ENGINE
56
59
    assert _ENGINE
57
60
    BASE.metadata.create_all(_ENGINE)
58
61
 
 
62
 
59
63
def unregister_models():
60
64
    """Unregister Models, useful clearing out data before testing"""
61
65
    global _ENGINE
62
66
    assert _ENGINE
63
67
    BASE.metadata.drop_all(_ENGINE)
64
68
 
 
69
 
65
70
def network_create(tenant_id, name):
66
71
    session = get_session()
67
72
    net = None
77
82
            session.flush()
78
83
    return net
79
84
 
 
85
 
80
86
def network_list(tenant_id):
81
87
    session = get_session()
82
88
    return session.query(models.Network).\
83
89
      filter_by(tenant_id=tenant_id).\
84
90
      all()
85
91
 
 
92
 
86
93
def network_get(net_id):
87
94
    session = get_session()
88
95
    try:
92
99
    except exc.NoResultFound:
93
100
        raise Exception("No net found with id = %s" % net_id)
94
101
 
 
102
 
95
103
def network_rename(net_id, tenant_id, new_name):
96
104
    session = get_session()
97
105
    try:
106
114
        return net
107
115
    raise Exception("A network with name \"%s\" already exists" % new_name)
108
116
 
 
117
 
109
118
def network_destroy(net_id):
110
119
    session = get_session()
111
120
    try:
118
127
    except exc.NoResultFound:
119
128
        raise Exception("No network found with id = %s" % net_id)
120
129
 
 
130
 
121
131
def port_create(net_id):
122
132
    session = get_session()
123
133
    with session.begin():
126
136
        session.flush()
127
137
        return port
128
138
 
 
139
 
129
140
def port_list(net_id):
130
141
    session = get_session()
131
142
    return session.query(models.Port).\
132
143
      filter_by(network_id=net_id).\
133
144
      all()
134
145
 
 
146
 
135
147
def port_get(port_id):
136
148
    session = get_session()
137
149
    try:
141
153
    except exc.NoResultFound:
142
154
        raise Exception("No port found with id = %s " % port_id)
143
155
 
 
156
 
144
157
def port_set_attachment(port_id, new_interface_id):
145
158
    session = get_session()
146
159
    ports = None
157
170
        session.flush()
158
171
        return port
159
172
    else:
160
 
        raise Exception("Port with attachment \"%s\" already exists" % (new_interface_id))
 
173
        raise Exception("Port with attachment \"%s\" already exists"
 
174
                        % (new_interface_id))
 
175
 
161
176
 
162
177
def port_destroy(port_id):
163
178
    session = get_session()
170
185
        return port
171
186
    except exc.NoResultFound:
172
187
        raise Exception("No port found with id = %s " % port_id)
173