コード例 #1
0
ファイル: ds2_configure.py プロジェクト: tracelytics/ComboAMI
def getAddresses():
    conf.setConfig("AMI", "CurrentStatus", "Installation started")
    # Find internal IP address for seed list
    global internalip
    req = urllib2.Request('http://instance-data/latest/meta-data/local-ipv4')
    internalip = urllib2.urlopen(req).read()
    
    # Find public hostname for JMX
    req = urllib2.Request('http://instance-data/latest/meta-data/public-hostname')
    global publichostname
    publichostname = urllib2.urlopen(req).read()
    
    # Find launch index for token splitting
    req = urllib2.Request('http://instance-data/latest/meta-data/ami-launch-index')
    global launchindex
    launchindex = int(urllib2.urlopen(req).read())
    
    # Find reservation-id for cluster-id and jmxpass
    req = urllib2.Request('http://instance-data/latest/meta-data/reservation-id')
    global reservationid, jmxPass, clustername
    reservationid = urllib2.urlopen(req).read()
    jmxPass = reservationid
    clustername = reservationid

    # Try to get EC2 User Data
    userDataExists = False
    try:
        req = urllib2.Request('http://instance-data/latest/user-data/')
        global userdata
        userdata = urllib2.urlopen(req).read()
        userDataExists = True
        
    except Exception, e:
        userdata = ""
        exitPath("No User Data was set.")
コード例 #2
0
ファイル: ds2_configure.py プロジェクト: tracelytics/ComboAMI
def exitPath(errorMsg, appendMsg=False):
    if not appendMsg:
        global userdata
        # Remove passwords from printing
        p = re.search('(-p\s+)(\S*)', userdata)
        if p:
            userdata = userdata.replace(p.group(2), '****')
        p = re.search('(--password\s+)(\S*)', userdata)
        if p:
            userdata = userdata.replace(p.group(2), '****')

        appendMsg = " Aborting installation.\n\nPlease verify your settings:\n" + userdata

    errorMsg += appendMsg
    
    logger.error(errorMsg)
    conf.setConfig("AMI", "Error", errorMsg)
    sys.exit(1)
コード例 #3
0
ファイル: ds3_after_init.py プロジェクト: alanristic/ComboAMI
def checkAndLaunchOpsCenter():
    global launchindex
    if int(launchindex) == 0 and conf.getConfig("OpsCenter", "DNS") and not conf.getConfig("AMI", "CompletedFirstBoot") and not conf.getConfig("OpsCenter", "NoOpsCenter"):
        logger.exe('sudo service opscenterd restart')
        conf.setConfig("AMI", "CompletedFirstBoot", True)
コード例 #4
0
def mountRAID():
    # Only create raid0 once. Mount all times in init.d script.
    if not conf.getConfig("AMI", "RAIDCreated"):

        # Remove EC2 default /mnt from fstab
        fstab = ''
        fileToOpen = '/etc/fstab'
        logger.exe('sudo chmod 777 ' + fileToOpen)
        with open(fileToOpen, 'r') as f:
            for line in f:
                if not "/mnt" in line:
                    fstab += line
        with open(fileToOpen, 'w') as f:
            f.write(fstab)
        logger.exe('sudo chmod 644 ' + fileToOpen)
        
        # Create a list of devices
        devices = glob.glob("/dev/sd*")
        devices.remove('/dev/sda1')
        devices.sort()
        logger.info('Unformatted devices: ' + str(devices))
        
        # Check if there are enough drives to start a RAID set
        if len(devices) > 1:
            # Make sure the devices are umounted, then run fdisk on each device
            logger.info('Clear "invalid flag 0x0000 of partition table 4" by issuing a write, then running fdisk on each device...')
            formatCommands = """echo 'n
    p
    1


    t
    fd
    w'"""
            for device in devices:
                logger.info('Confirming devices are not mounted:')
                logger.exe('sudo umount ' + device, False)
                logger.pipe("echo 'w'", 'sudo fdisk -c -u ' + device)
                logger.pipe(formatCommands, 'sudo fdisk -c -u ' + device)
        
            # Create a list of partitions to RAID
            logger.exe('sudo fdisk -l')
            partitions = glob.glob("/dev/sd*[0-9]")
            partitions.remove('/dev/sda1')
            partitions.sort()
            logger.info('Partitions about to be added to RAID0 set: ' + str(partitions))
        
            # Make sure the partitions are umounted and create a list string
            partionList = ''
            for partition in partitions:
                logger.info('Confirming partitions are not mounted:')
                logger.exe('sudo umount ' + partition, False)
                partionList += partition + ' '
            partionList = partionList.strip()
        
            logger.info('Creating the RAID0 set:')
            time.sleep(5)
            logger.pipe('yes', 'sudo mdadm --create /dev/md0 --chunk=256 --level=0 --raid-devices=' + str(len(devices)) + ' ' + partionList, False)
            logger.pipe('echo DEVICE ' + partionList, 'sudo tee /etc/mdadm/mdadm.conf')
            logger.pipe('mdadm --detail --scan', 'sudo tee -a /etc/mdadm/mdadm.conf')
            time.sleep(5)
            logger.exe('blockdev --setra 65536 /dev/md0')

            logger.info('Formatting the RAID0 set:')
            time.sleep(5)
            logger.exe('sudo mkfs.xfs -f /dev/md0')
            
            # Configure fstab and mount the new RAID0 device
            raidMnt = '/raid0'
            logger.pipe("echo '/dev/md0\t" + raidMnt + "\txfs\tdefaults,nobootwait,noatime\t0\t0'", 'sudo tee -a /etc/fstab')
            logger.exe('sudo mkdir ' + raidMnt)
            logger.exe('sudo mount -a')
            logger.exe('sudo mkdir -p ' + raidMnt + '/cassandra/')
            logger.exe('sudo chown -R ubuntu:ubuntu ' + raidMnt + '/cassandra')
        
            logger.info('Showing RAID0 details:')
            logger.exe('cat /proc/mdstat')
            logger.exe('echo "15000" > /proc/sys/dev/raid/speed_limit_min')
            logger.exe('sudo mdadm --detail /dev/md0')

        else:
            # Make sure the device is umounted, then run fdisk on the device
            logger.info('Clear "invalid flag 0x0000 of partition table 4" by issuing a write, then running fdisk on the device...')
            formatCommands = """echo 'd
    n
    p
    1


    t
    83
    w'"""
            logger.exe('sudo umount ' + devices[0])
            logger.pipe("echo 'w'", 'sudo fdisk -c -u ' + devices[0])
            logger.pipe(formatCommands, 'sudo fdisk -c -u ' + devices[0])
            
            # Create a list of partitions to RAID
            logger.exe('sudo fdisk -l')
            partitions = glob.glob("/dev/sd*[0-9]")
            partitions.remove('/dev/sda1')
            partitions.sort()
            
            logger.info('Formatting the new partition:')
            logger.exe('sudo mkfs.xfs -f ' + partitions[0])
            
            # Configure fstab and mount the new formatted device
            mntPoint = '/mnt'
            logger.pipe("echo '" + partitions[0] + "\t" + mntPoint + "\txfs\tdefaults,nobootwait,noatime\t0\t0'", 'sudo tee -a /etc/fstab')
            logger.exe('sudo mkdir ' + mntPoint, False)
            logger.exe('sudo mount -a')
            logger.exe('sudo mkdir -p ' + mntPoint + '/cassandra')
            logger.exe('sudo chown -R cassandra:cassandra ' + mntPoint + '/cassandra')
        
        # Change cassandra.yaml to point to the new data directories
        with open(confPath + 'cassandra.yaml', 'r') as f:
            yaml = f.read()
        if len(partitions) > 1:
            yaml = yaml.replace('/var/lib/cassandra/data', raidMnt + '/cassandra/data')
            yaml = yaml.replace('/var/lib/cassandra/saved_caches', raidMnt + '/cassandra/saved_caches')
            yaml = yaml.replace('/var/lib/cassandra/commitlog', raidMnt + '/cassandra/commitlog')
        else:
            yaml = yaml.replace('/var/lib/cassandra/data', mntPoint + '/cassandra/data')
            yaml = yaml.replace('/var/lib/cassandra/saved_caches', mntPoint + '/cassandra/saved_caches')
            yaml = yaml.replace('/var/lib/cassandra/commitlog', mntPoint + '/cassandra/commitlog')
        with open(confPath + 'cassandra.yaml', 'w') as f:
            f.write(yaml)
        
        # Remove the old cassandra folders
        subprocess.Popen("sudo rm -rf /var/log/cassandra/*", shell=True)
        subprocess.Popen("sudo rm -rf /var/lib/cassandra/*", shell=True)
        logger.exe('sudo chown -R cassandra:cassandra /var/lib/cassandra')
        logger.exe('sudo chown -R cassandra:cassandra /var/log/cassandra')

        # Never create raid array again
        conf.setConfig("AMI", "RAIDCreated", True)

        logger.info("Mounted Raid.\n")
コード例 #5
0
        # # Option that specifies an alternative reflector.php
        # parser.add_option("-r", "--reflector", action="store", type="string", dest="reflector")
        # Developmental option that allows for a non-interactive instance on EBS instances
        parser.add_option("-m", "--manual", action="store_true", dest="manual")
        
        # Grab provided reflector through provided userdata
        global options
        try:
            (options, args) = parser.parse_args(userdata.strip().split(" "))
        except:
            logger.error('One of the options was not set correctly. Please verify your settings')
            print userdata
        if options and options.dev:
            global isDEV
            isDEV = True
            conf.setConfig("AMI", "IsDev", True)
        if isDEV:
            if options.smokeurl and options.smokefile:
                logger.info('Retrieving smoke testing tarball: ' + options.smokeurl)
                logger.info('Executing smoke testing file: ' + options.smokefile)
                conf.setConfig("AMI", "SmokeURL", options.smokeurl)
                conf.setConfig("AMI", "SmokeFile", options.smokefile)
            elif options.smokeurl or options.smokefile:
                logger.warn('Both -u and -f have to be set together in order for smoke tests to run.')

        conf.setConfig("AMI", "Type", "Cassandra")
        if options and options.deployment:
            options.deployment = options.deployment.lower()

            # Setup the repositories
            if options.deployment == "07x":
コード例 #6
0
ファイル: ds2_configure.py プロジェクト: tracelytics/ComboAMI
        # Option that allows for declaring this seed a vanilla node (in DSE)
        parser.add_option("-a", "--analyticsnode", action="store", type="string", dest="analyticsnode")

        # # Option that specifies an alternative reflector.php
        # parser.add_option("-r", "--reflector", action="store", type="string", dest="reflector")
        
        # Grab provided reflector through provided userdata
        global options
        try:
            (options, args) = parser.parse_args(userdata.strip().split(" "))
        except:
            exitPath("One of the options was not set correctly.")

        if options and options.version:
            if options.version.lower() == "community":
                conf.setConfig("AMI", "Type", "Community")
            if options.version.lower() == "enterprise":
                conf.setConfig("AMI", "Type", "Enterprise")
        else:
            exitPath("Missing required --version (-v) switch.")

        if not options or not options.clustersize:
            exitPath("Missing required --totalnodes (-n) switch.")

        if options.token or options.seeds:
            if not (options.token and options.seeds):
                exitPath("Both --token (-t) and --seeds (-s) must be set in order to attach nodes.")

        if conf.getConfig("AMI", "Type") == "Enterprise":
            if options and options.username and options.password:
                repo_url = "http://debian.datastax.com/enterprise"