Figure out the best diffs to use to reach all our required volumes.
518553
def analyze(self, chunkSize, *sinks):
        
        measureSize = False
        if self.measureSize:
            for sink in sinks:
                if sink.isRemote:
                    measureSize = True

        # Use destination (already uploaded) edges first
        sinks = list(sinks)
        sinks.reverse()
        self.dest = sinks[0]

        def currentSize():
            return sum([
                n.diffSize
                for n in self.nodes.values()
                if n.diff is not None and n.diff.sink != self.dest
            ])

        while True:
            self._analyzeDontMeasure(chunkSize, measureSize, *sinks)

            if not measureSize:
                return

            estimatedSize = currentSize()

            # logger.info("Measuring any estimated diffs")

            for node in self.nodes.values():
                edge = node.diff
                if edge is not None and edge.sink != self.dest and edge.sizeIsEstimated:
                    edge.sink.measureSize(edge, chunkSize)

            actualSize = currentSize()

            logger.info(
                "measured size (%s), estimated size (%s)",
                humanize(actualSize), humanize(estimatedSize),
            )

            if actualSize <= 1.2 * estimatedSize:
                return
941953
def volume_attach(provider, names, **kwargs):
    '''
    

    '''
    client = _get_client()
    info = client.extra_action(provider=provider, names=names, action='volume_attach', **kwargs)
    return info
1236915
def money_flow(close_data, high_data, low_data, volume):
    
    catch_errors.check_for_input_len_diff(
        close_data, high_data, low_data, volume
        )
    mf = volume * tp(close_data, high_data, low_data)
    return mf
912996
def get(self, volume_ids=None, filters=None):
        """"""
        params = {}
        if filters:
            params["filters"] = make_filters(filters)
        if isinstance(volume_ids, str):
            volume_ids = [volume_ids]
        return self.call("DescribeVolumes",
                         VolumeIds=volume_ids,
                         response_data_key="Volumes",
                         **params)
502157
function diffContentItems(lhs, rhs) {
  var d = diff(lhs, rhs, function(key, value) {
    return value === 'visitors' || value === 'headers';
  });
  return d;
}
20642
def control_volumes(self):
        
        if self._control_volumes is None:
            #   1/3. * (0.5 * edge_length) * covolume
            # = 1/6 * edge_length**2 * ce_ratio_edge_ratio
            v = self.ei_dot_ei * self.ce_ratios / 6.0
            # Explicitly sum up contributions per cell first. Makes
            # numpy.add.at faster.
            # For every node k (range(4)), check for which edges k appears in
            # local_idx, and sum() up the v's from there.
            idx = self.local_idx
            vals = numpy.array(
                [
                    sum([v[i, j] for i, j in zip(*numpy.where(idx == k)[1:])])
                    for k in range(4)
                ]
            ).T
            #
            self._control_volumes = numpy.zeros(len(self.node_coords))
            numpy.add.at(self._control_volumes, self.cells["nodes"], vals)
        return self._control_volumes
49015
def _volume(shape):
    """"""
    prod = 1
    for start, stop in shape:
        prod *= stop - start
    return prod
903299
def on_balance_volume(close_data, volume):
    
    catch_errors.check_for_input_len_diff(close_data, volume)
    obv = np.zeros(len(volume))
    obv[0] = 1
    for idx in range(1, len(obv)):
        if close_data[idx] > close_data[idx-1]:
            obv[idx] = obv[idx-1] + volume[idx]
        elif close_data[idx] < close_data[idx-1]:
            obv[idx] = obv[idx-1] - volume[idx]
        elif close_data[idx] == close_data[idx-1]:
            obv[idx] = obv[idx-1]
    return obv
1277222
def _get_all_volumes_paths(conn):
    '''
    
    '''
    volumes = [vol for l in [obj.listAllVolumes() for obj in conn.listAllStoragePools()] for vol in l]
    return {vol.path(): [path.text for path in ElementTree.fromstring(vol.XMLDesc()).findall('.//backingStore/path')]
            for vol in volumes if _is_valid_volume(vol)}
425531
def import_volumes(source, ignore_conflicts, yes):
    '''
    '''
    volumes = json.load(source)
    tot = len(volumes)
    if not yes:
        click.confirm("Are you sure you want to import {} volumes into index '{}'".format(tot, arc._config['ES_INDEXNAME']))
    conflicts=0
    with click.progressbar(volumes, label='adding volumes') as bar:
        for v in bar:
            try:
                arc.import_volume(v)
            except ConflictException as ce:
                if not ignore_conflicts:
                    die(str(ce))
                conflicts += 1
            except Exception as e:
                if conf.get('DEBUG', False):
                    raise
                else:
                    die(str(e))

    if conflicts > 0:
        click.echo("{} volumes has been skipped beacause of a conflict".format(conflicts))
1075379
def diff(ctx, files, metrics, all, detail):
    """"""
    config = ctx.obj["CONFIG"]

    if not exists(config):
        handle_no_cache(ctx)

    if not metrics:
        metrics = get_default_metrics(config)
        logger.info(f"Using default metrics {metrics}")
    else:
        metrics = metrics.split(",")
        logger.info(f"Using specified metrics {metrics}")

    from wily.commands.diff import diff

    logger.debug(f"Running diff on {files} for metric {metrics}")
    diff(
        config=config, files=files, metrics=metrics, changes_only=not all, detail=detail
    )
422394
def diff(self, *args):
        """"""
        arg_dicts = self._parse_args_forward_mode(*args)
        val, diff = self._forward_mode(*arg_dicts)
        return diff
922379
def cli(env, sortby, columns, datacenter, username, storage_type):
    """"""
    block_manager = SoftLayer.BlockStorageManager(env.client)
    block_volumes = block_manager.list_block_volumes(datacenter=datacenter,
                                                     username=username,
                                                     storage_type=storage_type,
                                                     mask=columns.mask())

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for block_volume in block_volumes:
        table.add_row([value or formatting.blank()
                       for value in columns.row(block_volume)])

    env.fout(table)
900685
def cli(env, volume_id):
    """"""
    file_manager = SoftLayer.FileStorageManager(env.client)
    file_volume = file_manager.get_file_volume_details(volume_id)
    file_volume = utils.NestedDict(file_volume)

    table = formatting.KeyValueTable(['Name', 'Value'])
    table.align['Name'] = 'r'
    table.align['Value'] = 'l'

    storage_type = file_volume['storageType']['keyName'].split('_').pop(0)
    table.add_row(['ID', file_volume['id']])
    table.add_row(['Username', file_volume['username']])
    table.add_row(['Type', storage_type])
    table.add_row(['Capacity (GB)', "%iGB" % file_volume['capacityGb']])

    used_space = int(file_volume['bytesUsed'])\
        if file_volume['bytesUsed'] else 0
    if used_space < (1 << 10):
        table.add_row(['Used Space', "%dB" % used_space])
    elif used_space < (1 << 20):
        table.add_row(['Used Space', "%dKB" % (used_space / (1 << 10))])
    elif used_space < (1 << 30):
        table.add_row(['Used Space', "%dMB" % (used_space / (1 << 20))])
    else:
        table.add_row(['Used Space', "%dGB" % (used_space / (1 << 30))])

    if file_volume.get('provisionedIops'):
        table.add_row(['IOPs', float(file_volume['provisionedIops'])])

    if file_volume.get('storageTierLevel'):
        table.add_row([
            'Endurance Tier',
            file_volume['storageTierLevel'],
        ])

    table.add_row([
        'Data Center',
        file_volume['serviceResource']['datacenter']['name'],
    ])
    table.add_row([
        'Target IP',
        file_volume['serviceResourceBackendIpAddress'],
    ])

    if file_volume['fileNetworkMountAddress']:
        table.add_row([
            'Mount Address',
            file_volume['fileNetworkMountAddress'],
        ])

    if file_volume['snapshotCapacityGb']:
        table.add_row([
            'Snapshot Capacity (GB)',
            file_volume['snapshotCapacityGb'],
        ])
        if 'snapshotSizeBytes' in file_volume['parentVolume']:
            table.add_row([
                'Snapshot Used (Bytes)',
                file_volume['parentVolume']['snapshotSizeBytes'],
            ])

    table.add_row(['# of Active Transactions', "%i"
                   % file_volume['activeTransactionCount']])

    if file_volume['activeTransactions']:
        for trans in file_volume['activeTransactions']:
            if 'transactionStatus' in trans and 'friendlyName' in trans['transactionStatus']:
                table.add_row(['Ongoing Transaction', trans['transactionStatus']['friendlyName']])

    table.add_row(['Replicant Count', "%u" % file_volume.get('replicationPartnerCount', 0)])

    if file_volume['replicationPartnerCount'] > 0:
        # This if/else temporarily handles a bug in which the SL API
        # returns a string or object for 'replicationStatus'; it seems that
        # the type is string for File volumes and object for Block volumes
        if 'message' in file_volume['replicationStatus']:
            table.add_row(['Replication Status', "%s"
                           % file_volume['replicationStatus']['message']])
        else:
            table.add_row(['Replication Status', "%s"
                           % file_volume['replicationStatus']])

        replicant_list = []
        for replicant in file_volume['replicationPartners']:
            replicant_table = formatting.Table(['Replicant ID',
                                                replicant['id']])
            replicant_table.add_row([
                'Volume Name',
                utils.lookup(replicant, 'username')])
            replicant_table.add_row([
                'Target IP',
                utils.lookup(replicant, 'serviceResourceBackendIpAddress')])
            replicant_table.add_row([
                'Data Center',
                utils.lookup(replicant,
                             'serviceResource', 'datacenter', 'name')])
            replicant_table.add_row([
                'Schedule',
                utils.lookup(replicant,
                             'replicationSchedule', 'type', 'keyname')])
            replicant_list.append(replicant_table)
        table.add_row(['Replicant Volumes', replicant_list])

    if file_volume.get('originalVolumeSize'):
        original_volume_info = formatting.Table(['Property', 'Value'])
        original_volume_info.add_row(['Original Volume Size', file_volume['originalVolumeSize']])
        if file_volume.get('originalVolumeName'):
            original_volume_info.add_row(['Original Volume Name', file_volume['originalVolumeName']])
        if file_volume.get('originalSnapshotName'):
            original_volume_info.add_row(['Original Snapshot Name', file_volume['originalSnapshotName']])
        table.add_row(['Original Volume Properties', original_volume_info])

    env.fout(table)
963957
def volume_info(self, vol=None, type_filter=None):
		''
		vols = yield self(join('volumes', vol))
		if not isinstance(vols, list): vols = [vols]
		if type_filter is not None:
			vols = list(vol for vol in vols if vol['type'] == type_filter)
		if vol is not None: defer.returnValue(vols[0] if vols else None)
		defer.returnValue(vols)
890950
def _full_diff(merge_result, key, context_lines=3):
    """"""
    header_printed = False
    for group in _split_diff(merge_result, context_lines=context_lines):
        if not header_printed:
            header_printed = True
            yield color.Header('diff a/%s b/%s' % (key, key))
            yield color.DeletedHeader('--- %s' % key)
            yield color.AddedHeader('+++ %s' % key)

        for l in _diff_group(group):
            yield l
596995
def best(self):
        """"""
        return pd.Series(
            {
                "name": self.best_dist.name,
                "params": self.best_param,
                "sse": self.best_sse,
            }
        )