import yaml


def get_yaml_from_topology_string(topology):
    """Transform a topology string into a dictionary of the same format used in
    the infrared provision.yml file.

    :param topology: Topology string in the format node: amount
    :type topology: str

    :returns: yaml representation of a provision.yml file
    :rtype: str
    """
    provision = {'provision': {'topology': {}}}
    if not topology:
        return yaml.dump(provision)
    topology_dict = {}
    for component in topology.split(","):
        name, amount = component.split(":")
        topology_dict[name+".yml"] = int(amount)
    provision['provision']['topology']['nodes'] = topology_dict
    return yaml.dump(provision)