Skip to content

Commit

Permalink
Merge pull request #89 from lhhyung/main
Browse files Browse the repository at this point in the history
Migration azure inventory plugin spaceone framwork 2.0
  • Loading branch information
lhhyung authored Aug 22, 2024
2 parents fcc3e34 + c0443cd commit 71b89c9
Show file tree
Hide file tree
Showing 472 changed files with 8,280 additions and 22,325 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ local-conf.yml
.venv/
.venv.nosync/
.DS_Store
!src/spaceone/inventory/metrics/Disks/disk
!src/plugin/metrics/Disks/Disk
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV SRC_DIR /tmp/src
COPY pkg/*.txt ${PKG_DIR}/
RUN pip install --upgrade pip && \
pip install --upgrade -r ${PKG_DIR}/pip_requirements.txt && \
pip install --upgrade spaceone-api
pip install --upgrade spaceone-api spaceone-inventory

COPY src ${SRC_DIR}

Expand All @@ -20,4 +20,4 @@ RUN python3 setup.py install && \
EXPOSE ${CLOUDONE_PORT}

ENTRYPOINT ["spaceone"]
CMD ["run", "grpc-server", "spaceone.inventory"]
CMD ["run", "plugin-server", "plugin"]
2 changes: 1 addition & 1 deletion pkg/pip_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schematics
spaceone-api
azure-identity
azure-mgmt-resource
azure-mgmt-compute
Expand Down
2 changes: 1 addition & 1 deletion src/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
0.0.1
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/plugin/conf/cloud_service_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ICON_URL = "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
__all__ = ['ApplicationGatewaysConnector']
_LOGGER = logging.getLogger(__name__)
from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")

class ApplicationGatewaysConnector(AzureConnector):

class ApplicationGatewaysConnector(AzureBaseConnector):

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -16,4 +15,4 @@ def list_all_application_gateways(self):
return self.network_client.application_gateways.list_all()

def get_public_ip_addresses(self, public_ip_address_name, resource_group_name):
return self.network_client.public_ip_addresses.get(public_ip_address_name, resource_group_name)
return self.network_client.public_ip_addresses.get(public_ip_address_name, resource_group_name)
75 changes: 75 additions & 0 deletions src/plugin/connector/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os
import logging

from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.resource import SubscriptionClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.sql import SqlManagementClient
from azure.mgmt.monitor import MonitorManagementClient
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.cosmosdb import CosmosDBManagementClient
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
from azure.mgmt.rdbms.postgresql_flexibleservers import PostgreSQLManagementClient as PostgreSQLFlexibleManagementClient
from azure.mgmt.webpubsub import WebPubSubManagementClient
from azure.mgmt.keyvault import KeyVaultManagementClient
from azure.mgmt.rdbms.mysql import MySQLManagementClient
from azure.mgmt.rdbms.mysql_flexibleservers import MySQLManagementClient as MySQLFlexibleManagementClient


from spaceone.core.connector import BaseConnector

DEFAULT_SCHEMA = 'azure_client_secret'
_LOGGER = logging.getLogger(__name__)


class AzureBaseConnector(BaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.subscription_client = None
self.compute_client = None
self.network_client = None
self.sql_client = None
self.monitor_client = None
self.container_instance_client = None
self.resource_client = None
self.storage_client = None
self.cosmosdb_client = None
self.postgre_sql_client = None
self.postgre_sql_flexible_client = None
self.web_pubsub_service_client = None
self.key_vault_client = None
self.mysql_client = None
self.mysql_flexible_client = None


def set_connect(self, secret_data: dict):
subscription_id = secret_data['subscription_id']

os.environ["AZURE_SUBSCRIPTION_ID"] = subscription_id
os.environ["AZURE_TENANT_ID"] = secret_data['tenant_id']
os.environ["AZURE_CLIENT_ID"] = secret_data['client_id']
os.environ["AZURE_CLIENT_SECRET"] = secret_data['client_secret']

credential = DefaultAzureCredential()

self.subscription_client = SubscriptionClient(credential=credential)
self.compute_client = ComputeManagementClient(credential=credential, subscription_id=subscription_id)
self.network_client = NetworkManagementClient(credential=credential, subscription_id=subscription_id)
self.sql_client = SqlManagementClient(credential=credential, subscription_id=subscription_id)
self.monitor_client = MonitorManagementClient(credential=credential, subscription_id=subscription_id)
self.container_instance_client = ContainerInstanceManagementClient(credential=credential, subscription_id=subscription_id)
self.resource_client = ResourceManagementClient(credential=credential, subscription_id=subscription_id)
self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id)
self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id)
self.postgre_sql_client = PostgreSQLManagementClient(credential=credential, subscription_id=subscription_id)
self.postgre_sql_flexible_client = PostgreSQLFlexibleManagementClient(credential=credential, subscription_id=subscription_id)
self.web_pubsub_service_client = WebPubSubManagementClient(credential=credential, subscription_id=subscription_id)
self.key_vault_client = KeyVaultManagementClient(credential=credential, subscription_id=subscription_id)
self.mysql_client = MySQLManagementClient(credential=credential, subscription_id=subscription_id)
self.mysql_flexible_client = MySQLFlexibleManagementClient(credential=credential, subscription_id=subscription_id)

def get_connector(self, cloud_service_group: str, cloud_service_type: str):
pass
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
__all__ = ['ContainerInstancesConnector']
_LOGGER = logging.getLogger(__name__)
from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")

class ContainerInstancesConnector(AzureConnector):

class ContainerInstancesConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand All @@ -17,4 +15,4 @@ def list_container_groups(self):

def get_container_groups(self, resource_group_name, container_group_name):
return self.container_instance_client.container_groups.get(resource_group_name=resource_group_name,
container_group_name=container_group_name)
container_group_name=container_group_name)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
__all__ = ['CosmosDBConnector']
_LOGGER = logging.getLogger(__name__)
from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")

class CosmosDBConnector(AzureConnector):

class CosmosDBConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand All @@ -16,8 +14,7 @@ def list_all_cosmos_db_accounts(self):
return self.cosmosdb_client.database_accounts.list()

def list_keys(self, account_name, resource_group_name):
return self.cosmosdb_client.database_accounts.list_keys(account_name= account_name, resource_group_name=resource_group_name)
return self.cosmosdb_client.database_accounts.list_keys(account_name=account_name, resource_group_name=resource_group_name)

def list_sql_resources(self, account_name, resource_group_name):
return self.cosmosdb_client.sql_resources.list_sql_databases(account_name=account_name, resource_group_name=resource_group_name)

File renamed without changes.
14 changes: 14 additions & 0 deletions src/plugin/connector/disks/disks_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging

from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")


class DisksConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))

def list_disks(self):
return self.compute_client.disks.list()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import logging

import azure.core.exceptions

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
from plugin.connector.base import AzureBaseConnector
from azure.keyvault.secrets import SecretClient
from azure.keyvault.certificates import CertificateClient
from azure.identity import DefaultAzureCredential

__all__ = ["KeyVaultsConnector"]
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")


class KeyVaultsConnector(AzureConnector):
class KeyVaultsConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)

Expand Down Expand Up @@ -47,4 +43,4 @@ def list_keys(self, resource_group_name, vault_name):

def list_secrets(self):
# return self.key_vault_secrets_client.list_properties_of_secrets()
return self.key_vault_client.secrets.list()
return self.key_vault_client.secrets.list()
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
__all__ = ['LoadBalancersConnector']
_LOGGER = logging.getLogger(__name__)
from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")

class LoadBalancersConnector(AzureConnector):

class LoadBalancersConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error import *
from plugin.connector.base import AzureBaseConnector

__all__ = ['MonitorConnector']
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")


class MonitorConnector(AzureConnector):

class MonitorConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand All @@ -19,5 +16,3 @@ def list_diagnostic_settings(self, resource_uri):
def list_metrics(self, resource_uri, metricnames, aggregation, timespan=None, interval=None):
return self.monitor_client.metrics.list(resource_uri, metricnames=metricnames, aggregation=aggregation,
timespan=timespan, interval=interval)


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging

from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")


class MySQLFlexibleServersConnector(AzureBaseConnector):
def __init__(self, secret_data=None, **kwargs):
super().__init__(**kwargs)

self.set_connect(secret_data)

def list_flexible_servers(self):
return self.mysql_flexible_client.servers.list()

def list_firewall_rules_by_server(self, resource_group_name, server_name):
return self.mysql_flexible_client.firewall_rules.list_by_server(resource_group_name=resource_group_name, server_name=server_name)
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error.custom import *
from plugin.connector.base import AzureBaseConnector

__all__ = ['MySQLServersConnector']
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")


class MySQLServersConnector(AzureConnector):

class MySQLServersConnector(AzureBaseConnector):
def __init__(self, secret_data=None, **kwargs):
super().__init__(**kwargs)

Expand All @@ -21,4 +18,4 @@ def list_firewall_rules_by_server(self, resource_group_name, server_name):
return self.mysql_client.firewall_rules.list_by_server(resource_group_name=resource_group_name, server_name=server_name)

def list_server_parameters(self, resource_group_name, server_name):
return self.mysql_client.server_parameters._list_update_configurations_initial(resource_group_name=resource_group_name, server_name=server_name, value=[])
return self.mysql_client.server_parameters._list_update_configurations_initial(resource_group_name=resource_group_name, server_name=server_name, value=[])
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error import *
from plugin.connector.base import AzureBaseConnector

__all__ = ['NATGatewaysConnector']
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")


class NATGatewaysConnector(AzureConnector):

class NATGatewaysConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging

from spaceone.inventory.libs.connector import AzureConnector
from spaceone.inventory.error import *
from plugin.connector.base import AzureBaseConnector

__all__ = ['NetworkSecurityGroupsConnector']
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger("spaceone")


class NetworkSecurityGroupsConnector(AzureConnector):

class NetworkSecurityGroupsConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get('secret_data'))
Expand All @@ -20,7 +17,9 @@ def list_all_network_interfaces(self):
return self.network_client.network_interfaces.list_all()

def get_network_interfaces(self, network_interface_name, resource_group):
return self.network_client.network_interfaces.get(network_interface_name=network_interface_name, resource_group_name=resource_group)
return self.network_client.network_interfaces.get(network_interface_name=network_interface_name,
resource_group_name=resource_group)

def get_subnet(self, resource_group_name, subnet_name, virtual_network_name):
return self.network_client.subnets.get(resource_group_name=resource_group_name, subnet_name=subnet_name, virtual_network_name=virtual_network_name)
return self.network_client.subnets.get(resource_group_name=resource_group_name, subnet_name=subnet_name,
virtual_network_name=virtual_network_name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logging

from plugin.connector.base import AzureBaseConnector

_LOGGER = logging.getLogger("spaceone")


class PostgreSQLFlexibleServersConnector(AzureBaseConnector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_connect(kwargs.get("secret_data"))

def list_flexible_servers(self):
return self.postgre_sql_flexible_client.servers.list()

def list_firewall_rules_by_server(self, resource_group_name, server_name):
return self.postgre_sql_flexible_client.firewall_rules.list_by_server(
resource_group_name=resource_group_name, server_name=server_name
)
Loading

0 comments on commit 71b89c9

Please sign in to comment.