def action(self, entity, action, attributes): ''' Perform an action on an Entity ''' if(action=="start"): logger.debug('\n[interCNG]-----Receiving action START intercng') clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'linkcng', {}) clientaction.action("start", clientaction.GetElement_pathuuid(entity['attributes']['occi']['intercng']['linkcng'])['uuid']) entity['attributes']['occi']['intercng']['state']="1" clientupdate = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'intercng', entity) clientupdate.PUT() elif(action=="stop"): logger.debug('\n[interCNG]-----Receiving action STOP intercng') clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'linkcng', {}) clientaction.action("stop", clientaction.GetElement_pathuuid(entity['attributes']['occi']['intercng']['linkcng'])['uuid']) entity['attributes']['occi']['intercng']['state']="0" clientupdate = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'intercng', entity) clientupdate.PUT() logger.debug('***The Entity\'s action operation of the intercng_backend***')
def delete(self, entity): ''' Delete an Entity ''' if(entity['attributes']['occi']['linkcng']['state'] == "0"): logger.debug('\n[linkCNG:stop]-----link is not configured') else: clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("stop", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngSRC'])['uuid']) clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("stop", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngDST'])['uuid']) if entity['attributes']['occi']['linkcng']['linkType'] == "openvpn": cngsrcDriver = ovpnDriver() cngdstDriver = ovpnDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] cngsrcDriver.stop_site_to_site_OVPN(cngsrcDriver, publicaddrCNGsrc, tunnelinterface, privateNetToCNGdst) cngdstDriver.stop_site_to_site_OVPN(cngdstDriver, publicaddrCNGdst, tunnelinterface, privateNetToCNGsrc) logger.debug('\n[linkCNG:stop]-----End Release of OpenVPN link') elif entity['attributes']['occi']['linkcng']['linkType'] == "ipsec": cngsrcDriver = ipsecDriver() cngdstDriver = ipsecDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] cngsrcDriver.stop_gw(cngsrcDriver, publicaddrCNGsrc, publicaddrCNGdst, privateNetToCNGdst, tunnelinterface) cngdstDriver.stop_gw(cngdstDriver, publicaddrCNGdst, publicaddrCNGsrc, privateNetToCNGsrc, tunnelinterface) logger.debug('\n[linkCNG:start]-----End Release of IPSEC link') elif entity['attributes']['occi']['linkcng']['linkType'] == "openflow": logger.debug('\n[linkCNG:stop]-----End Release of OpenFlow link') logger.debug('\n[linkCNG]-----Receiving DELETE linkcng') logger.debug('***The delete operation of the linkcng_backend***')
def action(self, entity, action, attributes): ''' Perform an action on an Entity ''' if(action=="start"): logger.debug('\n[linkCNG]-----Receiving action START linkcng') if(entity['attributes']['occi']['linkcng']['state'] == "1"): logger.debug('\n[linkCNG:start]-----link is configured') else: logger.debug('\n[linkCNG:start]-----link is not configured') clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("start", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngSRC'])['uuid']) clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("start", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngDST'])['uuid']) if entity['attributes']['occi']['linkcng']['linkType'] == "openvpn": cngsrcDriver = ovpnDriver() cngdstDriver = ovpnDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunneladdrSrc = entity['attributes']['occi']['linkcng']['tunneladdrSrc'] tunneladdrDst = entity['attributes']['occi']['linkcng']['tunneladdrDst'] cngsrcDriver.configure_site_to_site_openvpn(cngsrcDriver, publicaddrCNGsrc, tunnelinterface, tunneladdrSrc, tunneladdrDst, publicaddrCNGdst, privateNetToCNGdst) cngdstDriver.configure_site_to_site_openvpn(cngdstDriver, publicaddrCNGdst, tunnelinterface, tunneladdrDst, tunneladdrSrc, publicaddrCNGsrc, privateNetToCNGsrc) logger.debug('\n[linkCNG:start]-----End configuration of OpenVPN link') elif entity['attributes']['occi']['linkcng']['linkType'] == "ipsec": cngsrcDriver = ipsecDriver() cngdstDriver = ipsecDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunneladdrSrc = entity['attributes']['occi']['linkcng']['tunneladdrSrc'] tunneladdrDst = entity['attributes']['occi']['linkcng']['tunneladdrDst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] tunneladdrprefix = entity['attributes']['occi']['linkcng']['tunneladdrprefix'] tunnelauthenticationkey = entity['attributes']['occi']['linkcng']['tunnelauthenticationkey'] clientinformation = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'linkcng', {}) uuid_src = clientinformation.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngSRC'])['uuid'] uuid_dst = clientinformation.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngDST'])['uuid'] cngsrcDriver.configure_protocol_IPSEC(cngsrcDriver, publicaddrCNGsrc, "eth0", 'IKE'+uuid_src, 'ESP'+uuid_src) cngdstDriver.configure_protocol_IPSEC(cngdstDriver, publicaddrCNGdst, "eth0", 'IKE'+uuid_dst, 'ESP'+uuid_dst) cngsrcDriver.connect_gw(cngsrcDriver, tunnelinterface, tunneladdrSrc, tunneladdrprefix, '1', 'gre', publicaddrCNGsrc, publicaddrCNGdst, tunnelauthenticationkey, 'IKE'+uuid_src, 'ESP'+uuid_src, tunneladdrDst, privateNetToCNGdst) cngdstDriver.connect_gw(cngdstDriver, tunnelinterface, tunneladdrDst, tunneladdrprefix, '1', 'gre', publicaddrCNGdst, publicaddrCNGsrc, tunnelauthenticationkey, 'IKE'+uuid_dst, 'ESP'+uuid_dst, tunneladdrSrc, privateNetToCNGsrc) logger.debug('\n[linkCNG:start]-----End configuration of IPSEC link') elif entity['attributes']['occi']['linkcng']['linkType'] == "openflow": logger.debug('\n[linkCNG:start]-----End configuration of OpenFlow link') entity['attributes']['occi']['linkcng']['state']="1" clientupdate = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'linkcng', entity) clientupdate.PUT() elif(action=="stop"): logger.debug('\n[linkCNG]-----Receiving action STOP linkcng') if(entity['attributes']['occi']['linkcng']['state'] == "0"): logger.debug('\n[linkCNG:stop]-----link is not configured') else: clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("stop", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngSRC'])['uuid']) clientaction = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'cng', {}) clientaction.action("stop", clientaction.GetElement_pathuuid(entity['attributes']['occi']['linkcng']['cngDST'])['uuid']) if entity['attributes']['occi']['linkcng']['linkType'] == "openvpn": cngsrcDriver = ovpnDriver() cngdstDriver = ovpnDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] cngsrcDriver.stop_site_to_site_OVPN(cngsrcDriver, publicaddrCNGsrc, tunnelinterface, privateNetToCNGdst) cngdstDriver.stop_site_to_site_OVPN(cngdstDriver, publicaddrCNGdst, tunnelinterface, privateNetToCNGsrc) logger.debug('\n[linkCNG:stop]-----End Release of OpenVPN link') elif entity['attributes']['occi']['linkcng']['linkType'] == "ipsec": cngsrcDriver = ipsecDriver() cngdstDriver = ipsecDriver() publicaddrCNGsrc = entity['attributes']['occi']['linkcng']['publicaddrCNGsrc'] publicaddrCNGdst = entity['attributes']['occi']['linkcng']['publicaddrCNGdst'] privateNetToCNGsrc = entity['attributes']['occi']['linkcng']['privateNetToCNGsrc'] privateNetToCNGdst = entity['attributes']['occi']['linkcng']['privateNetToCNGdst'] tunnelinterface = entity['attributes']['occi']['linkcng']['tunnelinterface'] cngsrcDriver.stop_gw(cngsrcDriver, publicaddrCNGsrc, publicaddrCNGdst, privateNetToCNGdst, tunnelinterface) cngdstDriver.stop_gw(cngdstDriver, publicaddrCNGdst, publicaddrCNGsrc, privateNetToCNGsrc, tunnelinterface) logger.debug('\n[linkCNG:start]-----End Release of IPSEC link') elif entity['attributes']['occi']['linkcng']['linkType'] == "openflow": logger.debug('\n[linkCNG:stop]-----End Release of OpenFlow link') entity['attributes']['occi']['linkcng']['state']="0" clientupdate = OCCIinterfaceClient(config.OCNI_IP, config.OCNI_PORT, 'linkcng', entity) clientupdate.PUT() logger.debug('***The Entity\'s action operation of the linkcng_backend***')