API: inconsistent network endpoint naming
Naming of network endpoints should be consistent: /networks /net_interfaces -> /network_interfaces /netdevices -> /network_devices Also corresponding classes, methods and DB table names should follow the changed endpoint naming. Closes Bug: 1643356 Change-Id: Ib2b9d8fe11145944d050b55f2f965f1a90002639
This commit is contained in:
parent
68a49caa75
commit
912e335f65
|
@ -87,7 +87,7 @@ class NetworksVariables(base.Resource):
|
|||
return None, 204, None
|
||||
|
||||
|
||||
class NetDevices(base.Resource):
|
||||
class NetworkDevices(base.Resource):
|
||||
"""Controller for Network Device resources."""
|
||||
|
||||
@base.http_codes
|
||||
|
@ -97,7 +97,7 @@ class NetDevices(base.Resource):
|
|||
'device_type', 'region_id', 'vars'])
|
||||
def get(self, context, region_id, filters):
|
||||
"""Get all network devices for this region."""
|
||||
devices_obj = dbapi.netdevices_get_by_region(
|
||||
devices_obj = dbapi.network_devices_get_by_region(
|
||||
context, region_id, filters)
|
||||
return jsonutils.to_primitive(devices_obj), 200, None
|
||||
|
||||
|
@ -106,12 +106,12 @@ class NetDevices(base.Resource):
|
|||
"""Create a new network device."""
|
||||
context = request.environ.get('context')
|
||||
json = util.copy_project_id_into_json(context, g.json)
|
||||
obj = dbapi.netdevices_create(context, json)
|
||||
obj = dbapi.network_devices_create(context, json)
|
||||
device = jsonutils.to_primitive(obj)
|
||||
return device, 200, None
|
||||
|
||||
|
||||
class NetDeviceById(base.Resource):
|
||||
class NetworkDeviceById(base.Resource):
|
||||
"""Controller for Network Devices by ID."""
|
||||
|
||||
@base.http_codes
|
||||
|
@ -119,7 +119,7 @@ class NetDeviceById(base.Resource):
|
|||
"""Get network device by given id"""
|
||||
context = request.environ.get('context')
|
||||
resolved_values = g.args["resolved-values"]
|
||||
obj = dbapi.netdevices_get_by_id(context, id)
|
||||
obj = dbapi.network_devices_get_by_id(context, id)
|
||||
if resolved_values:
|
||||
obj.vars = obj.resolved
|
||||
else:
|
||||
|
@ -131,25 +131,25 @@ class NetDeviceById(base.Resource):
|
|||
def put(self, id):
|
||||
"""Update existing device values."""
|
||||
context = request.environ.get('context')
|
||||
net_obj = dbapi.netdevices_update(context, id, request.json)
|
||||
net_obj = dbapi.network_devices_update(context, id, request.json)
|
||||
return jsonutils.to_primitive(net_obj), 200, None
|
||||
|
||||
@base.http_codes
|
||||
def delete(self, id):
|
||||
"""Delete existing network device."""
|
||||
context = request.environ.get('context')
|
||||
dbapi.netdevices_delete(context, id)
|
||||
dbapi.network_devices_delete(context, id)
|
||||
return None, 204, None
|
||||
|
||||
|
||||
class NetDevicesVariables(base.Resource):
|
||||
class NetworkDevicesVariables(base.Resource):
|
||||
"""Controller for network device variables endpoints."""
|
||||
|
||||
@base.http_codes
|
||||
def get(self, id):
|
||||
"""Get variables for the given network."""
|
||||
context = request.environ.get('context')
|
||||
obj = dbapi.netdevice_get_by_id(context, id)
|
||||
obj = dbapi.network_devices_get_by_id(context, id)
|
||||
resp = {"variables": jsonutils.to_primitive(obj.variables)}
|
||||
return resp, 200, None
|
||||
|
||||
|
@ -157,7 +157,7 @@ class NetDevicesVariables(base.Resource):
|
|||
def put(self, id):
|
||||
""""Update device variables, or create if it does not exist."""
|
||||
context = request.environ.get('context')
|
||||
obj = dbapi.netdevice_variables_update(context, id, request.json)
|
||||
obj = dbapi.network_devices_variables_update(context, id, request.json)
|
||||
resp = {"variables": jsonutils.to_primitive(obj.variables)}
|
||||
return resp, 200, None
|
||||
|
||||
|
@ -165,18 +165,18 @@ class NetDevicesVariables(base.Resource):
|
|||
def delete(self, id):
|
||||
"""Delete network device variables."""
|
||||
context = request.environ.get('context')
|
||||
dbapi.netdevice_variables_delete(context, id, request.json)
|
||||
dbapi.network_devices_variables_delete(context, id, request.json)
|
||||
return None, 204, None
|
||||
|
||||
|
||||
class NetDeviceLabels(base.Resource):
|
||||
class NetworkDeviceLabels(base.Resource):
|
||||
"""Controller for Netowrk Device Labels."""
|
||||
|
||||
@base.http_codes
|
||||
def get(self, id):
|
||||
"""Get labels for given network device."""
|
||||
context = request.environ.get('context')
|
||||
obj = dbapi.netdevices_get_by_id(context, id)
|
||||
obj = dbapi.network_devices_get_by_id(context, id)
|
||||
response = {"labels": list(obj.labels)}
|
||||
return response, 200, None
|
||||
|
||||
|
@ -184,7 +184,7 @@ class NetDeviceLabels(base.Resource):
|
|||
def put(self, id):
|
||||
"""Update existing device label. Adds if it does not exist."""
|
||||
context = request.environ.get('context')
|
||||
resp = dbapi.netdevices_labels_update(context, id, request.json)
|
||||
resp = dbapi.network_devices_labels_update(context, id, request.json)
|
||||
response = {"labels": list(resp.labels)}
|
||||
return response, 200, None
|
||||
|
||||
|
@ -192,11 +192,11 @@ class NetDeviceLabels(base.Resource):
|
|||
def delete(self, id):
|
||||
"""Delete device label(s)."""
|
||||
context = request.environ.get('context')
|
||||
dbapi.netdevices_labels_delete(context, id)
|
||||
dbapi.network_devices_labels_delete(context, id)
|
||||
return None, 204, None
|
||||
|
||||
|
||||
class NetInterfaces(base.Resource):
|
||||
class NetworkInterfaces(base.Resource):
|
||||
"""Controller for Netowrk Interfaces."""
|
||||
|
||||
@base.http_codes
|
||||
|
@ -206,7 +206,7 @@ class NetInterfaces(base.Resource):
|
|||
'device_id', 'vars'])
|
||||
def get(self, context, device_id, filters):
|
||||
"""Get all network interfaces for a given network device."""
|
||||
interfaces_obj = dbapi.net_interfaces_get_by_device(
|
||||
interfaces_obj = dbapi.network_interfaces_get_by_device(
|
||||
context, device_id, filters)
|
||||
return jsonutils.to_primitive(interfaces_obj), 200, None
|
||||
|
||||
|
@ -215,18 +215,18 @@ class NetInterfaces(base.Resource):
|
|||
"""Create a new network interface."""
|
||||
context = request.environ.get('context')
|
||||
json = util.copy_project_id_into_json(context, g.json)
|
||||
obj = dbapi.net_interfaces_create(context, json)
|
||||
obj = dbapi.network_interfaces_create(context, json)
|
||||
interface = jsonutils.to_primitive(obj)
|
||||
return interface, 200, None
|
||||
|
||||
|
||||
class NetInterfaceById(base.Resource):
|
||||
class NetworkInterfaceById(base.Resource):
|
||||
|
||||
@base.http_codes
|
||||
def get(self, id):
|
||||
"""Get network interface by given id"""
|
||||
context = request.environ.get('context')
|
||||
obj = dbapi.net_interface_get_by_id(context, id)
|
||||
obj = dbapi.network_interfaces_get_by_id(context, id)
|
||||
interface = jsonutils.to_primitive(obj)
|
||||
interface['variables'] = jsonutils.to_primitive(obj.variables)
|
||||
return interface, 200, None
|
||||
|
@ -234,12 +234,12 @@ class NetInterfaceById(base.Resource):
|
|||
def put(self, id):
|
||||
"""Update existing network interface values."""
|
||||
context = request.environ.get('context')
|
||||
net_obj = dbapi.net_interfaces_update(context, id, request.json)
|
||||
net_obj = dbapi.network_interfaces_update(context, id, request.json)
|
||||
return jsonutils.to_primitive(net_obj), 200, None
|
||||
|
||||
@base.http_codes
|
||||
def delete(self, id):
|
||||
"""Delete existing network interface."""
|
||||
context = request.environ.get('context')
|
||||
dbapi.net_interfaces_delete(context, id)
|
||||
dbapi.network_interfaces_delete(context, id)
|
||||
return None, 204, None
|
||||
|
|
|
@ -63,22 +63,22 @@ routes = [
|
|||
dict(resource=networks.NetworkById,
|
||||
urls=['/networks/<id>'],
|
||||
endpoint='networks_id'),
|
||||
dict(resource=networks.NetInterfaces,
|
||||
urls=['/net_interfaces'],
|
||||
endpoint='net_interfaces'),
|
||||
dict(resource=networks.NetInterfaceById,
|
||||
urls=['/net_interfaces/<id>'],
|
||||
endpoint='net_interfaces_id'),
|
||||
dict(resource=networks.NetDevices,
|
||||
urls=['/netdevices'],
|
||||
endpoint='netdevices'),
|
||||
dict(resource=networks.NetDeviceById,
|
||||
urls=['/netdevices/<id>'],
|
||||
endpoint='netdevices_id'),
|
||||
dict(resource=networks.NetDevicesVariables,
|
||||
urls=['/netdevices/<id>/variables'],
|
||||
endpoint='netdevices_variables'),
|
||||
dict(resource=networks.NetDeviceLabels,
|
||||
urls=['/netdevices/<id>/labels'],
|
||||
endpoint='netdevices_labels'),
|
||||
dict(resource=networks.NetworkInterfaces,
|
||||
urls=['/network_interfaces'],
|
||||
endpoint='network_interfaces'),
|
||||
dict(resource=networks.NetworkInterfaceById,
|
||||
urls=['/network_interfaces/<id>'],
|
||||
endpoint='network_interfaces_id'),
|
||||
dict(resource=networks.NetworkDevices,
|
||||
urls=['/network_devices'],
|
||||
endpoint='network_devices'),
|
||||
dict(resource=networks.NetworkDeviceById,
|
||||
urls=['/network_devices/<id>'],
|
||||
endpoint='network_devices_id'),
|
||||
dict(resource=networks.NetworkDevicesVariables,
|
||||
urls=['/network_devices/<id>/variables'],
|
||||
endpoint='network_devices_variables'),
|
||||
dict(resource=networks.NetworkDeviceLabels,
|
||||
urls=['/network_devices/<id>/labels'],
|
||||
endpoint='network_devices_labels'),
|
||||
]
|
||||
|
|
|
@ -380,7 +380,7 @@ DefinitionNetworkId = {
|
|||
},
|
||||
}
|
||||
|
||||
DefinitionNetInterface = {
|
||||
DefinitionNetworkInterface = {
|
||||
"discriminator": "name",
|
||||
"required": [
|
||||
"name",
|
||||
|
@ -437,7 +437,7 @@ DefinitionNetInterface = {
|
|||
},
|
||||
}
|
||||
|
||||
DefinitionNetInterfaceId = {
|
||||
DefinitionNetworkInterfaceId = {
|
||||
"discriminator": "name",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -487,7 +487,7 @@ DefinitionNetInterfaceId = {
|
|||
},
|
||||
}
|
||||
|
||||
DefinitionNetDevice = {
|
||||
DefinitionNetworkDevice = {
|
||||
"discriminator": "hostname",
|
||||
"required": [
|
||||
"hostname",
|
||||
|
@ -540,7 +540,7 @@ DefinitionNetDevice = {
|
|||
},
|
||||
}
|
||||
|
||||
DefinitionNetDeviceId = {
|
||||
DefinitionNetworkDeviceId = {
|
||||
"discriminator": "hostname",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -841,7 +841,7 @@ validators = {
|
|||
("users", "POST"): {
|
||||
"json": DefinitionUser,
|
||||
},
|
||||
("netdevices", "GET"): {
|
||||
("network_devices", "GET"): {
|
||||
"args": {
|
||||
"properties": {
|
||||
"id": {
|
||||
|
@ -882,7 +882,7 @@ validators = {
|
|||
},
|
||||
},
|
||||
},
|
||||
("netdevices_id", "GET"): {
|
||||
("network_devices_id", "GET"): {
|
||||
"args": {
|
||||
"properties": {
|
||||
"resolved-values": {
|
||||
|
@ -892,7 +892,7 @@ validators = {
|
|||
},
|
||||
},
|
||||
},
|
||||
("netdevices_id_variables", "PUT"): {
|
||||
("network_devices_id_variables", "PUT"): {
|
||||
"json": DefinitionsData
|
||||
},
|
||||
("networks_id", "PUT"): {
|
||||
|
@ -919,7 +919,7 @@ validators = {
|
|||
},
|
||||
},
|
||||
},
|
||||
("netdevices_id", "PUT"): {
|
||||
("network_devices_id", "PUT"): {
|
||||
"args": {
|
||||
"properties": {
|
||||
"ip_address": {
|
||||
|
@ -943,13 +943,13 @@ validators = {
|
|||
},
|
||||
},
|
||||
},
|
||||
("netdevices", "POST"): {
|
||||
"json": DefinitionNetDevice,
|
||||
("network_devices", "POST"): {
|
||||
"json": DefinitionNetworkDevice,
|
||||
},
|
||||
("netdevices_labels", "PUT"): {
|
||||
("network_devices_labels", "PUT"): {
|
||||
"json": DefinitionsLabel,
|
||||
},
|
||||
("net_interfaces", "GET"): {
|
||||
("network_interfaces", "GET"): {
|
||||
"args": {
|
||||
"required": [
|
||||
"device_id",
|
||||
|
@ -978,10 +978,10 @@ validators = {
|
|||
},
|
||||
},
|
||||
},
|
||||
("net_interfaces", "POST"): {
|
||||
"json": DefinitionNetInterface,
|
||||
("network_interfaces", "POST"): {
|
||||
"json": DefinitionNetworkInterface,
|
||||
},
|
||||
("net_interfaces_id", "PUT"): {
|
||||
("network_interfaces_id", "PUT"): {
|
||||
"args": {
|
||||
"properties": {
|
||||
"name": {
|
||||
|
@ -1584,11 +1584,11 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices", "GET"): {
|
||||
("network_devices", "GET"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": {
|
||||
"items": DefinitionNetDeviceId,
|
||||
"items": DefinitionNetworkDeviceId,
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
|
@ -1605,10 +1605,10 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_id", "GET"): {
|
||||
("network_devices_id", "GET"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionNetDeviceId,
|
||||
"schema": DefinitionNetworkDeviceId,
|
||||
},
|
||||
400: {
|
||||
"headers": None,
|
||||
|
@ -1623,7 +1623,7 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_labels", "GET"): {
|
||||
("network_devices_labels", "GET"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionsLabel,
|
||||
|
@ -1641,7 +1641,7 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_labels", "PUT"): {
|
||||
("network_devices_labels", "PUT"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionsLabel,
|
||||
|
@ -1659,10 +1659,10 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_id", "PUT"): {
|
||||
("network_devices_id", "PUT"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionNetDeviceId,
|
||||
"schema": DefinitionNetworkDeviceId,
|
||||
},
|
||||
400: {
|
||||
"headers": None,
|
||||
|
@ -1677,7 +1677,7 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_id_variables", "PUT"): {
|
||||
("network_devices_id_variables", "PUT"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": None,
|
||||
|
@ -1695,7 +1695,7 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("netdevices_id_variables", "DELETE"): {
|
||||
("network_devices_id_variables", "DELETE"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": None,
|
||||
|
@ -1806,11 +1806,11 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("net_interfaces", "GET"): {
|
||||
("network_interfaces", "GET"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": {
|
||||
"items": DefinitionNetInterface,
|
||||
"items": DefinitionNetworkInterface,
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
|
@ -1827,10 +1827,10 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("net_interfaces_id", "GET"): {
|
||||
("network_interfaces_id", "GET"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionNetInterfaceId,
|
||||
"schema": DefinitionNetworkInterfaceId,
|
||||
},
|
||||
400: {
|
||||
"headers": None,
|
||||
|
@ -1845,10 +1845,10 @@ filters = {
|
|||
"schema": None,
|
||||
},
|
||||
},
|
||||
("net_interfaces_id", "PUT"): {
|
||||
("network_interfaces_id", "PUT"): {
|
||||
200: {
|
||||
"headers": None,
|
||||
"schema": DefinitionNetInterfaceId,
|
||||
"schema": DefinitionNetworkInterfaceId,
|
||||
},
|
||||
400: {
|
||||
"headers": None,
|
||||
|
@ -1889,8 +1889,8 @@ scopes = {
|
|||
("users", "GET"): [],
|
||||
("users", "POST"): [],
|
||||
("users_id", "GET"): [],
|
||||
("netdevices_id_variables", "PUT"): [],
|
||||
("netdevices_id_variables", "DELETE"): [],
|
||||
("network_devices_id_variables", "PUT"): [],
|
||||
("network_devices_id_variables", "DELETE"): [],
|
||||
("networks_id_variables", "PUT"): [],
|
||||
("networks_id_variables", "DELETE"): [],
|
||||
}
|
||||
|
|
|
@ -263,71 +263,75 @@ def networks_variables_delete(context, network_id, data):
|
|||
return IMPL.networks_variables_delete(context, network_id, data)
|
||||
|
||||
|
||||
def netdevices_get_by_region(context, region_id, filters):
|
||||
def network_devices_get_by_region(context, region_id, filters):
|
||||
"""Get all network devices for the given region id."""
|
||||
return IMPL.netdevices_get_by_region(context, region_id, filters)
|
||||
return IMPL.network_devices_get_by_region(context, region_id, filters)
|
||||
|
||||
|
||||
def netdevices_get_by_id(context, netdevice_id):
|
||||
def network_devices_get_by_id(context, network_device_id):
|
||||
"""Get a given network device by its id."""
|
||||
return IMPL.netdevices_get_by_id(context, netdevice_id)
|
||||
return IMPL.network_devices_get_by_id(context, network_device_id)
|
||||
|
||||
|
||||
def netdevices_create(context, values):
|
||||
def network_devices_create(context, values):
|
||||
"""Create a new network device."""
|
||||
return IMPL.netdevices_create(context, values)
|
||||
return IMPL.network_devices_create(context, values)
|
||||
|
||||
|
||||
def netdevices_update(context, netdevice_id, values):
|
||||
def network_devices_update(context, network_device_id, values):
|
||||
"""Update an existing network device"""
|
||||
return IMPL.netdevices_update(context, netdevice_id, values)
|
||||
return IMPL.network_devices_update(context, network_device_id, values)
|
||||
|
||||
|
||||
def netdevices_delete(context, netdevice_id):
|
||||
def network_devices_delete(context, network_device_id):
|
||||
"""Delete existing network device."""
|
||||
return IMPL.netdevices_delete(context, netdevice_id)
|
||||
return IMPL.network_devices_delete(context, network_device_id)
|
||||
|
||||
|
||||
def netdevices_variables_delete(context, netdevice_id, data):
|
||||
def network_devices_variables_delete(context, network_device_id, data):
|
||||
"""Delete network device variables."""
|
||||
return IMPL.netdevices_variables_delete(context, netdevice_id, data)
|
||||
return IMPL.network_devices_variables_delete(context, network_device_id,
|
||||
data)
|
||||
|
||||
|
||||
def netdevices_variables_update(context, netdevice_id, data):
|
||||
def network_devices_variables_update(context, network_device_id, data):
|
||||
"""Update network device variables."""
|
||||
return IMPL.netdevices_variables_update(context, netdevice_id, data)
|
||||
return IMPL.network_devices_variables_update(context, network_device_id,
|
||||
data)
|
||||
|
||||
|
||||
def netdevices_labels_delete(context, netdevice_id, labels):
|
||||
def network_devices_labels_delete(context, network_device_id, labels):
|
||||
"""Delete network device labels."""
|
||||
return IMPL.netdevices_labels_delete(context, netdevice_id, labels)
|
||||
return IMPL.network_devices_labels_delete(context, network_device_id,
|
||||
labels)
|
||||
|
||||
|
||||
def netdevices_labels_update(context, netdevice_id, labels):
|
||||
def network_devices_labels_update(context, network_device_id, labels):
|
||||
"""Update network device labels."""
|
||||
return IMPL.netdevices_labels_update(context, netdevice_id, labels)
|
||||
return IMPL.network_devices_labels_update(context, network_device_id,
|
||||
labels)
|
||||
|
||||
|
||||
def net_interfaces_get_by_device(context, device_id, filters):
|
||||
def network_interfaces_get_by_device(context, device_id, filters):
|
||||
"""Get all network interfaces for the given device."""
|
||||
return IMPL.net_interfaces_get_by_device(context, device_id, filters)
|
||||
return IMPL.network_interfaces_get_by_device(context, device_id, filters)
|
||||
|
||||
|
||||
def net_interfaces_get_by_id(context, interface_id):
|
||||
def network_interfaces_get_by_id(context, interface_id):
|
||||
"""Get a given network interface by its id."""
|
||||
return IMPL.net_interfaces_get_by_id(context, interface_id)
|
||||
return IMPL.network_interfaces_get_by_id(context, interface_id)
|
||||
|
||||
|
||||
def net_interfaces_create(context, values):
|
||||
def network_interfaces_create(context, values):
|
||||
"""Create a new network interface."""
|
||||
return IMPL.net_interfaces_create(context, values)
|
||||
return IMPL.network_interfaces_create(context, values)
|
||||
|
||||
|
||||
def net_interfaces_update(context, interface_id, values):
|
||||
def network_interfaces_update(context, interface_id, values):
|
||||
"""Update an existing network interface."""
|
||||
return IMPL.net_interfaces_update(context, interface_id, values)
|
||||
return IMPL.network_interfaces_update(context, interface_id, values)
|
||||
|
||||
|
||||
def net_interfaces_delete(context, interface_id):
|
||||
def network_interfaces_delete(context, interface_id):
|
||||
"""Delete existing network interface."""
|
||||
return IMPL.net_interfaces_delete(context, interface_id)
|
||||
return IMPL.network_interfaces_delete(context, interface_id)
|
||||
|
|
|
@ -4,7 +4,7 @@ To create alembic migrations use:
|
|||
$ craton-dbsync --config-file=craton.conf revision --message "revision description" --autogenerate
|
||||
|
||||
Stamp db with most recent migration version, without actually running migrations
|
||||
$ craton-dbsync --config-file=crton.conf stamp head
|
||||
$ craton-dbsync --config-file=craton.conf stamp head
|
||||
|
||||
Upgrade can be performed by:
|
||||
$ craton-dbsync --config-file=craton.conf upgrade
|
||||
|
|
|
@ -215,7 +215,7 @@ def upgrade():
|
|||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table(
|
||||
'net_devices',
|
||||
'network_devices',
|
||||
sa.Column('id', sa.Integer, nullable=False),
|
||||
sa.Column('model_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('os_version', sa.String(length=255), nullable=True),
|
||||
|
@ -236,7 +236,7 @@ def upgrade():
|
|||
'fk_labels_devices')
|
||||
)
|
||||
op.create_table(
|
||||
'net_interfaces',
|
||||
'network_interfaces',
|
||||
sa.Column('created_at', sa.DateTime, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime, nullable=True),
|
||||
sa.Column('id', sa.Integer, nullable=False),
|
||||
|
@ -263,13 +263,13 @@ def upgrade():
|
|||
sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ),
|
||||
sa.ForeignKeyConstraint(
|
||||
['variable_association_id'], ['variable_association.id'],
|
||||
'fk_net_interfaces_variable_association')
|
||||
'fk_network_interfaces_variable_association')
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('net_interfaces')
|
||||
op.drop_table('net_devices')
|
||||
op.drop_table('network_interfaces')
|
||||
op.drop_table('network_devices')
|
||||
op.drop_table('hosts')
|
||||
op.drop_index(op.f('ix_networks_region_id'), table_name='networks')
|
||||
op.drop_index(op.f('ix_networks_project_id'), table_name='networks')
|
||||
|
|
|
@ -766,12 +766,12 @@ def networks_variables_delete(context, network_id, data):
|
|||
return ref
|
||||
|
||||
|
||||
def netdevices_get_by_region(context, region_id, filters):
|
||||
def network_devices_get_by_region(context, region_id, filters):
|
||||
"""Get all network devices for the given region."""
|
||||
devices = with_polymorphic(models.Device, [models.NetDevice])
|
||||
devices = with_polymorphic(models.Device, [models.NetworkDevice])
|
||||
query = model_query(context, devices, project_only=True)
|
||||
query = query.filter_by(region_id=region_id)
|
||||
query = query.filter_by(type='net_devices')
|
||||
query = query.filter_by(type='network_devices')
|
||||
|
||||
if "vars" in filters:
|
||||
query = add_var_filters_to_query(query, filters)
|
||||
|
@ -780,12 +780,12 @@ def netdevices_get_by_region(context, region_id, filters):
|
|||
return result
|
||||
|
||||
|
||||
def netdevices_get_by_id(context, netdevice_id):
|
||||
def network_devices_get_by_id(context, network_device_id):
|
||||
"""Get a given network device by its id."""
|
||||
devices = with_polymorphic(models.Device, [models.NetDevice])
|
||||
devices = with_polymorphic(models.Device, [models.NetworkDevice])
|
||||
query = model_query(context, devices, project_only=True)
|
||||
query = query.filter_by(type='net_devices')
|
||||
query = query.filter_by(id=netdevice_id)
|
||||
query = query.filter_by(type='network_devices')
|
||||
query = query.filter_by(id=network_device_id)
|
||||
try:
|
||||
result = query.one()
|
||||
except sa_exc.NoResultFound:
|
||||
|
@ -794,68 +794,70 @@ def netdevices_get_by_id(context, netdevice_id):
|
|||
return result
|
||||
|
||||
|
||||
def netdevices_create(context, values):
|
||||
def network_devices_create(context, values):
|
||||
"""Create a new network device."""
|
||||
session = get_session()
|
||||
device = models.NetDevice()
|
||||
device = models.NetworkDevice()
|
||||
with session.begin():
|
||||
device.update(values)
|
||||
device.save(session)
|
||||
return device
|
||||
|
||||
|
||||
def netdevices_update(context, netdevice_id, values):
|
||||
def network_devices_update(context, network_device_id, values):
|
||||
"""Update existing network device"""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
device = with_polymorphic(models.Device, '*')
|
||||
query = model_query(context, device, session=session,
|
||||
project_only=True)
|
||||
query = query.filter_by(type='net_devices')
|
||||
query = query.filter_by(id=netdevice_id)
|
||||
netdevice_ref = query.with_for_update().one()
|
||||
netdevice_ref.update(values)
|
||||
netdevice_ref.save(session)
|
||||
return netdevice_ref
|
||||
query = query.filter_by(type='network_devices')
|
||||
query = query.filter_by(id=network_device_id)
|
||||
network_device_ref = query.with_for_update().one()
|
||||
network_device_ref.update(values)
|
||||
network_device_ref.save(session)
|
||||
return network_device_ref
|
||||
|
||||
|
||||
def netdevices_delete(context, netdevice_id):
|
||||
def network_devices_delete(context, network_device_id):
|
||||
"""Delete existing network device."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
device = with_polymorphic(models.Device, '*')
|
||||
query = model_query(context, device, session=session,
|
||||
project_only=True)
|
||||
query = query.filter_by(type='net_devices')
|
||||
query = query.filter_by(id=netdevice_id)
|
||||
query = query.filter_by(type='network_devices')
|
||||
query = query.filter_by(id=network_device_id)
|
||||
query.delete()
|
||||
|
||||
|
||||
def netdevices_labels_update(context, device_id, labels):
|
||||
def network_devices_labels_update(context, device_id, labels):
|
||||
"""Update labels for a network device. Add the label if it is not present
|
||||
in host labels list, otherwise do nothing."""
|
||||
return _device_labels_update(context, 'net_devices', device_id, labels)
|
||||
return _device_labels_update(context, 'network_devices', device_id, labels)
|
||||
|
||||
|
||||
def netdevices_labels_delete(context, device_id, labels):
|
||||
def network_devices_labels_delete(context, device_id, labels):
|
||||
"""Delete labels from the network device labels list if it matches
|
||||
the given label in the query, otherwise do nothing."""
|
||||
return _device_labels_delete(context, 'net_devices', device_id, labels)
|
||||
return _device_labels_delete(context, 'network_devices', device_id, labels)
|
||||
|
||||
|
||||
def netdevices_variables_update(context, device_id, data):
|
||||
def network_devices_variables_update(context, device_id, data):
|
||||
"""Update/create network device variables."""
|
||||
return _device_variables_update(context, 'net_devices', device_id, data)
|
||||
return _device_variables_update(context, 'network_devices',
|
||||
device_id, data)
|
||||
|
||||
|
||||
def netdevices_variables_delete(context, device_id, data):
|
||||
def network_devices_variables_delete(context, device_id, data):
|
||||
"""Delete the existing key from network device variables."""
|
||||
return _device_variables_delete(context, 'net_devices', device_id, data)
|
||||
return _device_variables_delete(context, 'network_devices',
|
||||
device_id, data)
|
||||
|
||||
|
||||
def net_interfaces_get_by_device(context, device_id, filters):
|
||||
def network_interfaces_get_by_device(context, device_id, filters):
|
||||
"""Get all network interfaces for the given host."""
|
||||
query = model_query(context, models.NetInterface, project_only=True)
|
||||
query = model_query(context, models.NetworkInterface, project_only=True)
|
||||
query = query.filter_by(device_id=device_id)
|
||||
|
||||
if "id" in filters:
|
||||
|
@ -868,9 +870,9 @@ def net_interfaces_get_by_device(context, device_id, filters):
|
|||
return query.all()
|
||||
|
||||
|
||||
def net_interfaces_get_by_id(context, interface_id):
|
||||
def network_interfaces_get_by_id(context, interface_id):
|
||||
"""Get a given network interface by its id."""
|
||||
query = model_query(context, models.NetInterface, project_only=True)
|
||||
query = model_query(context, models.NetworkInterface, project_only=True)
|
||||
query = query.filter_by(id=interface_id)
|
||||
try:
|
||||
result = query.one()
|
||||
|
@ -880,34 +882,34 @@ def net_interfaces_get_by_id(context, interface_id):
|
|||
return result
|
||||
|
||||
|
||||
def net_interfaces_create(context, values):
|
||||
def network_interfaces_create(context, values):
|
||||
"""Create a new network interface."""
|
||||
session = get_session()
|
||||
interface = models.NetInterface()
|
||||
interface = models.NetworkInterface()
|
||||
with session.begin():
|
||||
interface.update(values)
|
||||
interface.save(session)
|
||||
return interface
|
||||
|
||||
|
||||
def net_interfaces_update(context, interface_id, values):
|
||||
def network_interfaces_update(context, interface_id, values):
|
||||
"""Update an existing network interface."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
query = model_query(context, models.NetInterface, session=session,
|
||||
query = model_query(context, models.NetworkInterface, session=session,
|
||||
project_only=True)
|
||||
query = query.filter_by(id=interface_id)
|
||||
net_interface_ref = query.with_for_update().one()
|
||||
net_interface_ref.update(values)
|
||||
net_interface_ref.save(session)
|
||||
return net_interface_ref
|
||||
network_interface_ref = query.with_for_update().one()
|
||||
network_interface_ref.update(values)
|
||||
network_interface_ref.save(session)
|
||||
return network_interface_ref
|
||||
|
||||
|
||||
def net_interfaces_delete(context, interface_id):
|
||||
def network_interfaces_delete(context, interface_id):
|
||||
"""Delete existing network interface."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
query = model_query(context, models.NetInterface, session=session,
|
||||
query = model_query(context, models.NetworkInterface, session=session,
|
||||
project_only=True)
|
||||
query = query.filter_by(id=interface_id)
|
||||
query.delete()
|
||||
|
|
|
@ -344,7 +344,7 @@ class Device(Base, VariableMixin):
|
|||
cascade='all, delete-orphan', lazy='joined')
|
||||
labels = association_proxy('related_labels', 'label')
|
||||
access_secret = relationship('AccessSecret', back_populates='devices')
|
||||
interfaces = relationship('NetInterface', back_populates='device')
|
||||
interfaces = relationship('NetworkInterface', back_populates='device')
|
||||
children = relationship(
|
||||
'Device', backref=backref('parent', remote_side=[id]))
|
||||
|
||||
|
@ -384,8 +384,8 @@ class Host(Device):
|
|||
}
|
||||
|
||||
|
||||
class NetInterface(Base):
|
||||
__tablename__ = 'net_interfaces'
|
||||
class NetworkInterface(Base):
|
||||
__tablename__ = 'network_interfaces'
|
||||
__table_args__ = (
|
||||
UniqueConstraint("device_id", "name",
|
||||
name="uq_netinter0deviceid0name"),
|
||||
|
@ -433,14 +433,14 @@ class Network(Base, VariableMixin):
|
|||
UUIDType(binary=False), ForeignKey('projects.id'), index=True,
|
||||
nullable=False)
|
||||
|
||||
devices = relationship('NetInterface', back_populates='network')
|
||||
devices = relationship('NetworkInterface', back_populates='network')
|
||||
region = relationship('Region', back_populates='networks')
|
||||
cell = relationship('Cell', back_populates='networks')
|
||||
project = relationship('Project', back_populates='networks')
|
||||
|
||||
|
||||
class NetDevice(Device):
|
||||
__tablename__ = 'net_devices'
|
||||
class NetworkDevice(Device):
|
||||
__tablename__ = 'network_devices'
|
||||
id = Column(Integer, ForeignKey('devices.id'), primary_key=True)
|
||||
hostname = Device.name
|
||||
# network device specific properties
|
||||
|
@ -449,7 +449,7 @@ class NetDevice(Device):
|
|||
vlans = Column(JSONType)
|
||||
|
||||
__mapper_args__ = {
|
||||
'polymorphic_identity': 'net_devices',
|
||||
'polymorphic_identity': 'network_devices',
|
||||
'inherit_condition': (id == Device.id)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ device1 = {"hostname": "switch1",
|
|||
"device_type": "switch",
|
||||
"ip_address": "192.168.1.1"}
|
||||
|
||||
net_interface1 = {"device_id": 1,
|
||||
"project_id": project_id1,
|
||||
"name": "eth1",
|
||||
"ip_address": "192.168.0.2",
|
||||
"interface_type": "ethernet"}
|
||||
network_interface1 = {"device_id": 1,
|
||||
"project_id": project_id1,
|
||||
"name": "eth1",
|
||||
"ip_address": "192.168.0.2",
|
||||
"interface_type": "ethernet"}
|
||||
|
||||
|
||||
class NetworksDBTestCase(base.DBTestCase):
|
||||
|
@ -88,122 +88,127 @@ class NetworksDBTestCase(base.DBTestCase):
|
|||
|
||||
class NetworkDevicesDBTestCase(base.DBTestCase):
|
||||
|
||||
def test_netdevices_create(self):
|
||||
def test_network_devices_create(self):
|
||||
try:
|
||||
dbapi.netdevices_create(self.context, device1)
|
||||
dbapi.network_devices_create(self.context, device1)
|
||||
except Exception:
|
||||
self.fail("Network device create raised unexpected exception")
|
||||
|
||||
def test_netdevice_get_all(self):
|
||||
dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_get_all(self):
|
||||
dbapi.network_devices_create(self.context, device1)
|
||||
filters = {}
|
||||
res = dbapi.netdevices_get_by_region(self.context,
|
||||
device1['region_id'],
|
||||
filters)
|
||||
res = dbapi.network_devices_get_by_region(self.context,
|
||||
device1['region_id'],
|
||||
filters)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['hostname'], 'switch1')
|
||||
|
||||
def test_netdevices_get_by_id(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
res = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
def test_network_devices_get_by_id(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
res = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(res.hostname, 'switch1')
|
||||
|
||||
def test_netdevices_get_by_filter_no_exit(self):
|
||||
def test_network_devices_get_by_filter_no_exit(self):
|
||||
filters = {"id": 5}
|
||||
res = dbapi.networks_get_by_region(self.context,
|
||||
device1['region_id'],
|
||||
filters)
|
||||
self.assertEqual(res, [])
|
||||
|
||||
def test_netdevices_delete(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_delete(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
# First make sure we have the device
|
||||
res = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
res = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(res.id, device.id)
|
||||
# Delete the device
|
||||
dbapi.netdevices_delete(self.context, res.id)
|
||||
self.assertRaises(exceptions.NotFound, dbapi.netdevices_get_by_id,
|
||||
dbapi.network_devices_delete(self.context, res.id)
|
||||
self.assertRaises(exceptions.NotFound, dbapi.network_devices_get_by_id,
|
||||
self.context, res.id)
|
||||
|
||||
def test_netdevice_labels_create(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_labels_create(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
labels = {"labels": ["tom", "jerry"]}
|
||||
dbapi.netdevices_labels_update(self.context, device.id, labels)
|
||||
dbapi.network_devices_labels_update(self.context, device.id, labels)
|
||||
|
||||
def test_netdevices_update(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
res = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
def test_network_devices_update(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
res = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(res.hostname, 'switch1')
|
||||
new_name = 'switch2'
|
||||
res = dbapi.netdevices_update(self.context, res.id,
|
||||
{'name': 'switch2'})
|
||||
res = dbapi.network_devices_update(self.context, res.id,
|
||||
{'name': 'switch2'})
|
||||
self.assertEqual(res.name, new_name)
|
||||
|
||||
def test_netdevice_labels_delete(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_labels_delete(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
_labels = {"labels": ["tom", "jerry"]}
|
||||
dbapi.netdevices_labels_update(self.context, device.id, _labels)
|
||||
ndevice = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
dbapi.network_devices_labels_update(self.context, device.id, _labels)
|
||||
ndevice = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(sorted(ndevice.labels), sorted(_labels["labels"]))
|
||||
_dlabels = {"labels": ["tom"]}
|
||||
dbapi.netdevices_labels_delete(self.context, ndevice.id, _dlabels)
|
||||
ndevice = dbapi.netdevices_get_by_id(self.context, ndevice.id)
|
||||
dbapi.network_devices_labels_delete(self.context, ndevice.id, _dlabels)
|
||||
ndevice = dbapi.network_devices_get_by_id(self.context, ndevice.id)
|
||||
self.assertEqual(ndevice.labels, {"jerry"})
|
||||
|
||||
def test_netdevice_variables_create(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_variables_create(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
_data = {"hello": "hi"}
|
||||
dbapi.netdevices_variables_update(self.context, device.id, _data)
|
||||
ndevice = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
dbapi.network_devices_variables_update(self.context, device.id, _data)
|
||||
ndevice = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(ndevice.variables, _data)
|
||||
|
||||
def test_netdevice_variables_delete(self):
|
||||
device = dbapi.netdevices_create(self.context, device1)
|
||||
def test_network_devices_variables_delete(self):
|
||||
device = dbapi.network_devices_create(self.context, device1)
|
||||
_data = {"hello": "hi", "a": "b"}
|
||||
dbapi.netdevices_variables_update(self.context, device.id, _data)
|
||||
ndevice = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
dbapi.network_devices_variables_update(self.context, device.id, _data)
|
||||
ndevice = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(ndevice.variables, _data)
|
||||
_del_data = {"key": "a"}
|
||||
dbapi.netdevices_variables_delete(self.context, device.id, _del_data)
|
||||
ndevice = dbapi.netdevices_get_by_id(self.context, device.id)
|
||||
dbapi.network_devices_variables_delete(self.context, device.id,
|
||||
_del_data)
|
||||
ndevice = dbapi.network_devices_get_by_id(self.context, device.id)
|
||||
self.assertEqual(ndevice.variables, {"hello": "hi"})
|
||||
|
||||
|
||||
class NetworkInterfacesDBTestCase(base.DBTestCase):
|
||||
|
||||
def test_interface_create(self):
|
||||
def test_network_interfaces_create(self):
|
||||
try:
|
||||
dbapi.net_interfaces_create(self.context, net_interface1)
|
||||
dbapi.network_interfaces_create(self.context, network_interface1)
|
||||
except Exception:
|
||||
self.fail("Network interface create raised unexpected exception")
|
||||
|
||||
def test_interface_get_all(self):
|
||||
dbapi.net_interfaces_create(self.context, net_interface1)
|
||||
def test_network_interfaces_get_all(self):
|
||||
dbapi.network_interfaces_create(self.context, network_interface1)
|
||||
filters = {}
|
||||
res = dbapi.net_interfaces_get_by_device(self.context, 1, filters)
|
||||
res = dbapi.network_interfaces_get_by_device(self.context, 1, filters)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['name'], 'eth1')
|
||||
|
||||
def test_interface_get_by_id(self):
|
||||
interface = dbapi.net_interfaces_create(self.context, net_interface1)
|
||||
res = dbapi.net_interfaces_get_by_id(self.context, interface.id)
|
||||
def test_network_interfaces_get_by_id(self):
|
||||
interface = dbapi.network_interfaces_create(self.context,
|
||||
network_interface1)
|
||||
res = dbapi.network_interfaces_get_by_id(self.context, interface.id)
|
||||
self.assertEqual(res.name, 'eth1')
|
||||
|
||||
def test_interface_update(self):
|
||||
interface = dbapi.net_interfaces_create(self.context, net_interface1)
|
||||
res = dbapi.net_interfaces_get_by_id(self.context, interface.id)
|
||||
def test_network_interfaces_update(self):
|
||||
interface = dbapi.network_interfaces_create(self.context,
|
||||
network_interface1)
|
||||
res = dbapi.network_interfaces_get_by_id(self.context, interface.id)
|
||||
self.assertEqual(res.name, 'eth1')
|
||||
new_name = 'eth2'
|
||||
res = dbapi.net_interfaces_update(self.context, interface.id,
|
||||
{'name': 'eth2'})
|
||||
res = dbapi.network_interfaces_update(self.context, interface.id,
|
||||
{'name': 'eth2'})
|
||||
self.assertEqual(res.name, new_name)
|
||||
|
||||
def test_interface_delete(self):
|
||||
interface = dbapi.net_interfaces_create(self.context, net_interface1)
|
||||
def test_network_interfaces_delete(self):
|
||||
interface = dbapi.network_interfaces_create(self.context,
|
||||
network_interface1)
|
||||
# First make sure we have the interface created
|
||||
res = dbapi.net_interfaces_get_by_id(self.context, interface.id)
|
||||
res = dbapi.network_interfaces_get_by_id(self.context, interface.id)
|
||||
self.assertEqual(res.id, interface.id)
|
||||
# Delete the device
|
||||
dbapi.net_interfaces_delete(self.context, res.id)
|
||||
self.assertRaises(exceptions.NotFound, dbapi.net_interfaces_get_by_id,
|
||||
dbapi.network_interfaces_delete(self.context, res.id)
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
dbapi.network_interfaces_get_by_id,
|
||||
self.context, res.id)
|
||||
|
|
|
@ -127,7 +127,7 @@ NETWORK2 = Networks("PublicNetwork", 1, "10.10.1.0/24", "10.10.1.1",
|
|||
NETWORKS_LIST = [NETWORK1, NETWORK2]
|
||||
|
||||
|
||||
class NetDevice():
|
||||
class NetworkDevice():
|
||||
def __init__(self, region_id, ip_address):
|
||||
self.region_id = region_id
|
||||
self.ip_address = ip_address
|
||||
|
@ -136,11 +136,11 @@ class NetDevice():
|
|||
return iter(self.__dict__.items())
|
||||
|
||||
|
||||
NETDEVICE1 = NetDevice(1, '10.10.0.1')
|
||||
NETDEVICE_LIST1 = [NETDEVICE1]
|
||||
NETWORK_DEVICE1 = NetworkDevice(1, '10.10.0.1')
|
||||
NETWORK_DEVICE_LIST1 = [NETWORK_DEVICE1]
|
||||
|
||||
|
||||
class NetInterface():
|
||||
class NetworkInterface():
|
||||
def __init__(self, name, device_id, interface_type, ip_address):
|
||||
self.name = name
|
||||
self.device_id = device_id
|
||||
|
@ -151,7 +151,7 @@ class NetInterface():
|
|||
return iter(self.__dict__.items())
|
||||
|
||||
|
||||
NETINTERFACE1 = NetInterface(
|
||||
NETWORK_INTERFACE1 = NetworkInterface(
|
||||
'NetworkDevice1', 1, 'interface_type1', '10.10.0.1'
|
||||
)
|
||||
NETINTERFACE_LIST1 = [NETINTERFACE1]
|
||||
NETWORK_INTERFACE_LIST1 = [NETWORK_INTERFACE1]
|
||||
|
|
|
@ -562,36 +562,40 @@ class APIV1NetworksTest(APIV1Test):
|
|||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
|
||||
class APIV1NetDevicesTest(APIV1Test):
|
||||
@mock.patch.object(dbapi, 'netdevices_get_by_region')
|
||||
def test_get_netdevices_by_ip_address_filter(self, fake_devices):
|
||||
class APIV1NetworkDevicesTest(APIV1Test):
|
||||
@mock.patch.object(dbapi, 'network_devices_get_by_region')
|
||||
def test_get_network_devices_by_ip_address_filter(self, fake_devices):
|
||||
region_id = '1'
|
||||
ip_address = '10.10.0.1'
|
||||
filters = {'region_id': region_id, 'ip_address': ip_address}
|
||||
path_query = '/v1/netdevices?region_id={}&ip_address={}'.format(
|
||||
region_id, ip_address
|
||||
path_query = (
|
||||
'/v1/network_devices?region_id={}&ip_address={}'.format(
|
||||
region_id, ip_address
|
||||
)
|
||||
)
|
||||
fake_devices.return_value = fake_resources.NETDEVICE_LIST1
|
||||
fake_devices.return_value = fake_resources.NETWORK_DEVICE_LIST1
|
||||
resp = self.get(path_query)
|
||||
device_resp = fake_resources.NETDEVICE_LIST1
|
||||
device_resp = fake_resources.NETWORK_DEVICE_LIST1
|
||||
self.assertEqual(len(resp.json), 1)
|
||||
self.assertEqual(resp.json[0]["ip_address"], device_resp[0].ip_address)
|
||||
|
||||
fake_devices.assert_called_once_with(mock.ANY, region_id, filters)
|
||||
|
||||
|
||||
class APIV1NetInterfacesTest(APIV1Test):
|
||||
@mock.patch.object(dbapi, 'net_interfaces_get_by_device')
|
||||
class APIV1NetworkInterfacesTest(APIV1Test):
|
||||
@mock.patch.object(dbapi, 'network_interfaces_get_by_device')
|
||||
def test_get_netinterfaces_by_ip_address_filter(self, fake_interfaces):
|
||||
device_id = 1
|
||||
ip_address = '10.10.0.1'
|
||||
filters = {'device_id': device_id, 'ip_address': ip_address}
|
||||
path_query = '/v1/net_interfaces?device_id={}&ip_address={}'.format(
|
||||
device_id, ip_address
|
||||
path_query = (
|
||||
'/v1/network_interfaces?device_id={}&ip_address={}'.format(
|
||||
device_id, ip_address
|
||||
)
|
||||
)
|
||||
fake_interfaces.return_value = fake_resources.NETINTERFACE_LIST1
|
||||
fake_interfaces.return_value = fake_resources.NETWORK_INTERFACE_LIST1
|
||||
resp = self.get(path_query)
|
||||
interface_resp = fake_resources.NETINTERFACE_LIST1
|
||||
interface_resp = fake_resources.NETWORK_INTERFACE_LIST1
|
||||
self.assertEqual(len(resp.json), 1)
|
||||
self.assertEqual(resp.json[0]["name"], interface_resp[0].name)
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ class Inventory(object):
|
|||
return resp.json()
|
||||
|
||||
def create_netdevice(self, name, device_type):
|
||||
netdevices_url = self.url + "/netdevices"
|
||||
network_devices_url = self.url + "/network_devices"
|
||||
payload = {"hostname": name,
|
||||
"model_name": "model-x",
|
||||
"os_version": "version-1",
|
||||
|
@ -151,7 +151,7 @@ class Inventory(object):
|
|||
"region_id": self.region.get("id"),
|
||||
"cell_id": self.cell.get("id")}
|
||||
|
||||
resp = requests.post(netdevices_url, headers=self.headers,
|
||||
resp = requests.post(network_devices_url, headers=self.headers,
|
||||
data=json.dumps(payload), verify=False)
|
||||
if resp.status_code != 200:
|
||||
raise Exception(resp.text)
|
||||
|
@ -159,7 +159,7 @@ class Inventory(object):
|
|||
return resp.json()
|
||||
|
||||
def create_net_interface(self, device, int_num, network=None):
|
||||
netinterfaces_url = self.url + "/net_interfaces"
|
||||
netinterfaces_url = self.url + "/network_interfaces"
|
||||
name = "eth%s" % int_num
|
||||
payload = {"name": name,
|
||||
"interface_type": "ethernet",
|
||||
|
|
Loading…
Reference in New Issue