Beispiel #1
0
 def __poll_startup_script(self):
     # Return true if instance is currently available for running commands
     data = GoogleCloudHelper.describe(self.name, self.zone)
     # Check to see if "READY" has been added to instance metadata indicating startup-script has complete
     for item in data["metadata"]["items"]:
         if item["key"] == "READY":
             return True
     return False
Beispiel #2
0
    def update_status(self):

        # Initialize the number of retries
        retries = 0

        # Get status from the cloud
        while True:

            try:
                # Obtain the instance information
                data = GoogleCloudHelper.describe(self.name, self.zone)

                # Update the external IP address
                self.external_IP = data["networkInterfaces"][0][
                    "accessConfigs"][0].get("natIP", None)

                # Set the status accordingly
                if data["status"] in ["TERMINATED", "STOPPING"]:
                    self.set_status(Processor.DESTROYING)
                    break

                elif data["status"] in ["PROVISIONING", "STAGING"]:
                    self.set_status(Processor.CREATING)
                    break

                elif data["status"] == "RUNNING":
                    self.set_status(Processor.AVAILABLE if self.
                                    ssh_ready else Processor.CREATING)
                    break

                else:
                    raise RuntimeError(
                        "Unkown Google Compute Engine instance status: %s!" %
                        data["status"])

            # If no resource found, then the processor was manually deleted by someone
            except GoogleResourceNotFound:

                # Update the external IP address
                self.external_IP = None

                # Set the status to OFF
                self.set_status(Processor.OFF)
                break

            # For any other error, retry again
            except BaseException:

                # Raise an error when retried the default number of retries
                if retries >= self.default_num_cmd_retries:
                    raise

                # Sleep for 5 seconds and retry again
                else:
                    time.sleep(5)
                    retries += 1