Пример #1
0
 def __init__(self, name, format, classes, role):
     self.role = role
     self.name = name
     self.format = format
     self.classes = classes
     self.dbapi = api.get_instance()
     self._get_lookup_key_id()
Пример #2
0
    def get_one(self, status):
        """
        scanning network status

        scan if dhcp is exist, gateway is ok and subnet can be used
        """
        dbapi = api.get_instance()
        try:
            gateway = dbapi.find_lookup_value_by_match("env=gateway")[0].value
            master = dbapi.find_lookup_value_by_match("env=master")[0].value
            LOG.info("get env from database, gateway: %s, master: %s" %
                     (gateway, master))
        except:
            return {
                "error": "system error with no master and gateway"
            }
        LOG.info("begin to scanning network")
        dhcp_status = network_scan.dhcp_scan()
        LOG.info("scanning dhcp")
        gateway_status = network_scan.gateway_scan(gateway)
        LOG.info("scanning gateway")
        #subnet_status = network_scan.subnet_scan(gateway, master)
        LOG.info("scanning subnet")
        subnet_status = True
        result = {
            "dhcp_status": dhcp_status,
            "gateway_status": gateway_status,
            "subnet_status": subnet_status
        }
        return result
Пример #3
0
 def test_action(self):
     with mock.patch("mimic.db.api.get_instance",
                     mock.MagicMock(return_value=FakeDBAPI())):
                     self.dbapi = dbapi.get_instance()
                     driver = base_line_ip_driver.get_backend("PublicIP",
                                     "192.168.10.1",
                                     ["sunfire::masternode"],
                                     ["master"])
                     driver.action(1, "master.ustack.com")
Пример #4
0
 def test_action(self):
     with mock.patch("mimic.db.api.get_instance",
                     mock.MagicMock(return_value=FakeDBAPI())):
                     self.dbapi = dbapi.get_instance()
                     driver = env_driver.get_backend("Env",
                                     "env=master",
                                     ["sunfire::masternode"],
                                     ["master"])
                     driver.action(1, "master.ustack.com")
Пример #5
0
def unused_ip(mac):
    dbapi = api.get_instance()
    result = dbapi.find_lookup_value_by_match("env=subnet")
    subnet = result[0].value
    ipdata = get_remote_data("%s/dhcp/%s/unused_ip?mac=%s" %
                              (cfg.CONF.foreman_proxy_address,
                               subnet, mac), "GET")
    LOG.info("unused_ip: %s" % ipdata)
    return ipdata['ip']
Пример #6
0
    def setUp(self):
        super(FunctionalTest, self).setUp()
        self.app = self._make_app()
        self.dbapi = dbapi.get_instance()

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)
Пример #7
0
 def test_action(self):
     with contextlib.nested(
         mock.patch("mimic.db.api.get_instance",
                     mock.MagicMock(return_value=FakeDBAPI())),
         mock.patch("mimic.engine.foreman_helper.hosts",
                     mock.MagicMock(return_value=utils.get_fake_hosts()))):
         self.dbapi = dbapi.get_instance()
         driver = list_increment_driver.get_backend("ListIncrement",
                                                    "ipaddr",
                                                    ["sunfire::masternode"],
                                                    ["master"])
         driver.action(1, "master.ustack.com", ip="192.168.10.1", role=["master"])
Пример #8
0
    def get_network_info(self, networklist):
        dbapi = api.get_instance()
        for network in networklist:
            LOG.info("find %s in network env" % network)
            value = dbapi.find_lookup_value_by_match("env=%s" % network)

            if len(value) > 0:
                if network != "netmask":
                    networklist[network] = value[0].value
                else:
                    networklist[network] = int(value[0].value)
        LOG.info("network infomation get from database is: %s" % networklist)
        return networklist
Пример #9
0
    def _update_env_key_value(self, key, value):
        """
        update the global parameter key and value

        key: global parameter key
        value: global parameter value
        """
        LOG.debug("begin to update env")
        dbapi = api.get_instance()
        lookup_values = {"match": "env=%s" % key, "value": value, "lookup_key_id": 10000}
        result = dbapi.find_lookup_value_by_match("env=%s" % key)
        LOG.debug("find env in database: %s" % result)
        if len(result) > 0:
            dbapi.update_lookup_value(result[0].id, lookup_values)
        else:
            dbapi.create_lookup_value(lookup_values)
        return lookup_values
Пример #10
0
    def post(self, content):

        key = content["key"]
        value = content["value"]
        LOG.info("new env parameter input, key: %s, value: %s" % (key, value))

        dbapi = api.get_instance()
        lookup_values = {"match": "env=%s" % key, "value": value, "lookup_key_id": 10000}
        result = dbapi.find_lookup_value_by_match("env=%s" % key)
        LOG.info("find env in database: %s" % result)

        if len(result) > 0:
            return {"error": "fail to add same env"}

        dbapi.create_lookup_value(lookup_values)
        LOG.info("env created: %s" % lookup_values)
        return lookup_values
Пример #11
0
 def setUp(self):
     super(DbLookupValueTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
Пример #12
0
 def before(self, state):
     state.request.dbapi = dbapi.get_instance()
Пример #13
0
 def setUp(self):
     super(ForemanHelperTestCase, self).setUp()
     foreman_helper.get_remote_data = mock.MagicMock(
         return_value="test_data")
     self.dbapi = dbapi.get_instance()
Пример #14
0
 def get_one(self, match):
     dbapi = api.get_instance()
     result = dbapi.find_lookup_value_by_match("env=%s" % match)
     LOG.info("find env: %s" % result)
     if len(result) > 0:
         return result[0]["value"]