Advertisement
Guest User

Untitled

a guest
Jan 15th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.96 KB | None | 0 0
  1. class ComputeTask(task.Task):
  2.     """This task creates a Compute instance
  3.  
  4.    so far it's not loading the driver properly
  5.    """
  6.  
  7.     def __init__(self, **kwargs):
  8.         super(ComputeTask, self).__init__(**kwargs)
  9.         self.compute = nova_driver.VirtualMachineManager()
  10.  
  11. class ComputeCreate(ComputeTask):
  12.     def revert(self, amphora, *args, **kwargs):
  13.         """This method will revert the creation
  14.  
  15.        of the
  16.        amphora. So it will just delete it in this
  17.        flow
  18.        """
  19.         LOG.info(i18n._LI("Reverting Nova for amphora with id %s "),
  20.                  amphora.id)
  21.         try:
  22.             self.compute.delete(amphora.compute_id)
  23.             amphora.compute_id = None
  24.         except Exception as e:
  25.             LOG.error(i18n._LI("Reverting Nova failed with exception %s"),
  26.                       e)
  27.         return
  28.  
  29.     def execute(self, amphora):
  30.         """Create an amphora
  31.  
  32.        :returns an amphora
  33.        """
  34.         LOG.debug("Nova Create execute for amphora with id %s" % amphora.id)
  35.  
  36.         # #Hack to create nova vm
  37.  
  38.  
  39.         try:
  40.             nics = []
  41.             for net_id in CONF.api_manager.amp_network_list:
  42.                 nics.append({"net-id": net_id})
  43.  
  44.  
  45.             compute_id = self.compute.build(name="octavia-test" + uuid.uuid1().hex,
  46.                                amphora_flavor=CONF.api_manager.amp_flavor_id,
  47.                                image_id=CONF.api_manager.amp_image_id,
  48.                                key_name=CONF.api_manager.amp_key_list,
  49.                                sec_groups=None,
  50.                                network_ids=nics)
  51.  
  52.  
  53.             LOG.debug("Server created")
  54.  
  55.             amphora.compute_id = compute_id
  56.  
  57.             return amphora
  58.  
  59.         except Exception as e:
  60.             LOG.error(i18n._LE("Nova create failed: "))
  61.             LOG.debug(e)
  62.             raise e
  63.  
  64. class ComputeWait(ComputeTask):
  65.  
  66.     def execute(self, amphora):
  67.             time.sleep(10)
  68.             if self.compute.status(amphora.compute_id) == constants.AMPHORA_UP:
  69.                 return
  70.  
  71.             raise Exception()
  72.  
  73. class Finalize_Amphora_Create(task.Task):
  74.     """This task will finalize the amphora
  75.  
  76.    with some driver call - this will
  77.    likely move into the driver
  78.    """
  79.  
  80.     def revert(self, history, *args, **kwargs):
  81.         # Todo(german) call driver revert code
  82.         return
  83.  
  84.     def execute(self, amphora):
  85.         LOG.debug("Finalize Amphora")
  86.         return None
  87.  
  88. class ComputeTask(task.Task):
  89.     """This task creates a Compute instance
  90.  
  91.    so far it's not loading the driver properly
  92.    """
  93.  
  94.     def __init__(self, **kwargs):
  95.         super(ComputeTask, self).__init__(**kwargs)
  96.         self.compute = nova_driver.VirtualMachineManager()
  97.  
  98. class ComputeCreate(ComputeTask):
  99.     def revert(self, amphora, *args, **kwargs):
  100.         """This method will revert the creation
  101.  
  102.        of the
  103.        amphora. So it will just delete it in this
  104.        flow
  105.        """
  106.         LOG.info(i18n._LI("Reverting Nova for amphora with id %s "),
  107.                  amphora.id)
  108.         try:
  109.             self.compute.delete(amphora.compute_id)
  110.             amphora.compute_id = None
  111.         except Exception as e:
  112.             LOG.error(i18n._LI("Reverting Nova failed with exception %s"),
  113.                       e)
  114.         return
  115.  
  116.     def execute(self, amphora):
  117.         """Create an amphora
  118.  
  119.        :returns an amphora
  120.        """
  121.         LOG.debug("Nova Create execute for amphora with id %s" % amphora.id)
  122.  
  123.         # #Hack to create nova vm
  124.  
  125.  
  126.         try:
  127.             nics = []
  128.             for net_id in CONF.api_manager.amp_network_list:
  129.                 nics.append({"net-id": net_id})
  130.  
  131.  
  132.             compute_id = self.compute.build(name="octavia-test" + uuid.uuid1().hex,
  133.                                amphora_flavor=CONF.api_manager.amp_flavor_id,
  134.                                image_id=CONF.api_manager.amp_image_id,
  135.                                key_name=CONF.api_manager.amp_key_list,
  136.                                sec_groups=None,
  137.                                network_ids=nics)
  138.  
  139.  
  140.             LOG.debug("Server created")
  141.  
  142.             amphora.compute_id = compute_id
  143.  
  144.             return amphora
  145.  
  146.         except Exception as e:
  147.             LOG.error(i18n._LE("Nova create failed: "))
  148.             LOG.debug(e)
  149.             raise e
  150.  
  151. class ComputeWait(ComputeTask):
  152.  
  153.     def execute(self, amphora):
  154.             time.sleep(10)
  155.             if self.compute.status(amphora.compute_id) == constants.AMPHORA_UP:
  156.                 return
  157.  
  158.             raise Exception()
  159.  
  160. class Finalize_Amphora_Create(task.Task):
  161.     """This task will finalize the amphora
  162.  
  163.    with some driver call - this will
  164.    likely move into the driver
  165.    """
  166.  
  167.     def revert(self, history, *args, **kwargs):
  168.         # Todo(german) call driver revert code
  169.         return
  170.  
  171.     def execute(self, amphora):
  172.         LOG.debug("Finalize Amphora")
  173.         return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement