summaryrefslogtreecommitdiffstats
path: root/nova/virt/baremetal/db/api.py
blob: 672f14486326d054d0c104fea58a75b5775d2369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2012 NTT DOCOMO, INC.
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""Defines interface for DB access.

The underlying driver is loaded as a :class:`LazyPluggable`.

Functions in this module are imported into the nova.virt.baremetal.db
namespace. Call these functions from nova.virt.baremetal.db namespace, not
the nova.virt.baremetal.db.api namespace.

All functions in this module return objects that implement a dictionary-like
interface. Currently, many of these objects are sqlalchemy objects that
implement a dictionary interface. However, a future goal is to have all of
these objects be simple dictionaries.


**Related Flags**

:baremetal_db_backend:  string to lookup in the list of LazyPluggable backends.
                        `sqlalchemy` is the only supported backend right now.

:[BAREMETAL] sql_connection: string specifying the sqlalchemy connection to
                             use, like: `sqlite:///var/lib/nova/nova.sqlite`.

"""

from oslo.config import cfg

from nova import utils

# NOTE(deva): we can't move baremetal_db_backend into an OptGroup yet
#             because utils.LazyPluggable doesn't support reading from
#             option groups. See bug #1093043.
db_opts = [
    cfg.StrOpt('db_backend',
               default='sqlalchemy',
               help='The backend to use for bare-metal database'),
    ]

baremetal_group = cfg.OptGroup(name='baremetal',
                               title='Baremetal Options')

CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(db_opts, baremetal_group)

IMPL = utils.LazyPluggable(
        'db_backend',
        config_group='baremetal',
        sqlalchemy='nova.virt.baremetal.db.sqlalchemy.api')


def bm_node_get_all(context, service_host=None):
    return IMPL.bm_node_get_all(context,
                                service_host=service_host)


def bm_node_find_free(context, service_host=None,
                      memory_mb=None, cpus=None, local_gb=None):
    return IMPL.bm_node_find_free(context,
                                  service_host=service_host,
                                  memory_mb=memory_mb,
                                  cpus=cpus,
                                  local_gb=local_gb)


def bm_node_get(context, bm_node_id):
    return IMPL.bm_node_get(context, bm_node_id)


def bm_node_get_by_instance_uuid(context, instance_uuid):
    return IMPL.bm_node_get_by_instance_uuid(context,
                                             instance_uuid)


def bm_node_create(context, values):
    return IMPL.bm_node_create(context, values)


def bm_node_destroy(context, bm_node_id):
    return IMPL.bm_node_destroy(context, bm_node_id)


def bm_node_update(context, bm_node_id, values):
    return IMPL.bm_node_update(context, bm_node_id, values)


def bm_node_set_uuid_safe(context, bm_node_id, uuid):
    return IMPL.bm_node_set_uuid_safe(context, bm_node_id, uuid)


def bm_pxe_ip_create(context, address, server_address):
    return IMPL.bm_pxe_ip_create(context, address, server_address)


def bm_pxe_ip_create_direct(context, bm_pxe_ip):
    return IMPL.bm_pxe_ip_create_direct(context, bm_pxe_ip)


def bm_pxe_ip_destroy(context, ip_id):
    return IMPL.bm_pxe_ip_destroy(context, ip_id)


def bm_pxe_ip_destroy_by_address(context, address):
    return IMPL.bm_pxe_ip_destroy_by_address(context, address)


def bm_pxe_ip_get_all(context):
    return IMPL.bm_pxe_ip_get_all(context)


def bm_pxe_ip_get(context, ip_id):
    return IMPL.bm_pxe_ip_get(context, ip_id)


def bm_pxe_ip_get_by_bm_node_id(context, bm_node_id):
    return IMPL.bm_pxe_ip_get_by_bm_node_id(context, bm_node_id)


def bm_pxe_ip_associate(context, bm_node_id):
    return IMPL.bm_pxe_ip_associate(context, bm_node_id)


def bm_pxe_ip_disassociate(context, bm_node_id):
    return IMPL.bm_pxe_ip_disassociate(context, bm_node_id)


def bm_interface_get(context, if_id):
    return IMPL.bm_interface_get(context, if_id)


def bm_interface_get_all(context):
    return IMPL.bm_interface_get_all(context)


def bm_interface_destroy(context, if_id):
    return IMPL.bm_interface_destroy(context, if_id)


def bm_interface_create(context, bm_node_id, address, datapath_id, port_no):
    return IMPL.bm_interface_create(context, bm_node_id, address,
                                    datapath_id, port_no)


def bm_interface_set_vif_uuid(context, if_id, vif_uuid):
    return IMPL.bm_interface_set_vif_uuid(context, if_id, vif_uuid)


def bm_interface_get_by_vif_uuid(context, vif_uuid):
    return IMPL.bm_interface_get_by_vif_uuid(context, vif_uuid)


def bm_interface_get_all_by_bm_node_id(context, bm_node_id):
    return IMPL.bm_interface_get_all_by_bm_node_id(context, bm_node_id)


def bm_deployment_create(context, key, image_path, pxe_config_path, root_mb,
                         swap_mb):
    return IMPL.bm_deployment_create(context, key, image_path,
                                     pxe_config_path, root_mb, swap_mb)


def bm_deployment_get(context, dep_id):
    return IMPL.bm_deployment_get(context, dep_id)


def bm_deployment_destroy(context, dep_id):
    return IMPL.bm_deployment_destroy(context, dep_id)