Minor refactoring of parent fields
This commit is contained in:
parent
7589305a58
commit
854dded6fb
115
hnv/client.py
115
hnv/client.py
@ -45,19 +45,17 @@ class _BaseHNVModel(model.Model):
|
|||||||
the context of the resource if it is a top-level resource, or in the
|
the context of the resource if it is a top-level resource, or in the
|
||||||
context of the direct parent resource if it is a child resource."""
|
context of the direct parent resource if it is a child resource."""
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=False,
|
is_property=False, is_required=False, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
grandparent_id = model.Field(name="grandparent_id",
|
grandparent_id = model.Field(
|
||||||
key="grandParentResourceID",
|
name="grandparent_id", key="grandParentResourceID",
|
||||||
is_property=False, is_required=False,
|
is_property=False, is_required=False, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The grand parent resource ID field contains the resource ID that
|
"""The grand parent resource ID field contains the resource ID that
|
||||||
is associated with network objects that are ancestors of the parent
|
is associated with network objects that are ancestors of the parent
|
||||||
of the necessary resource."""
|
of the necessary resource."""
|
||||||
@ -224,9 +222,9 @@ class _BaseHNVModel(model.Model):
|
|||||||
"""Get the latest representation of the current model."""
|
"""Get the latest representation of the current model."""
|
||||||
client = self._get_client()
|
client = self._get_client()
|
||||||
endpoint = self._endpoint.format(
|
endpoint = self._endpoint.format(
|
||||||
resource_id=self.resource_id or "", parent_id=self.parent_id or "",
|
resource_id=self.resource_id or "",
|
||||||
|
parent_id=self.parent_id or "",
|
||||||
grandparent_id=self.grandparent_id or "")
|
grandparent_id=self.grandparent_id or "")
|
||||||
|
|
||||||
response = client.get_resource(endpoint)
|
response = client.get_resource(endpoint)
|
||||||
self._reset_model(response)
|
self._reset_model(response)
|
||||||
|
|
||||||
@ -251,8 +249,10 @@ class _BaseHNVModel(model.Model):
|
|||||||
|
|
||||||
super(_BaseHNVModel, self).commit(wait=wait, timeout=timeout)
|
super(_BaseHNVModel, self).commit(wait=wait, timeout=timeout)
|
||||||
client = self._get_client()
|
client = self._get_client()
|
||||||
endpoint = self._endpoint.format(resource_id=self.resource_id or "",
|
endpoint = self._endpoint.format(
|
||||||
parent_id=self.parent_id or "")
|
resource_id=self.resource_id or "",
|
||||||
|
parent_id=self.parent_id or "",
|
||||||
|
grandparent_id=self.grandparent_id or "")
|
||||||
request_body = self.dump(include_read_only=False)
|
request_body = self.dump(include_read_only=False)
|
||||||
response = client.update_resource(endpoint, data=request_body,
|
response = client.update_resource(endpoint, data=request_body,
|
||||||
if_match=if_match)
|
if_match=if_match)
|
||||||
@ -401,21 +401,19 @@ class IPPools(_BaseHNVModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_endpoint = ("/networking/v1/logicalNetworks/{grandparent_id}"
|
_endpoint = ("/networking/v1/logicalNetworks/{grandparent_id}"
|
||||||
"/logicalSubnets/{parent_id}/ipPools/{resource_id}")
|
"/subnets/{parent_id}/ipPools/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
grandparent_id = model.Field(name="grandparent_id",
|
grandparent_id = model.Field(
|
||||||
key="grandParentResourceID",
|
name="grandparent_id", key="grandParentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The grand parent resource ID field contains the resource ID that
|
"""The grand parent resource ID field contains the resource ID that
|
||||||
is associated with network objects that are ancestors of the parent
|
is associated with network objects that are ancestors of the parent
|
||||||
of the necessary resource."""
|
of the necessary resource."""
|
||||||
@ -450,10 +448,9 @@ class LogicalSubnetworks(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/logicalNetworks/{parent_id}"
|
_endpoint = ("/networking/v1/logicalNetworks/{parent_id}"
|
||||||
"/logicalSubnets/{resource_id}")
|
"/logicalSubnets/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -509,10 +506,10 @@ class LogicalSubnetworks(_BaseHNVModel):
|
|||||||
"""Create a new model using raw API response."""
|
"""Create a new model using raw API response."""
|
||||||
ip_pools = []
|
ip_pools = []
|
||||||
properties = raw_data["properties"]
|
properties = raw_data["properties"]
|
||||||
for raw_ip_pool in properties.get("ipPools", []):
|
for raw_content in properties.get("ipPools", []):
|
||||||
raw_ip_pool["parentResourceID"] = raw_data["resourceId"]
|
raw_content["parentResourceID"] = raw_data["resourceId"]
|
||||||
raw_ip_pool["grandParentResourceID"] = raw_data["parentResourceID"]
|
raw_content["grandParentResourceID"] = raw_data["parentResourceID"]
|
||||||
ip_pools.append(IPPools.from_raw_data(raw_ip_pool))
|
ip_pools.append(IPPools.from_raw_data(raw_content))
|
||||||
properties["ipPools"] = ip_pools
|
properties["ipPools"] = ip_pools
|
||||||
|
|
||||||
ip_configurations = []
|
ip_configurations = []
|
||||||
@ -522,6 +519,12 @@ class LogicalSubnetworks(_BaseHNVModel):
|
|||||||
ip_configurations.append(ip_configuration)
|
ip_configurations.append(ip_configuration)
|
||||||
properties["ipConfigurations"] = ip_configurations
|
properties["ipConfigurations"] = ip_configurations
|
||||||
|
|
||||||
|
network_interfaces = []
|
||||||
|
for raw_content in properties.get("networkInterfaces", []):
|
||||||
|
resource = Resource.from_raw_data(raw_content)
|
||||||
|
network_interfaces.append(resource)
|
||||||
|
properties["networkInterfaces"] = network_interfaces
|
||||||
|
|
||||||
return super(LogicalSubnetworks, cls).from_raw_data(raw_data)
|
return super(LogicalSubnetworks, cls).from_raw_data(raw_data)
|
||||||
|
|
||||||
|
|
||||||
@ -584,10 +587,9 @@ class IPConfiguration(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/networkInterfaces/{parent_id}"
|
_endpoint = ("/networking/v1/networkInterfaces/{parent_id}"
|
||||||
"/ipConfigurations/{resource_id}")
|
"/ipConfigurations/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -863,10 +865,9 @@ class SubNetworks(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/virtualNetworks/{parent_id}"
|
_endpoint = ("/networking/v1/virtualNetworks/{parent_id}"
|
||||||
"/subnets/{resource_id}")
|
"/subnets/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -1022,10 +1023,9 @@ class ACLRules(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/accessControlLists/{parent_id}"
|
_endpoint = ("/networking/v1/accessControlLists/{parent_id}"
|
||||||
"/aclRules/{resource_id}")
|
"/aclRules/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -1239,10 +1239,9 @@ class Routes(_BaseHNVModel):
|
|||||||
|
|
||||||
_endpoint = "/networking/v1/routeTables/{parent_id}/routes/{resource_id}"
|
_endpoint = "/networking/v1/routeTables/{parent_id}/routes/{resource_id}"
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=False,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -1656,10 +1655,9 @@ class NetworkConnections(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/virtualGateways/{parent_id}"
|
_endpoint = ("/networking/v1/virtualGateways/{parent_id}"
|
||||||
"/networkConnections/{resource_id}")
|
"/networkConnections/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
@ -1867,6 +1865,18 @@ class PublicIPAddresses(_BaseHNVModel):
|
|||||||
gateways.
|
gateways.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_raw_data(cls, raw_data):
|
||||||
|
"""Create a new model using raw API response."""
|
||||||
|
properties = raw_data.get("properties", {})
|
||||||
|
|
||||||
|
raw_content = properties.get("ipConfiguration", None)
|
||||||
|
if raw_content is not None:
|
||||||
|
resource = Resource.from_raw_data(raw_content)
|
||||||
|
properties["ipConfiguration"] = resource
|
||||||
|
|
||||||
|
return super(PublicIPAddresses, cls).from_raw_data(raw_data)
|
||||||
|
|
||||||
|
|
||||||
class BackendAddressPools(_BaseHNVModel):
|
class BackendAddressPools(_BaseHNVModel):
|
||||||
|
|
||||||
@ -2837,10 +2847,9 @@ class BGPRouters(_BaseHNVModel):
|
|||||||
_endpoint = ("/networking/v1/virtualGateways/{parent_id}"
|
_endpoint = ("/networking/v1/virtualGateways/{parent_id}"
|
||||||
"/bgpRouters/{resource_id}")
|
"/bgpRouters/{resource_id}")
|
||||||
|
|
||||||
parent_id = model.Field(name="parent_id",
|
parent_id = model.Field(
|
||||||
key="parentResourceID",
|
name="parent_id", key="parentResourceID",
|
||||||
is_property=False, is_required=True,
|
is_property=False, is_required=True, is_read_only=True)
|
||||||
is_read_only=True)
|
|
||||||
"""The parent resource ID field contains the resource ID that is
|
"""The parent resource ID field contains the resource ID that is
|
||||||
associated with network objects that are ancestors of the necessary
|
associated with network objects that are ancestors of the necessary
|
||||||
resource.
|
resource.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user