コード例 #1
0
ファイル: datacenters.py プロジェクト: vinnishtein/conductor
def create():
    from app.models import Datacenter
    dc_attrs = dict(
        [x for x in request.json.items() if x[0] in Datacenter.FIELDS])
    dc = Datacenter(**dc_attrs)
    # TODO: check permissions!
    try:
        dc.save()
    except Exception as e:
        return json_exception(e, 500)
    if "parent_id" in dc_attrs and dc_attrs["parent_id"]:
        return set_parent(dc._id)
    return json_response({"data": dc.to_dict()}, 201)
コード例 #2
0
from app.models import Datacenter

Datacenter.destroy_all()
dc1 = Datacenter(name="dc1")
dc11 = Datacenter(name="dc1.1")
dc1.save()
dc11.save()
dc1.add_child(dc11)

dc12 = Datacenter(name="dc1.2")
dc121 = Datacenter(name="dc1.2.1")
dc122 = Datacenter(name="dc1.2.2")

dc1.add_child(dc12)

dc12.save()
dc121.save()
dc122.save()

dc121.set_parent(dc12)
dc122.set_parent(dc12)
コード例 #3
0
        child_ids.append(group_cache[child]._id)
    if len(child_ids) > 0:
        g = group_cache[group_name]
        for cid in child_ids:
            g.add_child(cid)
    i += 1
    if i % 100 == 0:
        print i
print i

print "Processing datacenters"
Datacenter.destroy_all()
datacenter_cache = {}
for datacenter_name, datacenter_desc in data["Datacenters"].items():
    dc = Datacenter(name=datacenter_name, human_readable=datacenter_desc["golem_name"])
    dc.save()
    datacenter_cache[datacenter_name] = dc

print "Setting parents"
for datacenter_name, datacenter_desc in data["Datacenters"].items():
    if datacenter_desc["parent"] is not None:
        dc = datacenter_cache[datacenter_name]
        parent = datacenter_cache[datacenter_desc["parent"]]
        dc.set_parent(parent)

print "Processing hosts"
Host.destroy_all()
i = 0
for fqdn, host_desc in data["Hosts"].items():
    if host_desc["datacenter"] is not None:
        dc_id = datacenter_cache[host_desc["datacenter"]]._id