def EventInfo(event_vo: Event, minimal=False): info = { 'event_id': event_vo.event_id, 'event_key': event_vo.event_key, 'event_type': event_vo.event_type, 'title': event_vo.title, 'severity': event_vo.severity, 'alert_id': event_vo.alert_id } if not minimal: info.update({ 'description': event_vo.description, 'rule': event_vo.rule, 'image_url': event_vo.image_url, 'resource': EventResourceInfo(event_vo.resource), 'raw_data': change_struct_type(event_vo.raw_data), 'additional_info': change_struct_type(event_vo.additional_info), 'alert_id': event_vo.alert_id, 'webhook_id': event_vo.webhook_id, 'project_id': event_vo.project_id, 'domain_id': event_vo.domain_id, 'created_at': utils.datetime_to_iso8601(event_vo.created_at), 'occurred_at': utils.datetime_to_iso8601(event_vo.occurred_at) }) return event_pb2.EventInfo(**info)
def get_metric_data(self, data_source_id, resource_type, resource, metric, start, end, period, stat): metrics = { 'domain_id': self.domain_id, 'labels': [], 'resource_values': {} } metric_resources = [resource] if isinstance(resource, str) else resource param = { 'data_source_id': data_source_id, 'resource_type': resource_type, 'resources': metric_resources, 'metric': metric, 'start': utils.datetime_to_iso8601(start), 'end': utils.datetime_to_iso8601(end), } if period: param.update({'period': period}) if stat: param.update({'stat': stat}) try: metrics = self.connector.metric_get_data(param, self.domain_id) except Exception as e: print('##################################') print(f'[ERROR: {e}]') print('##################################') return metrics
def CloudServiceInfo(cloud_svc_vo: CloudService, minimal=False): info = { 'cloud_service_id': cloud_svc_vo.cloud_service_id, 'name': cloud_svc_vo.name, 'state': cloud_svc_vo.state, 'cloud_service_group': cloud_svc_vo.cloud_service_group, 'cloud_service_type': cloud_svc_vo.cloud_service_type, 'provider': cloud_svc_vo.provider, 'region_code': cloud_svc_vo.region_code, 'reference': cloud_service_pb2.CloudServiceReference( **cloud_svc_vo.reference.to_dict()) if cloud_svc_vo.reference else None, 'project_id': cloud_svc_vo.project_id, } if not minimal: info.update({ 'account': cloud_svc_vo.account, 'instance_type': cloud_svc_vo.instance_type, 'instance_size': cloud_svc_vo.instance_size, 'data': change_struct_type(cloud_svc_vo.data), 'metadata': change_struct_type(cloud_svc_vo.metadata), 'tags': change_struct_type(utils.tags_to_dict(cloud_svc_vo.tags)), 'collection_info': CollectionInfo(cloud_svc_vo.collection_info.to_dict()), 'domain_id': cloud_svc_vo.domain_id, 'created_at': utils.datetime_to_iso8601(cloud_svc_vo.created_at), 'updated_at': utils.datetime_to_iso8601(cloud_svc_vo.updated_at), 'deleted_at': utils.datetime_to_iso8601(cloud_svc_vo.deleted_at), 'launched_at': utils.datetime_to_iso8601(cloud_svc_vo.launched_at), }) return cloud_service_pb2.CloudServiceInfo(**info)
def CollectorInfo(vo, minimal=False): info = { 'collector_id': vo.collector_id, 'name': vo.name, 'state': vo.state, 'provider': vo.provider, 'capability': change_struct_type(vo.capability), 'plugin_info': PluginInfo(vo.plugin_info, minimal=minimal), 'is_public': vo.is_public, 'project_id': vo.project_id } if not minimal: info.update({ 'priority': vo.priority, 'created_at': utils.datetime_to_iso8601(vo.created_at), 'last_collected_at': utils.datetime_to_iso8601(vo.last_collected_at), 'tags': change_struct_type(utils.tags_to_dict(vo.tags)), 'domain_id': vo.domain_id }) return collector_pb2.CollectorInfo(**info)
def ServerInfo(server_vo: Server, minimal=False): info = { 'server_id': server_vo.server_id, 'name': server_vo.name, 'state': server_vo.state, 'primary_ip_address': server_vo.primary_ip_address, 'os_type': server_vo.os_type, 'provider': server_vo.provider, 'cloud_service_group': server_vo.cloud_service_group, 'cloud_service_type': server_vo.cloud_service_type, 'region_code': server_vo.region_code, 'reference': server_pb2.ServerReference( **server_vo.reference.to_dict()) if server_vo.reference else None, 'project_id': server_vo.project_id, } if not minimal: info.update({ 'ip_addresses': server_vo.ip_addresses, 'account': server_vo.account, 'instance_type': server_vo.instance_type, 'data': change_struct_type(server_vo.data), 'metadata': change_struct_type(server_vo.metadata), 'nics': list(map(ServerNIC, server_vo.nics)), 'disks': list(map(ServerDisk, server_vo.disks)), 'tags': change_struct_type(utils.tags_to_dict(server_vo.tags)), 'collection_info': CollectionInfo(server_vo.collection_info.to_dict()), 'domain_id': server_vo.domain_id, 'created_at': utils.datetime_to_iso8601(server_vo.created_at), 'updated_at': utils.datetime_to_iso8601(server_vo.updated_at), 'deleted_at': utils.datetime_to_iso8601(server_vo.deleted_at), 'launched_at': utils.datetime_to_iso8601(server_vo.launched_at) }) return server_pb2.ServerInfo(**info)
def JobInfo(job_vo: Job, minimal=False): info = { 'job_id': job_vo.job_id, 'status': job_vo.status, 'created_at': utils.datetime_to_iso8601(job_vo.created_at), 'finished_at': utils.datetime_to_iso8601(job_vo.finished_at), } if not minimal: info.update({ 'filter': change_struct_type(job_vo.filters), 'total_tasks': job_vo.total_tasks, 'remained_tasks': job_vo.remained_tasks, 'errors': list(map(functools.partial(ErrorInfo), job_vo.errors)), 'collector_info': CollectorInfo(job_vo.collector, minimal=True) if job_vo.collector else None, 'project_id': job_vo.project_id, 'domain_id': job_vo.domain_id, 'updated_at': utils.datetime_to_iso8601(job_vo.updated_at), }) # Temporary code for DB migration if not job_vo.collector_id and job_vo.collector: job_vo.update({'collector_id': job_vo.collector.collector_id}) return collector_pb2.JobInfo(**info)
def CloudServiceTypeInfo(cloud_svc_type_vo: CloudServiceType, minimal=False): info = { 'cloud_service_type_id': cloud_svc_type_vo.cloud_service_type_id, 'name': cloud_svc_type_vo.name, 'provider': cloud_svc_type_vo.provider, 'group': cloud_svc_type_vo.group, 'service_code': cloud_svc_type_vo.service_code, 'is_primary': cloud_svc_type_vo.is_primary, 'is_major': cloud_svc_type_vo.is_major, 'resource_type': cloud_svc_type_vo.resource_type } if not minimal: info.update({ 'metadata': change_struct_type(cloud_svc_type_vo.metadata), 'labels': change_list_value_type(cloud_svc_type_vo.labels), 'tags': change_struct_type(utils.tags_to_dict(cloud_svc_type_vo.tags)), 'domain_id': cloud_svc_type_vo.domain_id, 'collection_info': CollectionInfo(cloud_svc_type_vo.collection_info.to_dict()), 'created_at': utils.datetime_to_iso8601(cloud_svc_type_vo.created_at), 'updated_at': utils.datetime_to_iso8601(cloud_svc_type_vo.updated_at) }) return cloud_service_type_pb2.CloudServiceTypeInfo(**info)
def ScheduleInfo(vo, minimal=False): info = { 'schedule_id': vo.schedule_id, 'collect_mode': vo.collect_mode, 'name': vo.name, 'schedule': ScheduledInfo(vo.schedule), 'collector_info': CollectorInfo(vo.collector, minimal=minimal) if vo.collector else None } if not minimal: info.update({ 'created_at': utils.datetime_to_iso8601(vo.created_at), 'last_scheduled_at': utils.datetime_to_iso8601(vo.last_scheduled_at), 'filter': change_struct_type(vo.filters) }) # Temporary code for DB migration if not vo.collector_id and vo.collector: vo.update({'collector_id': vo.collector.collector_id}) return collector_pb2.ScheduleInfo(**info)
def JobTaskInfo(job_task_vo: JobTask, minimal=False): info = { 'job_task_id': job_task_vo.job_task_id, 'status': job_task_vo.status, 'created_count': job_task_vo.created_count, 'updated_count': job_task_vo.updated_count, 'disconnected_count': job_task_vo.disconnected_count, 'deleted_count': job_task_vo.deleted_count, 'failure_count': job_task_vo.failure_count, 'job_id': job_task_vo.job_id, 'created_at': utils.datetime_to_iso8601(job_task_vo.created_at), 'started_at': utils.datetime_to_iso8601(job_task_vo.started_at), 'finished_at': utils.datetime_to_iso8601(job_task_vo.finished_at) } if not minimal: info.update({ 'errors': list(map(functools.partial(ErrorInfo), job_task_vo.errors)), 'secret_id': job_task_vo.secret_id, 'provider': job_task_vo.provider, 'service_account_id': job_task_vo.service_account_id, 'project_id': job_task_vo.project_id, 'domain_id': job_task_vo.domain_id, }) return job_task_pb2.JobTaskInfo(**info)
def SecretInfo(secret_vo: Secret, minimal=False): info = { 'secret_id': secret_vo.secret_id, 'name': secret_vo.name, 'secret_type': secret_vo.secret_type } if minimal is False: info.update({ 'tags': change_struct_type(utils.tags_to_dict(secret_vo.tags)), 'schema': secret_vo.schema, 'provider': secret_vo.provider, 'service_account_id': secret_vo.service_account_id, 'project_id': secret_vo.project_id, 'domain_id': secret_vo.domain_id, 'created_at': utils.datetime_to_iso8601(secret_vo.created_at) }) if getattr(secret_vo, 'secret_groups', None) is not None: secret_group_infos = list( map(lambda secret_group: SecretGroupInfo(secret_group), secret_vo.secret_groups)) info.update( {'secret_groups': change_list_value_type(secret_group_infos)}) return secret_pb2.SecretInfo(**info)
def WebhookInfo(webhook_vo: Webhook, minimal=False): if webhook_vo.webhook_url: webhook_url = f'{config.get_global("WEBHOOK_DOMAIN")}{webhook_vo.webhook_url}' else: webhook_url = None info = { 'webhook_id': webhook_vo.webhook_id, 'name': webhook_vo.name, 'state': webhook_vo.state, 'webhook_url': webhook_url, 'project_id': webhook_vo.project_id } if not minimal: info.update({ 'access_key': webhook_vo.access_key, 'capability': change_struct_type(webhook_vo.capability), 'plugin_info': PluginInfo(webhook_vo.plugin_info), 'domain_id': webhook_vo.domain_id, 'created_at': utils.datetime_to_iso8601(webhook_vo.created_at) }) return webhook_pb2.WebhookInfo(**info)
def ProjectGroupRoleBindingInfo(role_binding_vo, minimal=False): info = { 'role_binding_id': role_binding_vo.role_binding_id, 'resource_type': role_binding_vo.resource_type, 'resource_id': role_binding_vo.resource_id, 'role_info': RoleInfo(role_binding_vo.role, minimal=True) if role_binding_vo.role else None } if not minimal: info.update({ 'project_group_info': ProjectGroupInfo(role_binding_vo.project_group, minimal=True) if role_binding_vo.project_group else None, 'labels': change_list_value_type(role_binding_vo.labels), 'tags': change_struct_type(utils.tags_to_dict(role_binding_vo.tags)), 'domain_id': role_binding_vo.domain_id, 'created_at': utils.datetime_to_iso8601(role_binding_vo.created_at) }) return project_group_pb2.ProjectGroupRoleBindingInfo(**info)
def EventRuleInfo(event_rule_vo: EventRule, minimal=False): info = { 'event_rule_id': event_rule_vo.event_rule_id, 'name': event_rule_vo.name, 'order': event_rule_vo.order, } if not minimal: info.update({ 'conditions': EventRuleConditionsInfo(event_rule_vo.conditions), 'conditions_policy': event_rule_vo.conditions_policy, 'actions': EventRuleActionsInfo(event_rule_vo.actions), 'options': EventRuleOptionsInfo(event_rule_vo.options), 'tags': change_struct_type(event_rule_vo.tags), 'scope': event_rule_vo.scope, 'project_id': event_rule_vo.project_id, 'domain_id': event_rule_vo.domain_id, 'created_at': utils.datetime_to_iso8601(event_rule_vo.created_at) }) return event_rule_pb2.EventRuleInfo(**info)
def ServiceAccountInfo(service_account_vo: ServiceAccount, minimal=False): info = { 'service_account_id': service_account_vo.service_account_id, 'name': service_account_vo.name, 'provider': service_account_vo.provider } if not minimal: info.update({ 'data': change_struct_type(service_account_vo.data), 'tags': change_struct_type(utils.tags_to_dict(service_account_vo.tags)), 'domain_id': service_account_vo.domain_id, 'created_at': utils.datetime_to_iso8601(service_account_vo.created_at) }) if service_account_vo.project: info.update({ 'project_info': ProjectInfo(service_account_vo.project, minimal=True) }) return service_account_pb2.ServiceAccountInfo(**info)
def UserChannelInfo(user_channel_vo: UserChannel, minimal=False): info = { 'user_channel_id': user_channel_vo.user_channel_id, 'name': user_channel_vo.name, 'state': user_channel_vo.state } if not minimal: info.update({ 'data': change_struct_type(user_channel_vo.data), 'secret_id': user_channel_vo.secret_id, 'is_subscribe': user_channel_vo.is_subscribe, 'subscriptions': change_list_value_type(user_channel_vo.subscriptions), 'protocol_id': user_channel_vo.protocol_id, 'user_id': user_channel_vo.user_id, 'is_scheduled': user_channel_vo.is_scheduled, 'schedule': ScheduleInfo(user_channel_vo.schedule) if user_channel_vo.schedule else user_channel_vo.schedule, 'created_at': utils.datetime_to_iso8601(user_channel_vo.created_at), 'tags': change_struct_type(utils.tags_to_dict(user_channel_vo.tags)), 'domain_id': user_channel_vo.domain_id }) return user_channel_pb2.UserChannelInfo(**info)
def StorageInfo(storage_vo: Storage, minimal=False): info = { 'storage_id': storage_vo.storage_id, 'name': storage_vo.name, 'state': storage_vo.state } if not minimal: info.update({ 'tags': change_struct_type(storage_vo.tags) if storage_vo.tags else None, 'capability': change_struct_type(storage_vo.capability) if storage_vo.capability else None, 'plugin_info': PluginInfo(storage_vo.plugin_info) if storage_vo.plugin_info else None, 'user_id': storage_vo.user_id, 'domain_id': storage_vo.domain_id, 'created_at': utils.datetime_to_iso8601(storage_vo.created_at) }) return storage_pb2.StorageInfo(**info)
def ProjectGroupInfo(project_group_vo: ProjectGroup, minimal=False): info = { 'project_group_id': project_group_vo.project_group_id, 'name': project_group_vo.name } if not minimal: if project_group_vo.parent_project_group: info.update({ 'parent_project_group_info': ProjectGroupInfo(project_group_vo.parent_project_group, minimal=True) }) info.update({ 'tags': change_struct_type(utils.tags_to_dict(project_group_vo.tags)), 'domain_id': project_group_vo.domain_id, 'created_by': project_group_vo.created_by, 'created_at': utils.datetime_to_iso8601(project_group_vo.created_at) }) return project_group_pb2.ProjectGroupInfo(**info)
def ProjectChannelInfo(project_channel_vo: ProjectChannel, minimal=False): info = { 'project_channel_id': project_channel_vo.project_channel_id, 'name': project_channel_vo.name, 'state': project_channel_vo.state } if not minimal: info.update({ 'schema': project_channel_vo.schema, 'data': change_struct_type(project_channel_vo.data), 'secret_id': project_channel_vo.secret_id, 'is_subscribe': project_channel_vo.is_subscribe, 'subscriptions': change_list_value_type(project_channel_vo.subscriptions), 'notification_level': project_channel_vo.notification_level, 'protocol_id': project_channel_vo.protocol_id, 'project_id': project_channel_vo.project_id, 'is_scheduled': project_channel_vo.is_scheduled, 'schedule': ScheduleInfo(project_channel_vo.schedule) if project_channel_vo.schedule else project_channel_vo.schedule, 'created_at': utils.datetime_to_iso8601(project_channel_vo.created_at), 'tags': change_struct_type(project_channel_vo.tags), 'domain_id': project_channel_vo.domain_id }) return project_channel_pb2.ProjectChannelInfo(**info)
def ProtocolInfo(protocol_vo: Protocol, minimal=False): info = { 'protocol_id': protocol_vo.protocol_id, 'name': protocol_vo.name, 'state': protocol_vo.state } if not minimal: info.update({ 'capability': change_struct_type(protocol_vo.capability), 'protocol_type': protocol_vo.protocol_type, 'resource_type': protocol_vo.resource_type, 'plugin_info': PluginInfo(protocol_vo.plugin_info), 'created_at': utils.datetime_to_iso8601(protocol_vo.created_at), 'tags': change_struct_type(protocol_vo.tags), 'domain_id': protocol_vo.domain_id }) return protocol_pb2.ProtocolInfo(**info)
def NotificationInfo(notification_vo: Notification, minimal=False): info = { 'notification_id': notification_vo.notification_id, 'topic': notification_vo.topic, 'notification_type': notification_vo.notification_type, 'notification_level': notification_vo.notification_level } if not minimal: if notification_vo.user_id: info.update({'user_id': notification_vo.user_id}) info.update({ 'message': change_struct_type(notification_vo.message), 'is_read': notification_vo.is_read, 'created_at': utils.datetime_to_iso8601(notification_vo.created_at), 'domain_id': notification_vo.domain_id }) return notification_pb2.NotificationInfo(**info)
def DomainInfo(domain_vo: Domain, minimal=False): info = { 'domain_id': domain_vo.domain_id, 'name': domain_vo.name, 'state': domain_vo.state } if not minimal: info.update({ 'plugin_info': PluginInfo(domain_vo.plugin_info), 'config': change_struct_type(domain_vo.config), 'created_at': utils.datetime_to_iso8601(domain_vo.created_at), 'deleted_at': utils.datetime_to_iso8601(domain_vo.deleted_at), 'tags': change_struct_type(utils.tags_to_dict(domain_vo.tags)) }) return domain_pb2.DomainInfo(**info)
def SupervisorInfo(supervisor_vo): info = { 'supervisor_id': supervisor_vo.supervisor_id, 'name': supervisor_vo.name, 'hostname': supervisor_vo.hostname, 'state': supervisor_vo.state, 'is_public': supervisor_vo.is_public, 'labels': change_struct_type(supervisor_vo.labels), 'created_at': utils.datetime_to_iso8601(supervisor_vo.created_at), 'updated_at': utils.datetime_to_iso8601(supervisor_vo.updated_at), 'domain_id': supervisor_vo.domain_id } if supervisor_vo.tags: info['tags'] = change_struct_type(utils.tags_to_dict(supervisor_vo.tags)) return supervisor_pb2.SupervisorInfo(**info)
def ScheduleInfo(schedule_vo: Schedule, minimal=False): info = { 'schedule_id': schedule_vo.schedule_id, 'topic': schedule_vo.topic, 'state': schedule_vo.state, } if not minimal: info.update({ 'options': change_struct_type(schedule_vo.options) if schedule_vo.options else None, 'schedule': ScheduledInfo(schedule_vo.schedule) if schedule_vo.schedule else None, 'tags': change_struct_type(utils.tags_to_dict(schedule_vo.tags)), 'domain_id': schedule_vo.domain_id, 'created_at': utils.datetime_to_iso8601(schedule_vo.created_at), 'last_scheduled_at': utils.datetime_to_iso8601(schedule_vo.last_scheduled_at) }) return schedule_pb2.ScheduleInfo(**info)
def DomainOwnerInfo(owner_vo: DomainOwner, minimal=False): info = { 'owner_id': owner_vo.owner_id, 'name': owner_vo.name } if not minimal: info.update({ 'email': owner_vo.email, 'language': owner_vo.language, 'timezone': owner_vo.timezone, 'domain_id': owner_vo.domain_id, 'last_accessed_at': utils.datetime_to_iso8601(owner_vo.last_accessed_at), 'created_at': utils.datetime_to_iso8601(owner_vo.created_at) }) return domain_owner_pb2.DomainOwnerInfo(**info)
def SchemaInfo(schema_vo: Schema, minimal=False): info = {'name': schema_vo.name, 'service_type': schema_vo.service_type} if not minimal: info.update({ 'schema': change_struct_type(schema_vo.schema), 'labels': change_list_value_type(schema_vo.labels), 'tags': schema_vo.tags if isinstance(schema_vo.tags, Struct) else change_struct_type(utils.tags_to_dict(schema_vo.tags)), 'project_id': schema_vo.project_id, 'domain_id': schema_vo.domain_id, 'created_at': utils.datetime_to_iso8601(schema_vo.created_at) or schema_vo.created_at, 'updated_at': utils.datetime_to_iso8601(schema_vo.updated_at) or schema_vo.updated_at }) # WARNING # Based on local_schema or remote_schema # vo has different repository or repository_info field if getattr(schema_vo, 'repository', None): info.update({ 'repository_info': RepositoryInfo(schema_vo.repository, minimal=True) }) if getattr(schema_vo, 'repository_info', None): info.update({ 'repository_info': RepositoryInfo(schema_vo.repository_info, minimal=True) }) # Temporary code for DB migration if not getattr(schema_vo, 'repository_id', None) and getattr( schema_vo, 'repository', None): schema_vo.update( {'repository_id': schema_vo.repository.repository_id}) return schema_pb2.SchemaInfo(**info)
def PolicyInfo(policy_vo: Policy, minimal=False): info = {'policy_id': policy_vo.policy_id, 'name': policy_vo.name} if not minimal: info.update({ 'permissions': change_list_value_type(policy_vo.permissions), 'labels': change_list_value_type(policy_vo.labels), 'tags': policy_vo.tags if isinstance(policy_vo.tags, Struct) else change_struct_type(utils.tags_to_dict(policy_vo.tags)), 'project_id': policy_vo.project_id, 'domain_id': policy_vo.domain_id, 'created_at': utils.datetime_to_iso8601(policy_vo.created_at) or policy_vo.created_at, 'updated_at': utils.datetime_to_iso8601(policy_vo.updated_at) or policy_vo.updated_at }) # WARNING # Based on local_policy or remote_policy # vo has different repository or repository_info field if getattr(policy_vo, 'repository', None): info.update({ 'repository_info': RepositoryInfo(policy_vo.repository, minimal=True) }) if getattr(policy_vo, 'repository_info', None): info.update({ 'repository_info': RepositoryInfo(policy_vo.repository_info, minimal=True) }) # Temporary code for DB migration if not getattr(policy_vo, 'repository_id', None) and getattr( policy_vo, 'repository', None): policy_vo.update( {'repository_id': policy_vo.repository.repository_id}) return policy_pb2.PolicyInfo(**info)
def HistoryValueInfo(history_vo: History, minimal=False): info = { 'topic': history_vo.topic, 'values': change_struct_type(history_vo.values) if history_vo.values else None, 'created_at': utils.datetime_to_iso8601(history_vo.created_at), 'domain_id': history_vo.domain_id } return history_pb2.HistoryValueInfo(**info)
def APIKeyInfo(api_key_vo: APIKey, minimal=False, api_key=None, **kwargs): info = { 'api_key': api_key, 'api_key_id': api_key_vo.api_key_id, 'state': api_key_vo.state, 'user_id': api_key_vo.user_id } if not minimal: info.update({ 'domain_id': api_key_vo.domain_id, 'last_accessed_at': utils.datetime_to_iso8601(api_key_vo.last_accessed_at), 'created_at': utils.datetime_to_iso8601(api_key_vo.created_at) }) return api_key_pb2.APIKeyInfo(**info)
def MaintenanceWindowInfo(maintenance_window_vo: MaintenanceWindow, minimal=False): info = { 'maintenance_window_id': maintenance_window_vo.maintenance_window_id, 'title': maintenance_window_vo.title, 'state': maintenance_window_vo.state, 'projects': maintenance_window_vo.projects, 'start_time': utils.datetime_to_iso8601(maintenance_window_vo.start_time), 'end_time': utils.datetime_to_iso8601(maintenance_window_vo.end_time) } if not minimal: info.update({ 'tags': change_struct_type(maintenance_window_vo.tags), 'domain_id': maintenance_window_vo.domain_id, 'created_by': maintenance_window_vo.created_by, 'created_at': utils.datetime_to_iso8601(maintenance_window_vo.created_at), 'updated_at': utils.datetime_to_iso8601(maintenance_window_vo.updated_at), 'closed_at': utils.datetime_to_iso8601(maintenance_window_vo.closed_at) }) return maintenance_window_pb2.MaintenanceWindowInfo(**info)
def UserInfo(user_vo: User, minimal=False): info = { 'user_id': user_vo.user_id, 'name': user_vo.name, 'state': user_vo.state, 'user_type': user_vo.user_type } if not minimal: info.update({ 'email': user_vo.email, 'backend': user_vo.backend, 'language': user_vo.language, 'timezone': user_vo.timezone, 'tags': change_struct_type(utils.tags_to_dict(user_vo.tags)), 'domain_id': user_vo.domain_id, 'last_accessed_at': utils.datetime_to_iso8601(user_vo.last_accessed_at), 'created_at': utils.datetime_to_iso8601(user_vo.created_at) }) return user_pb2.UserInfo(**info)