Skip to content

Commit d776019

Browse files
authored
Merge pull request nerc-project#220 from QuanMPhm/209/linter
Applied pre-commit hook
2 parents fd81008 + f9a9ef1 commit d776019

33 files changed

+1526
-1215
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
default_app_config = 'coldfront_plugin_cloud.apps.OpenStackConfig'
1+
default_app_config = "coldfront_plugin_cloud.apps.OpenStackConfig"

src/coldfront_plugin_cloud/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class OpenStackConfig(AppConfig):
5-
name = 'coldfront_plugin_cloud'
5+
name = "coldfront_plugin_cloud"
66

77
def ready(self):
8-
import coldfront_plugin_cloud.signals
8+
import coldfront_plugin_cloud.signals # noqa: F401

src/coldfront_plugin_cloud/attributes.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@
44
@dataclass
55
class CloudResourceAttribute:
66
"""Class for configuring Cloud Resource Attributes"""
7+
78
name: str
8-
type: str = 'Text'
9+
type: str = "Text"
910

1011

1112
@dataclass
1213
class CloudAllocationAttribute:
1314
"""Class for configuring Cloud Allocation Attributes"""
15+
1416
name: str
15-
type: str = 'Int'
17+
type: str = "Int"
1618
has_usage: bool = False
1719
is_private: bool = False
1820
is_changeable: bool = True
1921

2022

21-
RESOURCE_AUTH_URL = 'Identity Endpoint URL'
22-
RESOURCE_API_URL = 'OpenShift API Endpoint URL'
23-
RESOURCE_IDENTITY_NAME = 'OpenShift Identity Provider Name'
24-
RESOURCE_ROLE = 'Role for User in Project'
23+
RESOURCE_AUTH_URL = "Identity Endpoint URL"
24+
RESOURCE_API_URL = "OpenShift API Endpoint URL"
25+
RESOURCE_IDENTITY_NAME = "OpenShift Identity Provider Name"
26+
RESOURCE_ROLE = "Role for User in Project"
2527

26-
RESOURCE_FEDERATION_PROTOCOL = 'OpenStack Federation Protocol'
27-
RESOURCE_IDP = 'OpenStack Identity Provider'
28-
RESOURCE_PROJECT_DOMAIN = 'OpenStack Domain for Projects'
29-
RESOURCE_USER_DOMAIN = 'OpenStack Domain for Users'
30-
RESOURCE_DEFAULT_PUBLIC_NETWORK = 'OpenStack Public Network ID'
31-
RESOURCE_DEFAULT_NETWORK_CIDR = 'OpenStack Default Network CIDR'
28+
RESOURCE_FEDERATION_PROTOCOL = "OpenStack Federation Protocol"
29+
RESOURCE_IDP = "OpenStack Identity Provider"
30+
RESOURCE_PROJECT_DOMAIN = "OpenStack Domain for Projects"
31+
RESOURCE_USER_DOMAIN = "OpenStack Domain for Users"
32+
RESOURCE_DEFAULT_PUBLIC_NETWORK = "OpenStack Public Network ID"
33+
RESOURCE_DEFAULT_NETWORK_CIDR = "OpenStack Default Network CIDR"
3234

3335
RESOURCE_EULA_URL = "EULA URL"
3436

@@ -47,55 +49,49 @@ class CloudAllocationAttribute:
4749
]
4850

4951
# TODO: Migration to rename the OpenStack specific prefix out of these attrs
50-
ALLOCATION_PROJECT_ID = 'Allocated Project ID'
51-
ALLOCATION_PROJECT_NAME = 'Allocated Project Name'
52-
ALLOCATION_INSTITUTION_SPECIFIC_CODE = 'Institution-Specific Code'
52+
ALLOCATION_PROJECT_ID = "Allocated Project ID"
53+
ALLOCATION_PROJECT_NAME = "Allocated Project Name"
54+
ALLOCATION_INSTITUTION_SPECIFIC_CODE = "Institution-Specific Code"
5355

5456
ALLOCATION_ATTRIBUTES = [
5557
CloudAllocationAttribute(
56-
name=ALLOCATION_PROJECT_ID,
57-
type='Text',
58-
is_changeable=False
58+
name=ALLOCATION_PROJECT_ID, type="Text", is_changeable=False
5959
),
6060
CloudAllocationAttribute(
61-
name=ALLOCATION_PROJECT_NAME,
62-
type='Text',
63-
is_changeable=False
61+
name=ALLOCATION_PROJECT_NAME, type="Text", is_changeable=False
6462
),
6563
CloudAllocationAttribute(
66-
name=ALLOCATION_INSTITUTION_SPECIFIC_CODE,
67-
type='Text',
68-
is_changeable=True
64+
name=ALLOCATION_INSTITUTION_SPECIFIC_CODE, type="Text", is_changeable=True
6965
),
7066
]
7167

7268
###########################################################
7369
# OpenStack Quota Attributes
74-
QUOTA_INSTANCES = 'OpenStack Compute Instance Quota'
75-
QUOTA_RAM = 'OpenStack Compute RAM Quota (MiB)'
76-
QUOTA_VCPU = 'OpenStack Compute vCPU Quota'
70+
QUOTA_INSTANCES = "OpenStack Compute Instance Quota"
71+
QUOTA_RAM = "OpenStack Compute RAM Quota (MiB)"
72+
QUOTA_VCPU = "OpenStack Compute vCPU Quota"
7773

78-
QUOTA_VOLUMES = 'OpenStack Number of Volumes Quota'
79-
QUOTA_VOLUMES_GB = 'OpenStack Volume Quota (GiB)'
74+
QUOTA_VOLUMES = "OpenStack Number of Volumes Quota"
75+
QUOTA_VOLUMES_GB = "OpenStack Volume Quota (GiB)"
8076

81-
QUOTA_FLOATING_IPS = 'OpenStack Floating IP Quota'
82-
QUOTA_NETWORKS = 'Openstack Network Quota'
77+
QUOTA_FLOATING_IPS = "OpenStack Floating IP Quota"
78+
QUOTA_NETWORKS = "Openstack Network Quota"
8379

84-
QUOTA_OBJECT_GB = 'OpenStack Swift Quota (GiB)'
80+
QUOTA_OBJECT_GB = "OpenStack Swift Quota (GiB)"
8581

86-
QUOTA_GPU = 'OpenStack GPU Quota'
82+
QUOTA_GPU = "OpenStack GPU Quota"
8783

8884
###########################################################
8985
# OpenShift Quota Attributes
90-
QUOTA_LIMITS_CPU = 'OpenShift Limit on CPU Quota'
91-
QUOTA_LIMITS_MEMORY = 'OpenShift Limit on RAM Quota (MiB)'
92-
QUOTA_LIMITS_EPHEMERAL_STORAGE_GB = 'OpenShift Limit on Ephemeral Storage Quota (GiB)'
93-
QUOTA_REQUESTS_STORAGE = 'OpenShift Request on Storage Quota (GiB)'
94-
QUOTA_REQUESTS_GPU = 'OpenShift Request on GPU Quota'
95-
QUOTA_REQUESTS_VM_GPU_A100_SXM4 = 'OpenShift Request on GPU A100 SXM4'
96-
QUOTA_REQUESTS_VM_GPU_V100 = 'OpenShift Request on GPU V100'
97-
QUOTA_REQUESTS_VM_GPU_H100 = 'OpenShift Request on GPU H100'
98-
QUOTA_PVC = 'OpenShift Persistent Volume Claims Quota'
86+
QUOTA_LIMITS_CPU = "OpenShift Limit on CPU Quota"
87+
QUOTA_LIMITS_MEMORY = "OpenShift Limit on RAM Quota (MiB)"
88+
QUOTA_LIMITS_EPHEMERAL_STORAGE_GB = "OpenShift Limit on Ephemeral Storage Quota (GiB)"
89+
QUOTA_REQUESTS_STORAGE = "OpenShift Request on Storage Quota (GiB)"
90+
QUOTA_REQUESTS_GPU = "OpenShift Request on GPU Quota"
91+
QUOTA_REQUESTS_VM_GPU_A100_SXM4 = "OpenShift Request on GPU A100 SXM4"
92+
QUOTA_REQUESTS_VM_GPU_V100 = "OpenShift Request on GPU V100"
93+
QUOTA_REQUESTS_VM_GPU_H100 = "OpenShift Request on GPU H100"
94+
QUOTA_PVC = "OpenShift Persistent Volume Claims Quota"
9995

10096

10197
ALLOCATION_QUOTA_ATTRIBUTES = [

src/coldfront_plugin_cloud/base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010

1111
class ResourceAllocator(abc.ABC):
12-
13-
resource_type = ''
12+
resource_type = ""
1413

1514
project_name_max_length = None
1615

1716
class Project(NamedTuple):
1817
name: str
1918
id: str
2019

21-
def __init__(self,
22-
resource: resource_models.Resource,
23-
allocation: allocation_models.Allocation):
20+
def __init__(
21+
self,
22+
resource: resource_models.Resource,
23+
allocation: allocation_models.Allocation,
24+
):
2425
self.resource = resource
2526
self.allocation = allocation
2627

@@ -35,7 +36,7 @@ def auth_url(self):
3536

3637
@functools.cached_property
3738
def member_role_name(self):
38-
return self.resource.get_attribute(attributes.RESOURCE_ROLE) or 'member'
39+
return self.resource.get_attribute(attributes.RESOURCE_ROLE) or "member"
3940

4041
@abc.abstractmethod
4142
def create_project(self, suggested_project_name) -> Project:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from coldfront.config.base import INSTALLED_APPS
2-
from coldfront.config.env import ENV
2+
from coldfront.config.env import ENV # noqa: F401
33

4-
if 'coldfront_plugin_cloud' not in INSTALLED_APPS:
4+
if "coldfront_plugin_cloud" not in INSTALLED_APPS:
55
INSTALLED_APPS += [
6-
'coldfront_plugin_cloud',
6+
"coldfront_plugin_cloud",
77
]

src/coldfront_plugin_cloud/esi.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import logging
2-
import functools
3-
import os
4-
5-
from keystoneauth1.identity import v3
6-
from keystoneauth1 import session
7-
8-
from coldfront_plugin_cloud import attributes, utils
1+
from coldfront_plugin_cloud import attributes
92
from coldfront_plugin_cloud.openstack import OpenStackResourceAllocator
103

11-
class ESIResourceAllocator(OpenStackResourceAllocator):
124

5+
class ESIResourceAllocator(OpenStackResourceAllocator):
136
QUOTA_KEY_MAPPING = {
14-
'network': {
15-
'keys': {
16-
attributes.QUOTA_FLOATING_IPS: 'floatingip',
17-
attributes.QUOTA_NETWORKS: 'network'
7+
"network": {
8+
"keys": {
9+
attributes.QUOTA_FLOATING_IPS: "floatingip",
10+
attributes.QUOTA_NETWORKS: "network",
1811
}
1912
}
2013
}
2114

22-
QUOTA_KEY_MAPPING_ALL_KEYS = {quota_key: quota_name for k in QUOTA_KEY_MAPPING.values() for quota_key, quota_name in k['keys'].items()}
15+
QUOTA_KEY_MAPPING_ALL_KEYS = {
16+
quota_key: quota_name
17+
for k in QUOTA_KEY_MAPPING.values()
18+
for quota_key, quota_name in k["keys"].items()
19+
}
2320

24-
resource_type = 'esi'
21+
resource_type = "esi"
2522

2623
def get_quota(self, project_id):
2724
quotas = dict()
Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,92 @@
11
from django.core.management.base import BaseCommand
2-
from django.core.management import call_command
32

4-
from coldfront.core.resource.models import (Resource,
5-
ResourceAttribute,
6-
ResourceAttributeType,
7-
ResourceType)
3+
from coldfront.core.resource.models import (
4+
Resource,
5+
ResourceAttribute,
6+
ResourceAttributeType,
7+
ResourceType,
8+
)
89

910
from coldfront_plugin_cloud import attributes
1011

1112

1213
class Command(BaseCommand):
13-
help = 'Create OpenShift resource'
14+
help = "Create OpenShift resource"
1415

1516
def add_arguments(self, parser):
16-
parser.add_argument('--name', type=str, required=True,
17-
help='Name of OpenShift resource')
18-
parser.add_argument('--auth-url', type=str, required=True,
19-
help='URL of the openshift-acct-mgt endpoint')
20-
parser.add_argument('--api-url', type=str, required=True,
21-
help='API URL of the openshift cluster')
22-
parser.add_argument('--idp', type=str, required=True,
23-
help='Name of Openshift identity provider')
24-
parser.add_argument('--role', type=str, default='edit',
25-
help='Role for user when added to project (default: edit)')
26-
parser.add_argument('--for-virtualization', action='store_true',
27-
help='Indicates this is an Openshift Virtualization resource (default: False)')
17+
parser.add_argument(
18+
"--name", type=str, required=True, help="Name of OpenShift resource"
19+
)
20+
parser.add_argument(
21+
"--auth-url",
22+
type=str,
23+
required=True,
24+
help="URL of the openshift-acct-mgt endpoint",
25+
)
26+
parser.add_argument(
27+
"--api-url",
28+
type=str,
29+
required=True,
30+
help="API URL of the openshift cluster",
31+
)
32+
parser.add_argument(
33+
"--idp", type=str, required=True, help="Name of Openshift identity provider"
34+
)
35+
parser.add_argument(
36+
"--role",
37+
type=str,
38+
default="edit",
39+
help="Role for user when added to project (default: edit)",
40+
)
41+
parser.add_argument(
42+
"--for-virtualization",
43+
action="store_true",
44+
help="Indicates this is an Openshift Virtualization resource (default: False)",
45+
)
2846

2947
def handle(self, *args, **options):
30-
31-
if options['for_virtualization']:
32-
resource_description = 'OpenShift Virtualization environment'
33-
resource_type = 'OpenShift Virtualization'
48+
if options["for_virtualization"]:
49+
resource_description = "OpenShift Virtualization environment"
50+
resource_type = "OpenShift Virtualization"
3451
else:
35-
resource_description = 'OpenShift cloud environment'
36-
resource_type = 'OpenShift'
52+
resource_description = "OpenShift cloud environment"
53+
resource_type = "OpenShift"
3754

3855
openshift, _ = Resource.objects.get_or_create(
3956
resource_type=ResourceType.objects.get(name=resource_type),
4057
parent_resource=None,
41-
name=options['name'],
58+
name=options["name"],
4259
description=resource_description,
4360
is_available=True,
4461
is_public=True,
45-
is_allocatable=True
62+
is_allocatable=True,
4663
)
4764

4865
ResourceAttribute.objects.get_or_create(
4966
resource_attribute_type=ResourceAttributeType.objects.get(
50-
name=attributes.RESOURCE_AUTH_URL),
67+
name=attributes.RESOURCE_AUTH_URL
68+
),
5169
resource=openshift,
52-
value=options['auth_url']
70+
value=options["auth_url"],
5371
)
5472
ResourceAttribute.objects.get_or_create(
5573
resource_attribute_type=ResourceAttributeType.objects.get(
56-
name=attributes.RESOURCE_API_URL),
74+
name=attributes.RESOURCE_API_URL
75+
),
5776
resource=openshift,
58-
value=options['api_url']
77+
value=options["api_url"],
5978
)
6079
ResourceAttribute.objects.get_or_create(
6180
resource_attribute_type=ResourceAttributeType.objects.get(
62-
name=attributes.RESOURCE_IDENTITY_NAME),
81+
name=attributes.RESOURCE_IDENTITY_NAME
82+
),
6383
resource=openshift,
64-
value=options['idp']
84+
value=options["idp"],
6585
)
6686
ResourceAttribute.objects.get_or_create(
6787
resource_attribute_type=ResourceAttributeType.objects.get(
68-
name=attributes.RESOURCE_ROLE),
88+
name=attributes.RESOURCE_ROLE
89+
),
6990
resource=openshift,
70-
value=options['role']
91+
value=options["role"],
7192
)

0 commit comments

Comments
 (0)