Esempio n. 1
0
    def __init__(self):
        self.failed_pvc_q = Q.Queue()
        self.client = KubernetesApiClient()

        aws_metadata = AWSMetaData()
        self.my_instance_id = aws_metadata.get_instance_id()
        self.my_region = aws_metadata.get_region()
Esempio n. 2
0
    def __init__(self, aws_profile=None):
        self._aws_profile = aws_profile
        self._name = None
        self._namespace = None
        self._version = None
        self._config_file = None

        # This runs from creator only.
        if AXEnv().is_in_pod() or AXEnv().on_kube_host():
            return

        cookie = AWSMetaData().get_user_data(attr="ax-install-cookie")
        if cookie is None:
            # For testing only.
            cookie = os.getenv("AX_INSTALL_COOKIE", None)
            if cookie is None:
                return

        # Use different bucket for AX testing.
        if cookie.startswith("ax-internal-"):
            self._bucket = "ax-install-config-dev"
            cookie = cookie.replace("ax-internal-", "")
        else:
            self._bucket = "ax-install-config"
        self._path = cookie
        self._get_install_config()
Esempio n. 3
0
File: rest.py Progetto: nuaays/argo
def volume_create(volume_id):
    manager = VolumeManager()

    # Right now, only AWS volumes of type EBS are supported!
    volume_options = request.get_json()
    assert "storage_provider_name" in volume_options and volume_options["storage_provider_name"].lower() == "ebs", "Only EBS volumes supported currently!"

    if "zone" not in volume_options:
        volume_options["zone"] = AWSMetaData().get_zone()

    resource_id = manager.create_raw_volume(volume_id, volume_options)
    return jsonify(result=resource_id)
Esempio n. 4
0
def get_public_ip():
    """
    Get public IP
    Currently only applicable to EC2 instances.
    Get IP from meta data.
    :return:
    """
    if cloud_provider() == CLOUD_AWS:
        from ax.aws.meta_data import AWSMetaData
        try:
            return AWSMetaData().get_public_ip()
        except:
            pass

    return get_public_ip_through_external_server()
Esempio n. 5
0
 def is_volume_in_cloud_provider(volume):
     try:
         ec2 = boto3.resource('ec2',
                              region_name=AWSMetaData().get_region())
         vol = ec2.Volume(volume)
         state = vol.state
         logger.debug(
             "The current state of volume {} aws vol {} is {}".format(
                 self.name, volume, state))
         return True
     except botocore.exceptions.ClientError as e:
         code = e.response['ResponseMetadata']['HTTPStatusCode']
         # 400 and 404 are for invalid volume id and volume not found
         if code != 404 and code != 400:
             raise e
     return False
Esempio n. 6
0
 def meta_data(self):
     """
     Return a meta data object that can be used to get instance metadata.
     As we can ONLY access metadata within the cloud, metadata is always
     determined based on own cloud type
     """
     if not self._own_cloud:
         self._own_cloud = self._get_own_cloud_type()
     if self.in_cloud_gcp():
         from .gke.meta_data import GCEMetaData
         return GCEMetaData()
     elif self.in_cloud_aws():
         from ax.aws.meta_data import AWSMetaData
         return AWSMetaData()
     else:
         assert 0, "Cloud {} not supported".format(self._own_cloud)
Esempio n. 7
0
    def __init__(self, cluster_name_id, region=None, profile=None):
        self.cluster_name_id = cluster_name_id

        # Region and profile info can be passed in with upgrade code path,
        # when this is run from axclustermanager outside cluster.
        self.region = AWSMetaData().get_region() if region is None else region
        self.profile = profile
        if profile is None:
            session = boto3.Session(region_name=self.region)
        else:
            session = boto3.Session(region_name=self.region,
                                    profile_name=profile)

        self.ec2 = session.resource('ec2')
        self.client = session.client('ec2')
        self.cluster_info = AXClusterInfo(cluster_name_id=cluster_name_id,
                                          aws_profile=profile)
        self.cluster_config = AXClusterConfig(cluster_name_id=cluster_name_id,
                                              aws_profile=profile)
        cluster_config_path = AXClusterConfigPath(cluster_name_id)
        self.s3_bucket = cluster_config_path.bucket()
        self.s3_config_prefix = cluster_config_path.master_config_dir()
        self.s3_attributes_path = cluster_config_path.master_attributes_path()
        self.s3_user_data_path = cluster_config_path.master_user_data_path()

        logger.info(
            "Create MasterManager in region %s, attributes path: %s and user_data_path: %s",
            self.region, self.s3_attributes_path, self.s3_user_data_path)

        # The EC2 instance object for the current master
        self.master_instance = None

        # Properties/attributes to use when launching the new master
        self.attributes = {}

        # For upgrades.
        # The following values are set to None from master manager but to not None from upgrade code.
        self.aws_image = None
        self.instance_profile = None

        self.event_notification_client = EventNotificationClient(
            FACILITY_PLATFORM)
Esempio n. 8
0
 def get_region():
     return AWSMetaData().get_region() if AXEnv().is_in_pod(
     ) else "us-west-2"