Exemplo n.º 1
0
    def get_equipamento(self):
        pagination = Pagination(0, 25, "", "", "")
        equipamento_ = Equipamento(self.network_api.url,
                                   self.network_api.username,
                                   self.network_api.password)

        result = equipamento_.find_equips(None, None, None, None, None,
                                          self.ip["address"], pagination)
        equip = result.get('equipamento', [])
        if equip:
            self.equipamento["name"] = equip[0]['nome']
            self.equipamento["id"] = equip[0]['id']
            self.equipamento["vlan"] = equip[0]['ips'][0]['vlan']

            #get vip
            result = equipamento_.get_real_related(self.equipamento["id"])
            vips = result["vips"]
            if isinstance(vips, list):  #is list?
                for vip_ in vips:
                    id_vip = vip_.get('id_vip')
                    if id_vip not in self.vips:
                        self.vips.append(id_vip)
            elif vips and isinstance(vips, dict):
                id_vip = vips.get('id_vip')
                if id_vip not in self.vips:
                    self.vips.append(id_vip)
Exemplo n.º 2
0
    def remove_networkapi_ip(self, equipment_id, ip_id):
        from networkapiclient.Equipamento import Equipamento

        try:
            LOG.info(
                "Removing networkapi equipment [ id = %s ]" % equipment_id)
            equipmentAPI = Equipamento(networkapi_url=self.networkapi_credentials.endpoint,
                                       user=self.networkapi_credentials.user,
                                       password=self.networkapi_credentials.password)
            equipmentAPI.remover_ip(id_equipamento=equipment_id, id_ip=ip_id)
            return True
        except Exception as e:
            LOG.warning(
                "We could not remove networkapi equipment because %s" % e)
            return None
Exemplo n.º 3
0
 def create_equipamento(self):
     """Get an instance of equipamento services facade."""
     return Equipamento(
         self.networkapi_url,
         self.user,
         self.password,
         self.user_ldap)
Exemplo n.º 4
0
    def release_ip(self):
        """
        Release de ip address in GloboNetwork

        # remove the real Vip.remover_real(<vip_id>, <ip_id>, <equip_id>)
        """
        vip_action = Vip(self.network_api.url, self.network_api.username,
                         self.network_api.password)
        equipamento_ = Equipamento(self.network_api.url,
                                   self.network_api.username,
                                   self.network_api.password)
        if self.vips and self.equipamento.get("id"):
            for vip_id in self.vips:
                if self.ip.get("id") and self.equipamento.get("id"):
                    LOG.debug(
                        "releasing ip %s from GloboNetwork with vip_id=%s and equipamento_id=%s",
                        self.ip["address"], vip_id, self.equipamento.get("id"))
                    try:
                        result = vip_action.remover_real(
                            vip_id, self.ip.get("id"),
                            self.equipamento.get("id"))
                        LOG.debug("vip.remover_real result: %s", result)
                    except Exception, e:
                        LOG.exception("ops... something went wrong")
                else:
                    LOG.warning("ip %s is already released from GloboNetwork",
                                self.ip["address"])
Exemplo n.º 5
0
    def register_networkapi_equipment(self, equipment_name):
        from networkapiclient.Equipamento import Equipamento

        try:
            LOG.info("Register database infra as equipment on network api...")
            equipmentAPI = Equipamento(networkapi_url=self.networkapi_credentials.endpoint,
                                       user=self.networkapi_credentials.user,
                                       password=self.networkapi_credentials.password)

            equipment = equipmentAPI.inserir(name=equipment_name,
                                             id_equipment_type=self.networkapi_credentials.get_parameter_by_name(
                                                 'id_equipment_type'),
                                             id_model=self.networkapi_credentials.get_parameter_by_name(
                                                 'id_model'),
                                             id_group=self.networkapi_credentials.get_parameter_by_name('id_group'))

            LOG.info("equipment = %s " % repr(equipment))
            return equipment['equipamento']['id']
        except Exception as e:
            LOG.warning(
                "We could not register networkapi equipment because %s" % e)
            return None
    def get_equipamento(self):
        pagination = Pagination(0, 25, "", "", "")
        equipamento_ = Equipamento(self.network_api.url, self.network_api.username, self.network_api.password)

        result = equipamento_.find_equips(None, None, None, None, None, self.ip["address"], pagination)
        equip = result.get('equipamento',[])
        if equip:
            self.equipamento["name"] = equip[0]['nome']
            self.equipamento["id"] = equip[0]['id']
            self.equipamento["vlan"] = equip[0]['ips'][0]['vlan']

            #get vip
            result = equipamento_.get_real_related(self.equipamento["id"])
            vips = result["vips"]
            if isinstance(vips, list): #is list?
                for vip_ in vips:
                    id_vip = vip_.get('id_vip')
                    if id_vip not in self.vips:
                        self.vips.append(id_vip)
            elif vips and isinstance(vips, dict):
                id_vip = vips.get('id_vip')
                if id_vip not in self.vips:
                    self.vips.append(id_vip)