# Path: smc/base/model.py
# class SubElement(ElementBase):
#     """
#     SubElement is the base class for elements that do not
#     have direct entry points in the SMC and instead are obtained
#     through a reference. They are not 'loaded' directly as are
#     classes that inherit from :class:`Element`.
#     """
# 
#     def __init__(self, **meta):
#         super(SubElement, self).__init__(**meta)
# 
#     @property
#     def name(self):
#         return self._meta.name if self._meta else None
# 
#     @property
#     def href(self):
#         return self._meta.href if self._meta else None
# 
# Path: smc/administration/tasks.py
# class Task(SubElement):
#     """
#     Task representation. This is generic and the format is used for
#     any calls to SMC that return an asynchronous follower link to
#     check the status of the task.
# 
#     :param str last_message: Last message received on this task
#     :param bool in_progress: Whether the task is in progress or finished
#     :param bool success: Whether the task succeeded or not
#     :param str follower: Fully qualified path to the follower link to track
#         this task.
#     """
#     def __init__(self, task):
#         super(Task, self).__init__(
#             href=task.get('follower', None),
#             name=task.get('type', None))
#         self.data = ElementCache(task)
# 
#     @property
#     def resource(self):
#         """
#         The resource/s associated with this task
# 
#         :rtype: list(Element)
#         """
#         return [Element.from_href(resource)
#                 for resource in self.data.get('resource', [])]
# 
#     @property
#     def progress(self):
#         """
#         Percentage of completion
# 
#         :rtype: int
#         """
#         return self.data.get('progress', 0)
# 
#     @property
#     def start_time(self):
#         """
#         Task start time in UTC datetime format
# 
#         :rtype: datetime
#         """
#         start_time = self.data.get('start_time')
#         if start_time:
#             return millis_to_utc(start_time)
# 
#     @property
#     def end_time(self):
#         """
#         Task end time in UTC datetime format
# 
#         :rtype: datetime
#         """
#         end_time = self.data.get('end_time')
#         if end_time:
#             return millis_to_utc(end_time)
# 
#     def abort(self):
#         """
#         Abort existing task.
# 
#         :raises ActionCommandFailed: aborting task failed with reason
#         :return: None
#         """
#         try:
#             self.make_request(
#                 method='delete',
#                 resource='abort')
#     
#         except ResourceNotFound:
#             pass
#         except ActionCommandFailed:
#             pass
# 
#     @property
#     def result_url(self):
#         """
#         Link to result (this task)
# 
#         :rtype: str
#         """
#         return self.get_relation('result')
# 
#     def update_status(self):
#         """
#         Gets the current status of this task and returns a
#         new task object.
# 
#         :raises TaskRunFailed: fail to update task status
#         """
#         task = self.make_request(
#             TaskRunFailed,
#             href=self.href)
# 
#         return Task(task)
#     
#     def __getattr__(self, key):
#         return self.data.get(key)
#     
#     @staticmethod
#     def execute(self, resource, **kw):
#         """
#         Execute the task and return a TaskOperationPoller.
#         
#         :rtype: TaskOperationPoller
#         """
#         params = kw.pop('params', {})
#         json = kw.pop('json', None)
#         task = self.make_request(
#             TaskRunFailed,
#             method='create',
#             params=params,
#             json=json,
#             resource=resource)
# 
#         timeout = kw.pop('timeout', 5)
#         wait_for_finish = kw.pop('wait_for_finish', True)
#         
#         return TaskOperationPoller(
#             task=task, timeout=timeout,
#             wait_for_finish=wait_for_finish,
#             **kw)
# 
#     @staticmethod
#     def download(self, resource, filename, **kw):
#         """
#         Start and return a Download Task
#         
#         :rtype: DownloadTask(TaskOperationPoller)
#         """
#         params = kw.pop('params', {})
#         task = self.make_request(
#             TaskRunFailed,
#             method='create',
#             resource=resource,
#             params=params)
# 
#         return DownloadTask(
#             filename=filename, task=task)


from smc.base.model import SubElement
from smc.administration.tasks import Task
"""
Functionality related to updating dynamic update packages and
engine upgrades
"""


class PackageMixin(object):
    """
    Manages downloads and activations of update packages and software
    upgrades
    """

    def download(self, timeout=5, wait_for_finish=False):
        """
        Download Package or Engine Update

        :param int timeout: timeout between queries
        :raises TaskRunFailed: failure during task status
        :rtype: TaskOperationPoller
        """

# Path: smc/base/model.py
# class SubElement(ElementBase):
#     """
#     SubElement is the base class for elements that do not
#     have direct entry points in the SMC and instead are obtained
#     through a reference. They are not 'loaded' directly as are
#     classes that inherit from :class:`Element`.
#     """
# 
#     def __init__(self, **meta):
#         super(SubElement, self).__init__(**meta)
# 
#     @property
#     def name(self):
#         return self._meta.name if self._meta else None
# 
#     @property
#     def href(self):
#         return self._meta.href if self._meta else None
# 
# Path: smc/administration/tasks.py
# class Task(SubElement):
#     """
#     Task representation. This is generic and the format is used for
#     any calls to SMC that return an asynchronous follower link to
#     check the status of the task.
# 
#     :param str last_message: Last message received on this task
#     :param bool in_progress: Whether the task is in progress or finished
#     :param bool success: Whether the task succeeded or not
#     :param str follower: Fully qualified path to the follower link to track
#         this task.
#     """
#     def __init__(self, task):
#         super(Task, self).__init__(
#             href=task.get('follower', None),
#             name=task.get('type', None))
#         self.data = ElementCache(task)
# 
#     @property
#     def resource(self):
#         """
#         The resource/s associated with this task
# 
#         :rtype: list(Element)
#         """
#         return [Element.from_href(resource)
#                 for resource in self.data.get('resource', [])]
# 
#     @property
#     def progress(self):
#         """
#         Percentage of completion
# 
#         :rtype: int
#         """
#         return self.data.get('progress', 0)
# 
#     @property
#     def start_time(self):
#         """
#         Task start time in UTC datetime format
# 
#         :rtype: datetime
#         """
#         start_time = self.data.get('start_time')
#         if start_time:
#             return millis_to_utc(start_time)
# 
#     @property
#     def end_time(self):
#         """
#         Task end time in UTC datetime format
# 
#         :rtype: datetime
#         """
#         end_time = self.data.get('end_time')
#         if end_time:
#             return millis_to_utc(end_time)
# 
#     def abort(self):
#         """
#         Abort existing task.
# 
#         :raises ActionCommandFailed: aborting task failed with reason
#         :return: None
#         """
#         try:
#             self.make_request(
#                 method='delete',
#                 resource='abort')
#     
#         except ResourceNotFound:
#             pass
#         except ActionCommandFailed:
#             pass
# 
#     @property
#     def result_url(self):
#         """
#         Link to result (this task)
# 
#         :rtype: str
#         """
#         return self.get_relation('result')
# 
#     def update_status(self):
#         """
#         Gets the current status of this task and returns a
#         new task object.
# 
#         :raises TaskRunFailed: fail to update task status
#         """
#         task = self.make_request(
#             TaskRunFailed,
#             href=self.href)
# 
#         return Task(task)
#     
#     def __getattr__(self, key):
#         return self.data.get(key)
#     
#     @staticmethod
#     def execute(self, resource, **kw):
#         """
#         Execute the task and return a TaskOperationPoller.
#         
#         :rtype: TaskOperationPoller
#         """
#         params = kw.pop('params', {})
#         json = kw.pop('json', None)
#         task = self.make_request(
#             TaskRunFailed,
#             method='create',
#             params=params,
#             json=json,
#             resource=resource)
# 
#         timeout = kw.pop('timeout', 5)
#         wait_for_finish = kw.pop('wait_for_finish', True)
#         
#         return TaskOperationPoller(
#             task=task, timeout=timeout,
#             wait_for_finish=wait_for_finish,
#             **kw)
# 
#     @staticmethod
#     def download(self, resource, filename, **kw):
#         """
#         Start and return a Download Task
#         
#         :rtype: DownloadTask(TaskOperationPoller)
#         """
#         params = kw.pop('params', {})
#         task = self.make_request(
#             TaskRunFailed,
#             method='create',
#             resource=resource,
#             params=params)
# 
#         return DownloadTask(
#             filename=filename, task=task)


# Path: smc/administration/updates.py
from smc.base.model import SubElement
from smc.administration.tasks import Task

"""
Functionality related to updating dynamic update packages and
engine upgrades
"""


class PackageMixin(object):
    """
    Manages downloads and activations of update packages and software
    upgrades
    """

    def download(self, timeout=5, wait_for_finish=False):
        """
        Download Package or Engine Update

        :param int timeout: timeout between queries
        :raises TaskRunFailed: failure during task status
        :rtype: TaskOperationPoller
        """

        return Task.execute(self, 'download', timeout=timeout,