1 # Copyright (C) 2021 Wind River Systems, Inc.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
15 # from typing_extensions import Required
\r
16 from sqlalchemy import (
\r
32 from sqlalchemy.orm import mapper, relationship
\r
33 # from sqlalchemy.sql.sqltypes import Integer
\r
35 from o2ims.domain import ocloud as ocloudModel
\r
36 from o2ims.domain import subscription_obj as subModel
\r
37 from o2ims.domain import configuration_obj as confModel
\r
38 from o2ims.domain.resource_type import ResourceTypeEnum
\r
40 from o2common.helper import o2logging
\r
41 logger = o2logging.get_logger(__name__)
\r
43 metadata = MetaData()
\r
48 Column("updatetime", DateTime),
\r
49 Column("createtime", DateTime),
\r
50 Column("hash", String(255)),
\r
51 Column("version_number", Integer),
\r
53 Column("oCloudId", String(255), primary_key=True),
\r
54 Column("globalcloudId", String(255)),
\r
55 Column("name", String(255)),
\r
56 Column("description", String(255)),
\r
57 Column("infrastructureManagementServiceEndpoint", String(255))
\r
58 # Column("extensions", String(1024))
\r
61 resourcetype = Table(
\r
64 Column("updatetime", DateTime),
\r
65 Column("createtime", DateTime),
\r
66 Column("hash", String(255)),
\r
68 Column("resourceTypeId", String(255), primary_key=True),
\r
69 Column("resourceTypeEnum", Enum(ResourceTypeEnum), nullable=False),
\r
70 Column("oCloudId", ForeignKey("ocloud.oCloudId")),
\r
71 Column("name", String(255)),
\r
72 Column("vendor", String(255)),
\r
73 Column("model", String(255)),
\r
74 Column("version", String(255)),
\r
75 Column("description", String(255)),
\r
76 # Column("extensions", String(1024))
\r
79 resourcepool = Table(
\r
82 Column("updatetime", DateTime),
\r
83 Column("createtime", DateTime),
\r
84 Column("hash", String(255)),
\r
85 Column("version_number", Integer),
\r
87 Column("resourcePoolId", String(255), primary_key=True),
\r
88 Column("oCloudId", ForeignKey("ocloud.oCloudId")),
\r
89 Column("globalLocationId", String(255)),
\r
90 Column("name", String(255)),
\r
91 Column("location", String(255)),
\r
92 Column("description", String(255)),
\r
93 # Column("resources", String(1024))
\r
94 # Column("extensions", String(1024))
\r
100 Column("updatetime", DateTime),
\r
101 Column("createtime", DateTime),
\r
102 Column("hash", String(255)),
\r
103 Column("version_number", Integer),
\r
105 Column("resourceId", String(255), primary_key=True),
\r
106 Column("resourceTypeId", ForeignKey("resourcetype.resourceTypeId")),
\r
107 Column("resourcePoolId", ForeignKey("resourcepool.resourcePoolId")),
\r
108 Column("name", String(255)),
\r
109 # Column("globalAssetId", String(255)),
\r
110 Column("parentId", String(255)),
\r
111 Column("description", String(255)),
\r
112 Column("elements", Text())
\r
113 # Column("extensions", String(1024))
\r
116 deploymentmanager = Table(
\r
117 "deploymentmanager",
\r
119 Column("updatetime", DateTime),
\r
120 Column("createtime", DateTime),
\r
121 Column("hash", String(255)),
\r
122 Column("version_number", Integer),
\r
124 Column("deploymentManagerId", String(255), primary_key=True),
\r
125 Column("oCloudId", ForeignKey("ocloud.oCloudId")),
\r
126 Column("name", String(255)),
\r
127 Column("description", String(255)),
\r
128 Column("deploymentManagementServiceEndpoint", String(255)),
\r
129 Column("supportedLocations", String(255)),
\r
130 Column("capabilities", String(255)),
\r
131 Column("capacity", String(255)),
\r
132 # Column("extensions", String(1024))
\r
135 subscription = Table(
\r
138 Column("updatetime", DateTime),
\r
139 Column("createtime", DateTime),
\r
140 Column("hash", String(255)),
\r
141 Column("version_number", Integer),
\r
143 Column("subscriptionId", String(255), primary_key=True),
\r
144 Column("callback", String(255)),
\r
145 Column("consumerSubscriptionId", String(255)),
\r
146 Column("filter", String(255)),
\r
149 configuration = Table(
\r
152 Column("updatetime", DateTime),
\r
153 Column("createtime", DateTime),
\r
155 Column("configurationId", String(255), primary_key=True),
\r
156 Column("conftype", String(255)),
\r
157 Column("callback", String(255)),
\r
158 Column("status", String(255)),
\r
159 Column("comments", String(255)),
\r
163 def start_o2ims_mappers(engine=None):
\r
164 logger.info("Starting O2 IMS mappers")
\r
166 dm_mapper = mapper(ocloudModel.DeploymentManager, deploymentmanager)
\r
167 resourcepool_mapper = mapper(ocloudModel.ResourcePool, resourcepool)
\r
168 resourcetype_mapper = mapper(ocloudModel.ResourceType, resourcetype)
\r
170 ocloudModel.Ocloud,
\r
173 "deploymentManagers": relationship(dm_mapper),
\r
174 "resourceTypes": relationship(resourcetype_mapper),
\r
175 "resourcePools": relationship(resourcepool_mapper)
\r
178 ocloudModel.Resource,
\r
181 "resourceTypes": relationship(resourcetype_mapper),
\r
182 "resourcePools": relationship(resourcepool_mapper)
\r
185 mapper(subModel.Subscription, subscription)
\r
186 mapper(confModel.Configuration, configuration)
\r
188 if engine is not None:
\r
189 metadata.create_all(engine)
\r