Ejemplo n.º 1
0
def _cluster_create(args: dict, project_id: str, creds: Credentials) -> None:
    """creates a gke cluster

  Args:
  args: commandline args
  project_id: project in which to create cluster
  creds: credentials to use
  """
    dry_run = args['dry_run']
    cluster_name = args['cluster_name'] or k.DEFAULT_CLUSTER_NAME
    zone = args['zone']
    dashboard_url = util.dashboard_cluster_url(cluster_name, zone, project_id)
    release_channel = args['release_channel']
    single_zone = args['single_zone']

    # --------------------------------------------------------------------------
    cluster_client = googleapiclient.discovery.build('container',
                                                     k.CLUSTER_API_VERSION,
                                                     credentials=creds,
                                                     cache_discovery=False)

    if cluster_client is None:
        logging.error('error building cluster client')
        return

    request = Cluster.create_request(cluster_client, creds, cluster_name,
                                     project_id, zone, release_channel,
                                     single_zone)

    if request is None:
        logging.error('error creating cluster creation request')
        return

    if dry_run:
        logging.info('request:\n{}'.format(pp.pformat(json.loads(
            request.body))))
        return

    # --------------------------------------------------------------------------
    # see if cluster(s) already exist, and if so, check with the user before
    # creating another
    if not _check_for_existing_cluster(cluster_name, project_id, creds):
        return

    logging.info('creating cluster {} in project {} in {}...'.format(
        cluster_name, project_id, zone))
    logging.info('please be patient, this may take several minutes')
    logging.info(
        'visit {} to monitor cluster creation progress'.format(dashboard_url))

    # --------------------------------------------------------------------------
    # create the cluster
    cluster = Cluster.create(cluster_client, creds, request, project_id)

    return
Ejemplo n.º 2
0
def test_dashboard_cluster_url():
    cfg = {
        'cluster_id': 'foo',
        'zone': 'us-central1-a',
        'project_id': 'bar',
    }

    url = util.dashboard_cluster_url(**cfg)

    assert url is not None
    assert url == (
        f'{k.DASHBOARD_CLUSTER_URL}/{cfg["zone"]}/{cfg["cluster_id"]}'
        f'?project={cfg["project_id"]}')
Ejemplo n.º 3
0
 def dashboard_url(self) -> str:
   """returns gke dashboard url for this cluster"""
   return util.dashboard_cluster_url(self.name, self.zone, self.project_id)
Ejemplo n.º 4
0
 def dashboard_url(self) -> Optional[str]:
     """returns gke dashboard url for this cluster on success, None otherwise"""
     if self.name is None:
         return None
     return util.dashboard_cluster_url(self.name, self.zone,
                                       self.project_id)