示例#1
0
def checkPrices(ctype=None, cluster_tag=None, max_times=10):
    """
    Checks the spot prices
    no args compares currently running clusters to possible spot prices
    ctype checks for a certain type of image i.e. 'm1.xlarge' and returns 
    prices in order of cheapest to most expensive
    cluster_tag checks only for one running cluster
    """
    assert ctype is None or cluster_tag is None, ("you cannot specify a "
                                                  "cluster and an image type.")
    if ctype == None:
        cfg = StarClusterConfig().load()
        cm = ClusterManager(cfg)
        for cluster in cm.get_clusters():
            if cluster_tag is not None and cluster.cluster_tag != cluster_tag:
                continue
            region, template = readLog(tag=cluster.cluster_tag)
            t = "%s - of type(%s) in zone(%s) with bid(%s)" % (
                cluster.cluster_tag, cluster.master_instance_type,
                cluster._nodes[0].placement, cluster.spot_bid)
            print "=" * len(t)
            print t
            sp = getSpotPrices(cluster.master_instance_type,
                               max_times=max_times)
            print sp[cluster._nodes[0].placement]['print']
            print "=" * len(t)
            print
            print
            print "Better/equal prices @"
            curr = sp[cluster._nodes[0].placement]['current']
            for k, v in sp.iteritems():
                if curr >= v['current'] and k != cluster._nodes[0].placement:
                    print v['print']
    else:
        sp = getSpotPrices(ctype, max_times=max_times)
        a = [(p['current'], k) for k, p in sp.iteritems()]
        a.sort()
        print "type(%s)  from cheapest to most expensive" % ctype
        for _, k in a:
            print sp[k]['print']
示例#2
0
def checkPrices(ctype=None, cluster_tag=None, max_times=10):
    """
    Checks the spot prices
    no args compares currently running clusters to possible spot prices
    ctype checks for a certain type of image i.e. 'm1.xlarge' and returns 
    prices in order of cheapest to most expensive
    cluster_tag checks only for one running cluster
    """
    assert ctype is None or cluster_tag is None, ("you cannot specify a "
                                    "cluster and an image type.")
    if ctype==None:
        cfg = StarClusterConfig().load()
        cm = ClusterManager(cfg)
        for cluster in cm.get_clusters():
            if cluster_tag is not None and  cluster.cluster_tag != cluster_tag:
                continue
            region, template = readLog(tag = cluster.cluster_tag)
            t = "%s - of type(%s) in zone(%s) with bid(%s)"% (
                    cluster.cluster_tag,  cluster.master_instance_type,
                    cluster._nodes[0].placement,cluster.spot_bid)
            print "="*len(t)
            print t
            sp = getSpotPrices( cluster.master_instance_type, 
                                    max_times=max_times )
            print sp[cluster._nodes[0].placement]['print']
            print "="*len(t)
            print 
            print
            print "Better/equal prices @"
            curr = sp[cluster._nodes[0].placement]['current']
            for k,v in sp.iteritems():
                if curr >= v['current'] and k != cluster._nodes[0].placement:
                    print v['print']
    else:
        sp = getSpotPrices( ctype, max_times=max_times )
        a = [(p['current'],k) for k,p in sp.iteritems()]
        a.sort()
        print "type(%s)  from cheapest to most expensive"%ctype
        for _,k in a:
            print sp[k]['print']
示例#3
0
def cloneCluster(new_zone, cluster_tag=None, template=None):
    assert cluster_tag is not None or template is not None, "You must provide a cluster template or a cluster tag"
    #get full config
    cfg = StarClusterConfig().load()
    cm = ClusterManager(cfg)
    dest_region = new_zone[:-1]
    if cluster_tag is not None: 
        for cluster in cm.get_clusters():
            if cluster.cluster_tag == cluster_tag:
                region, template = readLog(tag = cluster.cluster_tag)
                break

    cluster_sect, volume_sect = getClusterConfig(template, cfg)
    #get autogenerated portion of config
    auto_config = ConfigParser.RawConfigParser()
    auto_config.read(os.path.expanduser('~/.starcluster/cfgs/auto-gen.cfg'))
    new_cluster_sect = []
    new_volume_sect = []
    for key,value in cluster_sect:
        if key == 'node_image_id' or key=='master_image_id':
            source_region = regionFromAMI(value )
            if source_region is None:
                raise Exception("Cannot find %s  in any region." % value)
            new_ami = cpAMI( dest_region=dest_region, source_region=source_region, source_image_id=value)
           
            print "NA: ", new_ami 
            new_cluster_sect.append((key,new_ami))
        elif key == 'extends':
            if value[:4] != 'base':
                print "*"*50
                print "ALERT,%s extends non base cluster, CHECK CONFIG"%template
                print "*"*50

            new_cluster_sect.append((key,'base-%s'%dest_region))
        elif key == 'volumes':
            value = removeRegion(value)
            volume_sec_name = 'volume %s-%s' % (value, new_zone)
            counter = 0
            while auto_config.has_section(volume_sec_name):
                volume_sec_name = 'volume %s-%s-%02d' % (value, new_zone,counter)
                counter += 1

            for k,v in volume_sect:
                if k == 'volume_id':
                    region_from, zone_from = regionFromVolume( v )
                    if region_from is None:
                        raise Exception("Cannot find %s  in any region." % v)
                    new_vol_id = cpVolume(v, new_zone[:-1], new_zone, region_from=region_from)
                    new_volume_sect.append((k, new_vol_id))
                else:
                    new_volume_sect.append((k,v))
            new_cluster_sect.append((key, volume_sec_name.split(' ')[1]))
        else:
            new_cluster_sect.append((key,value))
            
    cluster_sec_name = 'cluster %s-%s' % (template, new_zone)
    counter = 0
    while auto_config.has_section(cluster_sec_name):
        cluster_sec_name = 'cluster %s-%s-%02d' % (template, new_zone, counter)
        counter += 1

    auto_config.add_section(cluster_sec_name)
    auto_config.add_section(volume_sec_name)
    for k,v in  new_cluster_sect:
        auto_config.set(cluster_sec_name, k,v)

    for k,v in  new_volume_sect:
        auto_config.set(volume_sec_name, k,v)

    with open(os.path.expanduser('~/.starcluster/cfgs/auto-gen.cfg'), 'wb') as configfile:
        auto_config.write(configfile)

    print "starcluster -r %s start --force-spot-master -b <my-bid> -c %s my-cluster"%(new_zone[:-1], cluster_sec_name.split(' ')[1])