Skip to content

Commit 1536176

Browse files
committed
Began some PEP8 / pyflakes-inspired code cleanup.
1 parent 50df654 commit 1536176

9 files changed

Lines changed: 127 additions & 102 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ task:
1111
python manage.py test celerytasks
1212

1313
pep8:
14-
pep8 api celerytasks deis web
14+
pep8 api celerytasks deis web --exclude=migrations
1515

1616
pyflakes:
1717
pyflakes api celerytasks deis web

api/fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class ParamsField(JSONField):
8888
A text field that accepts a JSON object, used for storing provider
8989
API Parameters.
9090
"""
91+
pass
92+
9193

9294
class CloudInitField(YAMLField):
9395
"""
@@ -107,7 +109,7 @@ class NodeStatusField(JSONField):
107109

108110
try:
109111
from south.modelsinspector import add_introspection_rules
110-
# Tell the South schema migration tool to handle a UuidField.
112+
# Tell the South schema migration tool to handle our custom fields.
111113
add_introspection_rules([], [r'^api\.fields\.UuidField'])
112114
add_introspection_rules([], [r'^api\.fields\.EnvVarsField'])
113115
add_introspection_rules([], [r'^api\.fields\.DataBagField'])

api/models.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from rest_framework.authtoken.models import Token
2020

2121
from api import fields
22-
from celerytasks import chef, controller
22+
from celerytasks import controller
2323
from celery.canvas import group
2424

2525

@@ -235,7 +235,7 @@ class Formation(UuidAuditedModel):
235235
ssh_username = models.CharField(max_length=64, default='ubuntu')
236236
ssh_private_key = models.TextField()
237237
ssh_public_key = models.TextField()
238-
238+
239239
class Meta:
240240
unique_together = (('owner', 'id'),)
241241

@@ -350,7 +350,7 @@ def balance(self, **kwargs):
350350
if containers_balanced:
351351
self.converge(databag)
352352
return databag
353-
353+
354354
def _balance_containers(self, **kwargs):
355355
backends = self.backend_set.all().order_by('created')
356356
if len(backends) < 2:
@@ -361,10 +361,10 @@ def _balance_containers(self, **kwargs):
361361
changed = False
362362
# iterate by unique container type
363363
for container_type in set([c.type for c in all_containers]):
364-
# map backend container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
364+
# map backend container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
365365
b_map = {}
366366
for b in backends:
367-
ct = len(b.node.container_set.filter(type=container_type))
367+
ct = len(b.node.container_set.filter(type=container_type))
368368
b_map.setdefault(ct, []).append(b)
369369
# loop until diff between min and max is 1 or 0
370370
while max(b_map.keys()) - min(b_map.keys()) > 1:
@@ -394,7 +394,7 @@ def _balance_containers(self, **kwargs):
394394
b_map.setdefault(ct, []).append(b)
395395
changed = True
396396
return changed
397-
397+
398398
def __str__(self):
399399
return self.id
400400

@@ -403,7 +403,7 @@ def prepare_provider(self, *args, **kwargs):
403403
args = (self.id, self.flavor.provider.creds.copy(),
404404
self.flavor.params.copy())
405405
return tasks.prepare_formation.subtask(args)
406-
406+
407407
def calculate(self):
408408
"Return a Chef data bag item for this formation"
409409
release = self.release_set.all().order_by('-created')[0]
@@ -448,12 +448,12 @@ def converge(self, databag):
448448
if settings.CHEF_ENABLED:
449449
controller.update_formation.delay(self.id, databag).wait() # @UndefinedVariable
450450
# converge all backends
451-
backend_nodes = [ b.node for b in self.backend_set.all() ]
452-
job = group(*[ n.converge() for n in backend_nodes ])
451+
backend_nodes = [b.node for b in self.backend_set.all()]
452+
job = group(*[n.converge() for n in backend_nodes])
453453
_results = job.apply_async().join()
454454
# converge all proxies
455-
proxy_nodes = [ b.node for b in self.proxy_set.all() ]
456-
job = group(*[ n.converge() for n in proxy_nodes ])
455+
proxy_nodes = [b.node for b in self.proxy_set.all()]
456+
job = group(*[n.converge() for n in proxy_nodes])
457457
_results = job.apply_async().join()
458458
return databag
459459

@@ -464,8 +464,8 @@ def destroy(self):
464464
if settings.CHEF_ENABLED:
465465
subtasks.extend([controller.destroy_formation.s(self.id)]) # @UndefinedVariable
466466
# create subtasks to terminate all nodes in parallel
467-
subtasks.extend([ b.node.terminate() for b in self.backend_set.all() ])
468-
subtasks.extend([ p.node.terminate() for p in self.proxy_set.all() ])
467+
subtasks.extend([b.node.terminate() for b in self.backend_set.all()])
468+
subtasks.extend([p.node.terminate() for p in self.proxy_set.all()])
469469
job = group(*subtasks)
470470
job.apply_async().join() # block for termination
471471
# purge other hosting provider infrastructure
@@ -500,7 +500,7 @@ class Node(UuidAuditedModel):
500500
List of nodes available as `formation.nodes`
501501
"""
502502
objects = NodeManager()
503-
503+
504504
NODE_TYPES = (
505505
('backend', 'Backend'),
506506
('proxy', 'Proxy'),
@@ -693,7 +693,7 @@ class Config(UuidAuditedModel):
693693
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
694694
formation = models.ForeignKey('Formation')
695695
version = models.PositiveIntegerField(default=1)
696-
696+
697697
values = fields.EnvVarsField(default='{}', blank=True)
698698

699699
class Meta:
@@ -714,7 +714,7 @@ class Build(UuidAuditedModel):
714714
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
715715
formation = models.ForeignKey('Formation')
716716
version = models.PositiveIntegerField(default=1)
717-
717+
718718
sha = models.CharField('SHA', max_length=255, blank=True)
719719
output = models.TextField(blank=True)
720720
# metadata
@@ -743,7 +743,7 @@ class Release(UuidAuditedModel):
743743
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
744744
formation = models.ForeignKey('Formation')
745745
version = models.PositiveIntegerField(default=1)
746-
746+
747747
config = models.ForeignKey('Config')
748748
image = models.CharField(max_length=256, default='ubuntu')
749749
# build only required for heroku-style apps
@@ -757,7 +757,7 @@ class Meta:
757757

758758
def __str__(self):
759759
return '{0}-v{1}'.format(self.formation.id, self.version)
760-
760+
761761
def rollback(self):
762762
# create a rollback log entry
763763
# call run
@@ -787,7 +787,7 @@ def new_release(sender, **kwargs):
787787
owner=user, formation=formation, values=new_values)
788788
# create new release and auto-increment version
789789
new_version = last_release.version + 1
790-
release = Release.objects.create(owner=user, formation=formation,
790+
release = Release.objects.create(owner=user, formation=formation,
791791
image=image, config=config, build=build, args=args, command=command,
792792
version=new_version)
793793
return release

celerytasks/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

celerytasks/azuresms.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

22
from __future__ import unicode_literals
3-
import json
4-
import time
53

64
from azure.servicemanagement import ServiceManagementService
75
from azure.servicemanagement import LinuxConfigurationSet, OSVirtualHardDisk
@@ -10,9 +8,6 @@
108
import yaml
119

1210
from . import util
13-
from api.models import Node
14-
from deis import settings
15-
from celerytasks.chef import ChefAPI
1611

1712
@task(name='azuresms.launch_node')
1813
def launch_node(node_id, creds, params, init, ssh_username, ssh_private_key):

0 commit comments

Comments
 (0)