예제 #1
0
 def test(self):
     with self.root.ui.throbber(_("Check compute credentials/connectivity")):
         try:
             self.driver.list_nodes()
         except InvalidCredsError:
             raise error.InvalidCredError(
                 "Unable to login to compute service", anchor=self.params.driver.id.anchor)
예제 #2
0
파일: part.py 프로젝트: yaybu/yaybu
 def destroy(self):
     """ Try to connect the layer successfully, then destroy the underlying node. """
     self.load()
     if not self.layer.attached:
         return
     with self.root.ui.throbber(_("Destroy node %r") % self.full_name):
         self.layer.destroy()
예제 #3
0
    def destroy(self):
        if not self.libcloud_node:
            self.state.refresh()
            if "their_name" in self.state:
                self.libcloud_node = self._find_node(self.state.their_name)
            if not self.libcloud_node:
                self.libcloud_node = self._find_node(self.full_name)
            if not self.libcloud_node:
                return

        with self.root.ui.throbber(_("Destroy node '%r'") % self.full_name):
            self.libcloud_node.destroy()
예제 #4
0
파일: part.py 프로젝트: yaybu/yaybu
    def create(self):
        with self.root.ui.throbber(_("Create node '%r'") % (self.full_name, )):
            self.layer.create()
            logger.debug("Waiting for node %r to start" % (self.full_name, ))
            try:
                with self.root.ui.throbber(_("Wait for node '%r' to start") % self.full_name):
                    self.layer.wait()
                logger.debug("Node %r running" % (self.full_name, ))
                self.synchronise()
                self.root.changed()
                return True

            except NodeFailedToStartException:
                logger.warning("Node %r did not start before timeout. retrying." % self.full_name)
                self.destroy()
                return False

            except Exception:
                logger.exception(
                    "Node %r had an unexpected error - node will be cleaned up and processing will stop" % (self.full_name,))
                self.node.destroy()
                raise
예제 #5
0
 def _find_node(self, name):
     try:
         existing = [
             n for n in self.driver.list_nodes() if n.name == name and n.state != NodeState.TERMINATED]
     except InvalidCredsError:
         raise error.InvalidCredsError(
             "Credentials invalid - unable to check/create '%s'" % self.params.name.as_string(), anchor=None)
     if len(existing) > 1:
         raise LibcloudError(
             _("There are already multiple nodes called '%s'") % name)
     elif not existing:
         return None
     node = existing[0]
     if node.state != NodeState.RUNNING:
         ex_start = getattr(node.driver, "ex_start", None)
         if ex_start is not None:
             logger.debug("Starting node")
             ex_start(node)
         else:
             raise LibcloudError(
                 _("The node is not running and cannot be started"))
     logger.debug(
         "Node '%s' already running - not creating new node" % (name, ))
     return node
예제 #6
0
    def apply(self):
        if self.libcloud_node:
            return

        self.state.refresh()

        if "their_name" in self.state:
            self.libcloud_node = self._find_node(self.state.their_name)

        if not self.libcloud_node:
            self.libcloud_node = self._find_node(self.full_name)

        if self.libcloud_node:
            logger.debug("Applying to node %r at %r/%r" %
                         (self.libcloud_node.name, self.libcloud_node.public_ip, self.libcloud_node.private_ip))
            self._update_node_info()
            return

        if self.root.readonly:
            self._fake_node_info()
            return

        logger.debug("Node will be %r" % self.full_name)

        for tries in range(10):
            logger.debug("Creating %r, attempt %d" % (self.full_name, tries))

            with self.root.ui.throbber(_("Create node '%r'") % (self.full_name, )):
                kwargs = args_from_expression(self.driver.create_node, self.params, ignore=(
                    "name", "image", "size"), kwargs=getattr(self.driver, "create_node_kwargs", []))

                if not 'ex_keyname' in kwargs:
                    kwargs['auth'] = self._get_auth()

                if 'ex_iamprofile' in kwargs:
                    kwargs['ex_iamprofile'] = kwargs['ex_iamprofile'].encode("utf-8")

                if self.root.simulate:
                    self._fake_node_info()
                    self.root.changed()
                    return

                node = self.driver.create_node(
                    name=self.full_name,
                    image=self._get_image(),
                    size=self._get_size(),
                    **kwargs
                )

            logger.debug("Waiting for node %r to start" % (self.full_name, ))

            try:
                with self.root.ui.throbber(_("Wait for node '%r' to start") % self.full_name):
                    self.libcloud_node, self.ip_addresses = self.driver.wait_until_running(
                        [node], wait_period=1, timeout=600)[0]

                logger.debug("Node %r running" % (self.full_name, ))
                # self.their_name = self.libcloud_node.name
                self._update_node_info()
                self.root.changed()
                return

            except LibcloudError as e:
                logger.warning(
                    "Node %r did not start before timeout. retrying." % self.full_name)
                node.destroy()
                continue

            except Exception as e:
                logger.warning(
                    "Node %r had an unexpected error %s - node will be cleaned up and processing will stop" % (self.full_name, e))
                node.destroy()
                raise
                return

        logger.error("Unable to create node successfully. giving up.")
        raise IOError()
예제 #7
0
파일: part.py 프로젝트: yaybu/yaybu
 def test(self):
     """ Check that we're able to connect to the underlying
     implementation. Will raise an exception if there is a failure. """
     with self.root.ui.throbber(_("Check compute credentials/connectivity")):
         self.layer.test()