Skip to content

Commit

Permalink
feat: add frame code for Function App cloud service (cloudforet-io#32)
Browse files Browse the repository at this point in the history
Signed-off-by: Minho Kim <[email protected]>
  • Loading branch information
ImMin5 committed Nov 21, 2022
1 parent fced380 commit ad05cd6
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/pip_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ azure-keyvault-secrets
azure-mgmt-rdbms
azure-mgmt-cosmosdb
azure-mgmt-containerinstance
azure-mgmt-webpubsub
azure-mgmt-webpubsub
azure-mgmt-web
1 change: 1 addition & 0 deletions src/spaceone/inventory/conf/cloud_service_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
'VirtualNetworks': 'VirtualNetworksManager',
'VMScaleSets': 'VmScaleSetsManager',
'WebPubSubService': 'WebPubSubServiceManager',
'FunctionApp': 'FunctionAppManager'
}
1 change: 1 addition & 0 deletions src/spaceone/inventory/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
from spaceone.inventory.connector.sql_databases import SQLDatabasesConnector
from spaceone.inventory.connector.container_instances import ContainerInstancesConnector
from spaceone.inventory.connector.web_pubsub_service import WebPubSubServiceConnector
from spaceone.inventory.connector.function_app import FunctionAppConnector
1 change: 1 addition & 0 deletions src/spaceone/inventory/connector/function_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from spaceone.inventory.connector.function_app.connector import FunctionAppConnector
12 changes: 12 additions & 0 deletions src/spaceone/inventory/connector/function_app/connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging
from spaceone.inventory.libs.connector import AzureConnector

__all__ = ['FunctionAppConnector']
_LOGGER = logging.getLogger(__name__)


class FunctionAppConnector(AzureConnector):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
1 change: 1 addition & 0 deletions src/spaceone/inventory/manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from spaceone.inventory.manager.virtual_machines.instnace_manger import VirtualMachinesManager
from spaceone.inventory.manager.container_instances.container_manager import ContainerInstancesManager
from spaceone.inventory.manager.web_pubsub_service.service_manager import WebPubSubServiceManager
from spaceone.inventory.manager.function_app.instance_manager import FunctionAppManager
Empty file.
40 changes: 40 additions & 0 deletions src/spaceone/inventory/manager/function_app/instance_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import time
import logging
from spaceone.inventory.libs.manager import AzureManager
from spaceone.inventory.libs.schema.base import ReferenceModel
from spaceone.core.utils import *
from spaceone.inventory.model.web_pubsub_service.cloud_service_type import CLOUD_SERVICE_TYPES

_LOGGER = logging.getLogger(__name__)


class FunctionAppManager(AzureManager):
connector_name = 'FunctionAppConnector'
cloud_service_types = CLOUD_SERVICE_TYPES

def collect_cloud_service(self, params):
"""
Args:
params (dict):
- 'options' : 'dict'
- 'schema' : 'str'
- 'secret_data' : 'dict'
- 'filter' : 'dict'
- 'zones' : 'list'
- 'subscription_info' : 'dict'
Response:
CloudServiceResponse (list) : list of azure function app data resource information
ErrorResourceResponse (list) : list of error resource information
"""

_LOGGER.debug(f'** Function App START **')
start_time = time.time()
subscription_info = params['subscription_info']
container_instances_responses = []
error_responses = []

_LOGGER.debug(f'** Function App Service Finished {time.time() - start_time} Seconds **')
return container_instances_responses, error_responses
Empty file.
34 changes: 34 additions & 0 deletions src/spaceone/inventory/model/function_app/cloud_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType
from spaceone.inventory.model.function_app.data import FunctionApp
from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField
from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout
from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta

'''
Function App
'''
# TAB - Function App
function_app_info_meta = ItemDynamicLayout.set_fields('Web PubSub Service', fields=[
])


function_app_meta = CloudServiceMeta.set_layouts(
[function_app_info_meta])


class ComputeResource(CloudServiceResource):
cloud_service_group = StringType(default='WebPubSubService')


class FunctionAppResource(ComputeResource):
cloud_service_type = StringType(default='ScaleSet')
data = ModelType(FunctionApp)
_metadata = ModelType(CloudServiceMeta, default=function_app_meta, serialized_name='metadata')
name = StringType()
account = StringType(serialize_when_none=False)
instance_type = StringType(serialize_when_none=False)
instance_size = FloatType(serialize_when_none=False)


class WebPubSubServiceResponse(CloudServiceResponse):
resource = PolyModelType(FunctionAppResource)
42 changes: 42 additions & 0 deletions src/spaceone/inventory/model/function_app/cloud_service_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
from spaceone.inventory.libs.utils import *
from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget
from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \
EnumDyField
from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \
CloudServiceTypeMeta

current_dir = os.path.abspath(os.path.dirname(__file__))

function_app_by_account_conf = os.path.join(current_dir, 'widget/function_app_by_account.yaml')
function_app_by_region_conf = os.path.join(current_dir, 'widget/function_app_by_region.yaml')
function_app_by_resource_group_conf = os.path.join(current_dir, 'widget/function_app_by_resource_group.yaml')
function_app_total_count_count_conf = os.path.join(current_dir, 'widget/function_app_total_count.yaml')

cst_function_app = CloudServiceTypeResource()
cst_function_app.name = 'Instance'
cst_function_app.group = 'FunctionApp'
cst_function_app.service_code = 'Microsoft.Web/sites'
cst_function_app.labels = ['Compute']
cst_function_app.is_major = True
cst_function_app.is_primary = True
cst_function_app.tags = {
'spaceone:icon': '',
}

cst_function_app._metadata = CloudServiceTypeMeta.set_meta(
fields=[
],
search=[

],
widget=[

]

)


CLOUD_SERVICE_TYPES = [
CloudServiceTypeResponse({'resource': cst_function_app}),
]
15 changes: 15 additions & 0 deletions src/spaceone/inventory/model/function_app/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from schematics import Model
from schematics.types import StringType
from spaceone.inventory.libs.schema.resource import AzureCloudService


class FunctionApp(AzureCloudService):
id = StringType(serialize_when_none=False)
name = StringType(serialize_when_none=False)
location = StringType(serialize_when_none=False)

def reference(self):
return {
"resource_id": self.id,
"external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview",
}
2 changes: 1 addition & 1 deletion test/api/test_cloud_service_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_verify(self):

def test_collect(self):

options = {'cloud_service_types': ['WebPubSubService']}
options = {'cloud_service_types': ['FunctionApp']}
# options = {}
filter = {}
resource_stream = self.inventory.Collector.collect({'options': options, 'secret_data': self.azure_credentials,
Expand Down

0 comments on commit ad05cd6

Please sign in to comment.