code: def setup_cluster(
      conn, master_nodes, slave_nodes, opts, deploy_ssh_key
  ):
      master = get_dns_name(master_nodes[0], opts.private_ips)
      if deploy_ssh_key:
          print("Generating cluster's SSH key on master...")
          key_setup = """
            [ -f ~/.ssh/id_rsa ] ||
              (ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa &&
               cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys)
          """
          ssh(master, opts, key_setup)
          dot_ssh_tar = ssh_read(master, opts, ["tar", "c", ".ssh"])
          print("Transferring cluster's SSH key to slaves...")
          for slave in slave_nodes:
              slave_address = get_dns_name(slave, opts.private_ips)
              print(slave_address)
              ssh_write(slave_address, opts, ["tar", "x"], dot_ssh_tar)
  
      modules = [
          "spark",
          "ephemeral-hdfs",
          "persistent-hdfs",
          "mapreduce",
          "spark-standalone",
      ]
  
      if opts.hadoop_major_version == "1":
          modules = list(filter(lambda x: x != "mapreduce", modules))
  
      if opts.ganglia:
          modules.append("ganglia")
  
      # Clear SPARK_WORKER_INSTANCES if running on YARN
      if opts.hadoop_major_version == "yarn":
          opts.worker_instances = ""
  
      # NOTE: We should clone the repository before running deploy_files to
      # prevent ec2-variables.sh from being overwritten
      print(
          "Cloning spark-ec2 scripts from {r}/tree/{b} on master...".format(
              r=opts.spark_ec2_git_repo, b=opts.spark_ec2_git_branch
          )
      )
      ssh(
          host=master,
          opts=opts,
          command="rm -rf spark-ec2"
          + " && "
          + "git clone {r} -b {b} spark-ec2".format(
              r=opts.spark_ec2_git_repo, b=opts.spark_ec2_git_branch
          ),
      )
  
      print("Deploying files to master...")
      deploy_files(
          conn=conn,
          root_dir=SPARK_EC2_DIR + "/" + "deploy.generic",
          opts=opts,
          master_nodes=master_nodes,
          slave_nodes=slave_nodes,
          modules=modules,
      )
  
      if opts.deploy_root_dir is not None:
          print(
              "Deploying {s} to master...".format(
                  s=opts.deploy_root_dir
              )
          )
          deploy_user_files(
              root_dir=opts.deploy_root_dir,
              opts=opts,
              master_nodes=master_nodes,
          )
  
      print("Running setup on master...")
      setup_spark_cluster(master, opts)
  
      print("Done!")
  
imports: from __future__ import division, print_function, with_statement
  import codecs
  import hashlib
  import itertools
  import logging
  import os
  import os.path
  import pipes
  import random
  import shutil
  import string
  from stat import S_IRUSR
  import subprocess
  import sys
  import tarfile
  import tempfile
  import textwrap
  import time
  import warnings
  from datetime import datetime
  from optparse import OptionParser
  from sys import stderr
  import boto
  from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType, EBSBlockDeviceType
  from boto import ec2
label_desc: Use image node_id 10 for calling a global function with example usage: setup_cluster(conn, master_nodes, slave_nodes, opts, deploy_ssh_key) without return types