Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

CIRCLE / cloud

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 94
  • Merge Requests 10
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Merged
Merge request !48 opened Mar 23, 2014 by Dudás Ádám@siliconbrain 
  • Report abuse
Report abuse

operations #69

  • Operation abstract class.
  • OperatedMixin.
  • Port old method + method_async pairs to Operation subclasses.
  • Merge async tasks to a single one.
  • ???
  • 🚧 Tests.

fixes #69 (closed)

  • Discussion 14
  • Commits 47
  • Changes
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Őry Máté
    @orymate started a discussion on an old version of the diff Mar 24, 2014
    Last updated by Őry Máté Mar 24, 2014
    circle/vm/models/instance.py
    255 254  
    256 255 self.instance = instance
    257 256  
    257 def __getattr__(self, name):
    258 if name in self._ops:
    259 return self._ops[name](self)
    260 else:
    261 raise AttributeError("%s object has no attribute '%s'" %
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      else: super??

      else: super??
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      (comment about no need to call super unless super's getattr is custom) (fixed)

      Edited Mar 26, 2014
      (comment about no need to call super unless super's getattr is custom) (fixed)
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Mar 24, 2014
    circle/vm/models/operation.py
    30 self.instance = instance
    31
    32 def __call__(self, **kwargs):
    33 """Execute the operation synchronously.
    34 """
    35 activity = self.__prelude(kwargs)
    36 return self._exec_op(activity=activity, **kwargs)
    37
    38 def __unicode__(self):
    39 return self.name
    40
    41 def __prelude(self, kwargs):
    42 """This method contains the shared prelude of __call__ and async.
    43 """
    44 user = kwargs.setdefault('user', None)
    45 self.check_auth(user) # TODO what's check_auth's specification?
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      ~ instance.has_level(user, self.acl_level) and user.has_perms(self.required_perms) (fixed)

      Edited Mar 26, 2014
      ~ instance.has_level(user, self.acl_level) and user.has_perms(self.required_perms) (fixed)
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Mar 24, 2014
    circle/vm/models/operation.py
    9
    10 from common.models import activity_context
    11 from storage.models import Disk
    12 from ..tasks import vm_tasks
    13 from ..tasks.local_tasks import async_operation
    14 from .activity import InstanceActivity
    15 from .instance import Instance, InstanceTemplate
    16
    17
    18 logger = getLogger(__name__)
    19
    20
    21 class Operation:
    22 """Base class for VM operations.
    23 """
    24 acl_level = 'owner'
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      required_perms = () (fixed)

      Edited Mar 26, 2014
      required_perms = () (fixed)
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Mar 24, 2014
    circle/vm/models/operation.py
    46 self.check_precond()
    47 return self.create_activity(user=user)
    48
    49 def _exec_op(self, activity, user=None, **kwargs):
    50 """Execute the operation inside the specified activity's context.
    51 """
    52 with activity_context(activity, on_abort=self.on_abort,
    53 on_commit=self.on_commit):
    54 return self._operation(activity, user, **kwargs)
    55
    56 def _operation(self, activity, user=None, **kwargs):
    57 """This method is the operation's particular implementation.
    58
    59 Deriving classes should implement this method.
    60 """
    61 pass
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      raise NotImplementedError() (fixed)

      Edited Mar 26, 2014
      raise NotImplementedError() (fixed)
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Mar 24, 2014
    circle/vm/models/operation.py
    51 """
    52 with activity_context(activity, on_abort=self.on_abort,
    53 on_commit=self.on_commit):
    54 return self._operation(activity, user, **kwargs)
    55
    56 def _operation(self, activity, user=None, **kwargs):
    57 """This method is the operation's particular implementation.
    58
    59 Deriving classes should implement this method.
    60 """
    61 pass
    62
    63 def async(self, **kwargs):
    64 """Execute the operation asynchronously.
    65
    66 Only a quick, preliminary check is ran before queuing the job.
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      and what about pre-creating activity? (fixed)

      Edited Apr 03, 2014
      ~~and what about pre-creating activity?~~ (fixed)
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on the diff Mar 24, 2014
    circle/vm/tasks/local_tasks.py
    48 def reset(instance, user):
    49 instance.reset(task_uuid=reset.request.id, user=user)
    50
    51
    52 @celery.task
    53 def reboot(instance, user):
    54 instance.reboot(task_uuid=reboot.request.id, user=user)
    55
    56
    57 @celery.task
    58 def migrate(instance, to_node, user):
    59 instance.migrate(to_node, task_uuid=migrate.request.id, user=user)
    60
    61
    62 @celery.task
    63 def flush(node, user):
    • Őry Máté @orymate commented Mar 24, 2014
      Owner

      this was a Node operation! (fixed)

      Edited Mar 26, 2014
      this was a Node operation! (fixed)
    Please register or sign in to reply
  • Őry Máté @orymate commented Mar 31, 2014
    Owner

    any progress here? can I help?

    Edited Apr 02, 2014
    ~~any progress here? can I help?~~
  • Őry Máté
    @orymate started a discussion on the diff Apr 02, 2014
    circle/vm/__init__.py
    1 from . import operations # noqa
    • Őry Máté @orymate commented Apr 02, 2014
      Owner

      I'd add a comment about this instruction registers the ops. fixed 299383c0

      Edited Apr 02, 2014
      ~~I'd add a comment about this instruction registers the ops.~~ fixed 299383c0
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Apr 02, 2014
    circle/vm/models/instance.py
    1184 tmpl.full_clean() # Avoiding database errors.
    1185 tmpl.save()
    1186 try:
    1187 with act.sub_activity('saving_disks'):
    1188 tmpl.disks.add(*[__try_save_disk(disk)
    1189 for disk in self.disks.all()])
    1190 # create interface templates
    1191 for i in self.interface_set.all():
    1192 i.save_as_template(tmpl)
    1193 except:
    1194 tmpl.delete()
    1195 raise
    1196 else:
    1197 return tmpl
    1198
    1199 818 def shutdown_and_save_as_template(self, name, user=None, task_uuid=None,
    • Őry Máté @orymate commented Apr 02, 2014
      Owner

      Should also be an Operation (if technically possible). This is normally called when the user wants to save a vm.

      Should also be an Operation (if technically possible). *This* is normally called when the user wants to save a vm.
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff Apr 02, 2014
    circle/vm/operations.py
    165 class RebootOperation(InstanceOperation):
    166 activity_code_suffix = 'reboot'
    167 id = 'reboot'
    168 name = _("reboot")
    169 description = _("""Reboot virtual machine with Ctrl+Alt+Del signal.""")
    170
    171 def _operation(self, activity, user, system, timeout=5):
    172 queue_name = self.instance.get_remote_queue_name('vm')
    173 vm_tasks.reboot.apply_async(args=[self.instance.vm_name],
    174 queue=queue_name).get(timeout=timeout)
    175
    176
    177 register_instance_operation(RebootOperation)
    178
    179
    180 class RedeployOperation(InstanceOperation):
    • Őry Máté @orymate commented Apr 02, 2014
      Owner

      should override precond checks, this works on destroyed Instances.

      should override precond checks, this works on destroyed Instances.
    Please register or sign in to reply
  • Őry Máté @orymate commented Apr 02, 2014
    Owner

    Some amount of logging could be added to operation base class' methods.

    Edited Apr 02, 2014
    Some amount of logging could be added to operation base class' methods.
  • Őry Máté @orymate commented Apr 02, 2014
    Owner

    👍 remek munka!

    :+1: remek munka!
  • Őry Máté
    @orymate started a discussion on commit 299383c0 Apr 02, 2014
    • Őry Máté @orymate

      mentioned in merge request !48 (merged)

      Apr 02, 2014

      mentioned in merge request !48 (merged)

      mentioned in merge request !48
      Toggle commit list
    Please register or sign in to reply
  • Bach Dániel @bachdaniel commented Apr 03, 2014
    Owner

    👍

    :+1:
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View labels
3
3 participants
Reference: circle/cloud!48