-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from lhhyung/master
Refactor Region service
- Loading branch information
Showing
15 changed files
with
244 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
from spaceone.api.inventory.v2 import region_pb2, region_pb2_grpc | ||
from spaceone.api.inventory_v2.v1 import region_pb2, region_pb2_grpc | ||
from spaceone.core.pygrpc import BaseAPI | ||
|
||
class Region(BaseAPI, region_pb2_grpc.RegionServicer): | ||
from spaceone.inventory_v2.service.region_service import RegionService | ||
|
||
|
||
class Region(BaseAPI, region_pb2_grpc.RegionServicer): | ||
pb2 = region_pb2 | ||
pb2_grpc = region_pb2_grpc | ||
|
||
def create(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
return self.locator.get_info('RegionInfo', region_service.create(params)) | ||
region_svc = RegionService(metadata) | ||
response: dict = region_svc.create(params) | ||
return self.dict_to_message(response) | ||
|
||
def update(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
return self.locator.get_info('RegionInfo', region_service.update(params)) | ||
region_svc = RegionService(metadata) | ||
response: dict = region_svc.update(params) | ||
return self.dict_to_message(response) | ||
|
||
def delete(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
region_service.delete(params) | ||
return self.locator.get_info('EmptyInfo') | ||
region_svc = RegionService(metadata) | ||
region_svc.delete(params) | ||
return self.empty() | ||
|
||
def get(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
return self.locator.get_info('RegionInfo', region_service.get(params)) | ||
region_svc = RegionService(metadata) | ||
response: dict = region_svc.get(params) | ||
return self.dict_to_message(response) | ||
|
||
def list(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
region_vos, total_count = region_service.list(params) | ||
return self.locator.get_info('RegionsInfo', region_vos, total_count, minimal=self.get_minimal(params)) | ||
region_svc = RegionService(metadata) | ||
response: dict = region_svc.list(params) | ||
return self.dict_to_message(response) | ||
|
||
def stat(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
|
||
with self.locator.get_service('RegionService', metadata) as region_service: | ||
return self.locator.get_info('StatisticsInfo', region_service.stat(params)) | ||
region_svc = RegionService(metadata) | ||
response: dict = region_svc.stat(params) | ||
return self.dict_to_message(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from mongoengine import * | ||
|
||
from spaceone.core.model.mongo_model import MongoModel | ||
|
||
|
||
class Region(MongoModel): | ||
region_id = StringField(max_length=40, unique=True) | ||
name = StringField(max_length=255) | ||
region_code = StringField(max_length=255) | ||
provider = StringField(max_length=255) | ||
tags = DictField() | ||
resource_group = StringField(max_length=40, choices=("DOMAIN", "WORKSPACE")) | ||
workspace_id = StringField(max_length=40) | ||
domain_id = StringField(max_length=40) | ||
created_at = DateTimeField(auto_now_add=True) | ||
updated_at = DateTimeField(auto_now=True) | ||
|
||
meta = { | ||
"updatable_fields": ["name", "tags", "updated_at"], | ||
"minimal_fields": ["region_id", "name", "region_code", "provider"], | ||
"ordering": ["name"], | ||
"indexes": [ | ||
"provider", | ||
"resource_group", | ||
"workspace_id", | ||
"domain_id", | ||
], | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Union, Literal | ||
from pydantic import BaseModel | ||
|
||
__all__ = [ | ||
"RegionCreateRequest", | ||
"RegionUpdateRequest", | ||
"RegionDeleteRequest", | ||
"RegionGetRequest", | ||
"RegionSearchQueryRequest", | ||
"RegionStatQueryRequest", | ||
] | ||
|
||
ResourceGroup = Literal["DOMAIN", "WORKSPACE"] | ||
|
||
|
||
class RegionCreateRequest(BaseModel): | ||
name: str | ||
region_code: str | ||
provider: str | ||
tags: Union[dict, None] = None | ||
resource_group: ResourceGroup | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class RegionUpdateRequest(BaseModel): | ||
region_id: str | ||
name: Union[str, None] = None | ||
tags: Union[dict, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class RegionDeleteRequest(BaseModel): | ||
region_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class RegionGetRequest(BaseModel): | ||
region_id: str | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str | ||
|
||
|
||
class RegionSearchQueryRequest(BaseModel): | ||
query: Union[dict, None] = None | ||
region_id: Union[str, None] = None | ||
name: Union[str, None] = None | ||
region_code: Union[str, None] = None | ||
provider: Union[str, None] = None | ||
exists_only: Union[bool, None] = None | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str | ||
|
||
|
||
class RegionStatQueryRequest(BaseModel): | ||
query: dict | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from datetime import datetime | ||
from typing import Union, List | ||
from pydantic import BaseModel | ||
|
||
from spaceone.core import utils | ||
|
||
__all__ = ["RegionResponse", "RegionsResponse"] | ||
|
||
|
||
class RegionResponse(BaseModel): | ||
region_id: Union[str, None] = None | ||
name: Union[str, None] = None | ||
region_code: Union[str, None] = None | ||
provider: Union[str, None] = None | ||
tags: Union[dict, None] = None | ||
domain_id: Union[str, None] = None | ||
created_at: Union[datetime, None] = None | ||
updated_at: Union[datetime, None] = None | ||
|
||
def dict(self, *args, **kwargs): | ||
data = super().dict(*args, **kwargs) | ||
data["created_at"] = utils.datetime_to_iso8601(data["created_at"]) | ||
data["updated_at"] = utils.datetime_to_iso8601(data["updated_at"]) | ||
return data | ||
|
||
|
||
class RegionsResponse(BaseModel): | ||
results: List[RegionResponse] | ||
total_count: int |
Oops, something went wrong.