Пример #1
0
def test_create_machines_for_test_interface():
    np = Building.get_unique(sess, 'np')
    assert isinstance(np, Building), 'no building in %s' % func_name()

    hp = Vendor.get_unique(sess, 'hp')
    assert isinstance(hp, Vendor), 'no vendor in %s' % func_name()

    am = Model.get_unique(sess, name='bl45p', vendor=hp)
    assert isinstance(am, Model), 'no model in %s' % func_name()

    cpu = sess.query(Cpu).first()
    assert isinstance(cpu, Cpu), 'no cpu in %s' % func_name()

    for i in xrange(NUM_MACHINES):
        machine = Machine(label='%s%s' % (MACHINE_NAME_PREFIX, i),
                          location=np,
                          model=am,
                          cpu=cpu,
                          cpu_quantity=2,
                          memory=32768)
        create(sess, machine)

    machines = sess.query(Machine).filter(
        Machine.label.like(MACHINE_NAME_PREFIX + '%')).all()

    eq_(len(machines), NUM_MACHINES)
Пример #2
0
    def render(self, session, room, building, fullname, comments, **arguments):
        dbbuilding = Building.get_unique(session, building, compel=True)
        add_location(session, Room, room, dbbuilding, fullname=fullname,
                     comments=comments)

        session.flush()

        return
Пример #3
0
    def render(self, session, room, building, fullname, comments, **arguments):
        dbbuilding = Building.get_unique(session, building, compel=True)
        add_location(session,
                     Room,
                     room,
                     dbbuilding,
                     fullname=fullname,
                     comments=comments)

        session.flush()

        return
Пример #4
0
    def render(self, session, dbuser, fqdn, building, ip, network_environment,
               comments, **arguments):
        dbnet_env = NetworkEnvironment.get_unique_or_default(
            session, network_environment)
        self.az.check_network_environment(dbuser, dbnet_env)

        if building:
            dbbuilding = Building.get_unique(session, building, compel=True)
        else:
            dbbuilding = None

        (short, dbdns_domain) = parse_fqdn(session, fqdn)
        dbfqdn = Fqdn.get_or_create(session,
                                    name=short,
                                    dns_domain=dbdns_domain,
                                    dns_environment=dbnet_env.dns_environment)
        if ip:
            dbnetwork = get_net_id_from_ip(session, ip, dbnet_env)
            dbdns_rec = ARecord.get_or_create(session,
                                              fqdn=dbfqdn,
                                              ip=ip,
                                              network=dbnetwork)
        else:
            dbdns_rec = ARecord.get_unique(session, dbfqdn, compel=True)
            ip = dbdns_rec.ip
            dbnetwork = dbdns_rec.network

        assert ip in dbnetwork.network, "IP %s is outside network %s" % (
            ip, dbnetwork.ip)

        if ip in dbnetwork.router_ips:
            raise ArgumentError(
                "IP address {0} is already present as a router "
                "for {1:l}.".format(ip, dbnetwork))

        # Policy checks are valid only for internal networks
        if dbnetwork.is_internal:
            if ip >= dbnetwork.first_usable_host or \
               int(ip) - int(dbnetwork.ip) in dbnetwork.reserved_offsets:
                raise ArgumentError(
                    "IP address {0} is not a valid router address "
                    "on {1:l}.".format(ip, dbnetwork))

        dbnetwork.routers.append(
            RouterAddress(ip=ip,
                          location=dbbuilding,
                          dns_environment=dbdns_rec.fqdn.dns_environment,
                          comments=comments))
        session.flush()

        # TODO: update the templates of Zebra hosts on the network

        return
Пример #5
0
def test_no_host_threshold():
    """ ensure down_hosts_threshold must exist """
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    np = Building.get_unique(sess, name='np', compel=True)

    per = sess.query(Personality).select_from(
            join(Archetype, Personality)).filter(
            and_(Archetype.name=='windows', Personality.name=='generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np, personality=per, branch=br)
    add(sess, ec)
    commit(sess)
Пример #6
0
def test_create_machines_for_hosts():
    np = Building.get_unique(sess, name='np', compel=True)
    am = Model.get_unique(sess, name='vm', compel=True)
    a_cpu = Cpu.get_unique(sess, name='aurora_cpu', compel=True)

    for i in xrange(NUM_HOSTS):
        machine = Machine(label='%s%s'% (MACHINE_NAME, i), location=np, model=am,
                          cpu=a_cpu, cpu_quantity=8, memory=32768)
        create(sess, machine)

    machines = sess.query(Machine).filter(
        Machine.label.like(MACHINE_NAME+'%')).all()

    assert len(machines) is NUM_MACHINES
    print 'created %s esx machines' % len(machines)
Пример #7
0
    def render(self, session, bunker, room, building, fullname, comments,
               **arguments):
        if room:
            dbparent = Room.get_unique(session, room, compel=True)
        elif building:
            dbparent = Building.get_unique(session, building, compel=True)
        else:  # pragma: no cover
            raise ArgumentError("Please specify either --room or --building.")

        add_location(session, Bunker, bunker, dbparent, fullname=fullname,
                     comments=comments)

        session.flush()

        return
Пример #8
0
def test_create_vm():
    #vend = Vendor.get_unique(sess, 'virtual')
    mod = Model.get_unique(sess, name='vm', compel=True)
    proc = Cpu.get_unique(sess, name='virtual_cpu', speed=0, compel=True)
    np = Building.get_unique(sess, 'np', compel=True)

    for i in xrange(NUM_MACHINES):
        vm = Machine(label='%s%s'%(VM_NAME, i), location=np, model=mod,
                     cpu=proc, cpu_quantity=1, memory=4196)
        create(sess, vm)

    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME+'%')).all()

    assert len(machines) is NUM_MACHINES
    print 'created %s machines' % (len(machines))
Пример #9
0
def test_no_host_threshold():
    """ ensure down_hosts_threshold must exist """
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    np = Building.get_unique(sess, name='np', compel=True)

    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np,
                    personality=per,
                    branch=br)
    add(sess, ec)
    commit(sess)
Пример #10
0
def setup():
    dmn = DnsDomain(name=DNS_DOMAIN_NAME)
    create(sess, dmn)
    assert dmn, 'no dns domain in %s' % func_name()

    pi = Building.get_unique(sess, name='pi', compel=True)

    n = IPv4Network(TEST_NET)
    net = Network(name=TEST_NET_NAME, network=n, location=pi)
    create(sess, net)
    assert net, 'no network created by %s' % func_name()

    ip = IPv4Address(TEST_IP)
    arec = ARecord(name=AREC_NAME, dns_domain=dmn, ip=ip, network=net)
    create(sess, arec)
    assert arec, 'no ARecord created by %s' % func_name()
Пример #11
0
def setup():
    dmn = DnsDomain(name=DNS_DOMAIN_NAME)
    create(sess, dmn)
    assert dmn, 'no dns domain in %s' % func_name()

    pi = Building.get_unique(sess, name='pi', compel=True)

    n = IPv4Network(TEST_NET)
    net = Network(name=TEST_NET_NAME, network=n, location=pi)
    create(sess, net)
    assert net, 'no network created by %s' % func_name()

    ip = IPv4Address(TEST_IP)
    arec = ARecord(name=AREC_NAME, dns_domain=dmn, ip=ip, network=net)
    create(sess, arec)
    assert arec, 'no ARecord created by %s' % func_name()
Пример #12
0
    def render(self, session, dbuser,
               fqdn, building, ip, network_environment, comments, **arguments):
        dbnet_env = NetworkEnvironment.get_unique_or_default(session,
                                                             network_environment)
        self.az.check_network_environment(dbuser, dbnet_env)

        if building:
            dbbuilding = Building.get_unique(session, building, compel=True)
        else:
            dbbuilding = None

        (short, dbdns_domain) = parse_fqdn(session, fqdn)
        dbfqdn = Fqdn.get_or_create(session, name=short,
                                    dns_domain=dbdns_domain,
                                    dns_environment=dbnet_env.dns_environment)
        if ip:
            dbnetwork = get_net_id_from_ip(session, ip, dbnet_env)
            dbdns_rec = ARecord.get_or_create(session, fqdn=dbfqdn, ip=ip,
                                              network=dbnetwork)
        else:
            dbdns_rec = ARecord.get_unique(session, dbfqdn, compel=True)
            ip = dbdns_rec.ip
            dbnetwork = dbdns_rec.network

        assert ip in dbnetwork.network, "IP %s is outside network %s" % (ip,
                                                                         dbnetwork.ip)

        if ip in dbnetwork.router_ips:
            raise ArgumentError("IP address {0} is already present as a router "
                                "for {1:l}.".format(ip, dbnetwork))

        # Policy checks are valid only for internal networks
        if dbnetwork.is_internal:
            if ip >= dbnetwork.first_usable_host or \
               int(ip) - int(dbnetwork.ip) in dbnetwork.reserved_offsets:
                raise ArgumentError("IP address {0} is not a valid router address "
                                    "on {1:l}.".format(ip, dbnetwork))

        dbnetwork.routers.append(RouterAddress(ip=ip, location=dbbuilding,
                                               dns_environment=dbdns_rec.fqdn.dns_environment,
                                               comments=comments))
        session.flush()

        # TODO: update the templates of Zebra hosts on the network

        return
Пример #13
0
def test_create_esx_cluster():
    """ tests the creation of an EsxCluster """
    np = Building.get_unique(sess, name='np', compel=True)
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    per = sess.query(Personality).select_from(
            join(Archetype, Personality)).filter(
            and_(Archetype.name=='windows', Personality.name=='generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME, location_constraint=np,
                    personality=per, down_hosts_threshold=2, branch=br)
    create(sess, ec)

    assert ec
    print ec

    assert ec.max_hosts is 8
    print 'esx cluster max members = %s' % ec.max_hosts
Пример #14
0
    def render(self, session, fqdn, ip, building, comments, **arguments):
        if fqdn:
            dbdns_rec = ARecord.get_unique(session, fqdn, compel=True)
            ip = dbdns_rec.ip
        if not ip:
            raise ArgumentError("Please specify either --ip or --fqdn.")

        router = RouterAddress.get_unique(session, ip=ip, compel=True)

        if building:
            dbbuilding = Building.get_unique(session, name=building,
                                             compel=True)
            router.location = dbbuilding

        if comments:
            router.comments = comments

        session.flush()
Пример #15
0
    def render(self, session, desk, room, building, fullname, comments,
               **arguments):
        if room:
            dbparent = Room.get_unique(session, room, compel=True)
        elif building:
            dbparent = Building.get_unique(session, building, compel=True)
        else:  # pragma: no cover
            raise ArgumentError("Please specify either --room or --building.")

        add_location(session,
                     Desk,
                     desk,
                     dbparent,
                     fullname=fullname,
                     comments=comments)

        session.flush()

        return
Пример #16
0
    def render(self, session, fqdn, ip, building, comments, **arguments):
        if fqdn:
            dbdns_rec = ARecord.get_unique(session, fqdn, compel=True)
            ip = dbdns_rec.ip
        if not ip:
            raise ArgumentError("Please specify either --ip or --fqdn.")

        router = RouterAddress.get_unique(session, ip=ip, compel=True)

        if building:
            dbbuilding = Building.get_unique(session,
                                             name=building,
                                             compel=True)
            router.location = dbbuilding

        if comments:
            router.comments = comments

        session.flush()
Пример #17
0
def test_create_machines_for_hosts():
    np = Building.get_unique(sess, name='np', compel=True)
    am = Model.get_unique(sess, name='vm', compel=True)
    a_cpu = Cpu.get_unique(sess, name='aurora_cpu', compel=True)

    for i in xrange(NUM_HOSTS):
        machine = Machine(label='%s%s' % (MACHINE_NAME, i),
                          location=np,
                          model=am,
                          cpu=a_cpu,
                          cpu_quantity=8,
                          memory=32768)
        create(sess, machine)

    machines = sess.query(Machine).filter(
        Machine.label.like(MACHINE_NAME + '%')).all()

    assert len(machines) is NUM_MACHINES
    print 'created %s esx machines' % len(machines)
Пример #18
0
def test_create_vm():
    #vend = Vendor.get_unique(sess, 'virtual')
    mod = Model.get_unique(sess, name='vm', compel=True)
    proc = Cpu.get_unique(sess, name='virtual_cpu', speed=0, compel=True)
    np = Building.get_unique(sess, 'np', compel=True)

    for i in xrange(NUM_MACHINES):
        vm = Machine(label='%s%s' % (VM_NAME, i),
                     location=np,
                     model=mod,
                     cpu=proc,
                     cpu_quantity=1,
                     memory=4196)
        create(sess, vm)

    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME +
                                                             '%')).all()

    assert len(machines) is NUM_MACHINES
    print 'created %s machines' % (len(machines))
Пример #19
0
def test_create_esx_cluster():
    """ tests the creation of an EsxCluster """
    np = Building.get_unique(sess, name='np', compel=True)
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np,
                    personality=per,
                    down_hosts_threshold=2,
                    branch=br)
    create(sess, ec)

    assert ec
    print ec

    assert ec.max_hosts is 8
    print 'esx cluster max members = %s' % ec.max_hosts
Пример #20
0
def test_create_machines_for_test_host():
    np = Building.get_unique(sess, 'np')
    assert isinstance(np,Building), 'no building in %s' % func_name()

    hp = Vendor.get_unique(sess, 'hp')
    assert isinstance(hp, Vendor), 'no vendor in %s' % func_name()

    am = Model.get_unique(sess, name='bl45p', vendor=hp)
    assert isinstance(am, Model), 'no model in %s' % func_name()

    cpu = sess.query(Cpu).first()
    assert isinstance(cpu, Cpu), 'no cpu in %s' % func_name()

    for i in xrange(NUM_MACHINES):
        machine = Machine(label='%s%s'% (MACHINE_NAME_PREFIX, i), location=np,
                          model=am, cpu=cpu, cpu_quantity=2, memory=32768)
        create(sess, machine)

    machines = sess.query(Machine).filter(
        Machine.label.like(MACHINE_NAME_PREFIX+'%')).all()

    eq_(len(machines), NUM_MACHINES)
Пример #21
0
 def render(self, session, building, **arguments):
     return Building.get_unique(session, building, compel=True)