def delete_deployment(dm, project, name):
    deployments_client = dm.deployments()
    try:
        op = deployments_client.delete(project=project,
                                       deployment=name).execute()
    except errors.HttpError as e:
        if not e.content:
            raise
        error_content = json.loads(e.content)
        message = error_content.get('error', {}).get('message', "")
        logging.info("delete deployment error %s", message)
        code = error_content.get('error', {}).get('code', 0)
        if code == 404:  # pylint: disable=no-else-return
            logging.info("Project %s doesn't have deployment %s", project,
                         name)
            return
        elif code == 409:
            logging.info("Conflicting operation in progress")
            raise ValueError(
                "Can't delete deployment confliction operation in "
                "progress")
        raise
    zone = None
    op = util.wait_for_gcp_operation(dm.operations(), project, zone,
                                     op["name"])
    logging.info("Final op: %s", op)
Esempio n. 2
0
def delete_storage_deployment(project, name):
  credentials = GoogleCredentials.get_application_default()
  dm = discovery.build("deploymentmanager", "v2", credentials=credentials)

  deployments_client = dm.deployments()

  try:
    op = deployments_client.delete(project=project, deployment=name,
                                   deletePolicy="DELETE").execute()
  except Exception as e:
    if hasattr(e, 'content'):
      m = json.loads(e.content)
      if m.get("error", {}).get("code") == 404:
        return
      raise
    raise

  util.wait_for_gcp_operation(dm.operations(), project, None, op["name"])