当前位置: 首页>>代码示例>>Python>>正文


Python CsFile.addeq方法代码示例

本文整理汇总了Python中cs.CsFile.CsFile.addeq方法的典型用法代码示例。如果您正苦于以下问题:Python CsFile.addeq方法的具体用法?Python CsFile.addeq怎么用?Python CsFile.addeq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cs.CsFile.CsFile的用法示例。


在下文中一共展示了CsFile.addeq方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: configure_l2tpIpsec

# 需要导入模块: from cs.CsFile import CsFile [as 别名]
# 或者: from cs.CsFile.CsFile import addeq [as 别名]
    def configure_l2tpIpsec(self, left,  obj):
        vpnconffile="%s/l2tp.conf" % (self.VPNCONFDIR)
        vpnsecretfilte="%s/ipsec.any.secrets" % (self.VPNCONFDIR)
        xl2tpdconffile="/etc/xl2tpd/xl2tpd.conf"
        xl2tpoptionsfile='/etc/ppp/options.xl2tpd'

        file = CsFile(vpnconffile)
        localip=obj['local_ip']
        localcidr=obj['local_cidr']
        publicIface=obj['public_interface']
        iprange=obj['ip_range']
        psk=obj['preshared_key']

        #left
        file.addeq(" left=%s" % left)
        file.commit()


        secret = CsFile(vpnsecretfilte)
        secret.addeq(": PSK \"%s\"" %psk)
        secret.commit()

        xl2tpdconf = CsFile(xl2tpdconffile)
        xl2tpdconf.addeq("ip range = %s" %iprange)
        xl2tpdconf.addeq("local ip = %s" %localip)
        xl2tpdconf.commit()

        xl2tpoptions=CsFile(xl2tpoptionsfile)
        xl2tpoptions.search("ms-dns ", "ms-dns %s" %localip)
        xl2tpoptions.commit()
开发者ID:HaiShengGu,项目名称:cloudstack,代码行数:32,代码来源:configure.py

示例2: configure_ipsec

# 需要导入模块: from cs.CsFile import CsFile [as 别名]
# 或者: from cs.CsFile.CsFile import addeq [as 别名]
    def configure_ipsec(self, obj):
        leftpeer = obj['local_public_ip']
        rightpeer = obj['peer_gateway_ip']
        peerlist = obj['peer_guest_cidr_list'].replace(' ', '')
        vpnconffile = "%s/ipsec.vpn-%s.conf" % (self.VPNCONFDIR, rightpeer)
        vpnsecretsfile = "%s/ipsec.vpn-%s.secrets" % (self.VPNCONFDIR, rightpeer)
        ikepolicy = obj['ike_policy'].replace(';', '-')
        esppolicy = obj['esp_policy'].replace(';', '-')

        if rightpeer in self.confips:
            self.confips.remove(rightpeer)
        file = CsFile(vpnconffile)
        file.add("#conn for vpn-%s" % rightpeer, 0)
        file.search("conn ", "conn vpn-%s" % rightpeer)
        file.addeq(" left=%s" % leftpeer)
        file.addeq(" leftsubnet=%s" % obj['local_guest_cidr'])
        file.addeq(" right=%s" % rightpeer)
        file.addeq(" rightsubnet=%s" % peerlist)
        file.addeq(" type=tunnel")
        file.addeq(" authby=secret")
        file.addeq(" keyexchange=ike")
        file.addeq(" ike=%s" % ikepolicy)
        file.addeq(" ikelifetime=%s" % self.convert_sec_to_h(obj['ike_lifetime']))
        file.addeq(" esp=%s" % esppolicy)
        file.addeq(" lifetime=%s" % self.convert_sec_to_h(obj['esp_lifetime']))
        file.addeq(" keyingtries=2")
        file.addeq(" auto=route")
        if 'encap' not in obj:
            obj['encap'] = False
        file.addeq(" forceencaps=%s" % CsHelper.bool_to_yn(obj['encap']))
        if obj['dpd']:
            file.addeq(" dpddelay=30")
            file.addeq(" dpdtimeout=120")
            file.addeq(" dpdaction=restart")
        secret = CsFile(vpnsecretsfile)
        secret.search("%s " % leftpeer, "%s %s : PSK \"%s\"" % (leftpeer, rightpeer, obj['ipsec_psk']))
        if secret.is_changed() or file.is_changed():
            secret.commit()
            file.commit()
            logging.info("Configured vpn %s %s", leftpeer, rightpeer)
            CsHelper.execute("ipsec rereadsecrets")

        # This will load the new config
        CsHelper.execute("ipsec reload")
        os.chmod(vpnsecretsfile, 0400)

        for i in xrange(3):
            result = CsHelper.execute('ipsec status vpn-%s | grep "%s"' % (rightpeer, peerlist.split(",", 1)[0]))
            if len(result) > 0:
                break
            time.sleep(1)

        # With 'auto=route', connections are established on an attempt to
        # communicate over the S2S VPN. This uses ping to initialize the connection.
        CsHelper.execute("timeout 5 ping -c 3 %s" % (peerlist.split("/", 1)[0].replace(".0", ".1")))
开发者ID:exoscale,项目名称:cloudstack,代码行数:57,代码来源:configure.py

示例3: configure_ipsec

# 需要导入模块: from cs.CsFile import CsFile [as 别名]
# 或者: from cs.CsFile.CsFile import addeq [as 别名]
 def configure_ipsec(self, obj):
     leftpeer = obj['local_public_ip']
     rightpeer = obj['peer_gateway_ip']
     peerlist = obj['peer_guest_cidr_list'].lstrip().rstrip().replace(',', ' ')
     vpnconffile = "%s/ipsec.vpn-%s.conf" % (self.VPNCONFDIR, rightpeer)
     vpnsecretsfile = "%s/ipsec.vpn-%s.secrets" % (self.VPNCONFDIR, rightpeer)
     if rightpeer in self.confips:
         self.confips.remove(rightpeer)
     file = CsFile(vpnconffile)
     file.search("conn ", "conn vpn-%s" % rightpeer)
     file.addeq(" left=%s" % leftpeer)
     file.addeq(" leftsubnet=%s" % obj['local_guest_cidr'])
     file.addeq(" leftnexthop=%s" % obj['local_public_gateway'])
     file.addeq(" right=%s" % rightpeer)
     file.addeq(" rightsubnets={%s}" % peerlist)
     file.addeq(" type=tunnel")
     file.addeq(" authby=secret")
     file.addeq(" keyexchange=ike")
     file.addeq(" ike=%s" % obj['ike_policy'])
     file.addeq(" ikelifetime=%s" % self.convert_sec_to_h(obj['ike_lifetime']))
     file.addeq(" esp=%s" % obj['esp_policy'])
     file.addeq(" salifetime=%s" % self.convert_sec_to_h(obj['esp_lifetime']))
     file.addeq(" pfs=%s" % CsHelper.bool_to_yn(obj['dpd']))
     file.addeq(" keyingtries=2")
     file.addeq(" auto=start")
     if 'encap' not in obj:
         obj['encap']=False
     file.addeq(" forceencaps=%s" % CsHelper.bool_to_yn(obj['encap']))
     if obj['dpd']:
         file.addeq("  dpddelay=30")
         file.addeq("  dpdtimeout=120")
         file.addeq("  dpdaction=restart")
     secret = CsFile(vpnsecretsfile)
     secret.search("%s " % leftpeer, "%s %s: PSK \"%s\"" % (leftpeer, rightpeer, obj['ipsec_psk']))
     if secret.is_changed() or file.is_changed():
         secret.commit()
         file.commit()
         logging.info("Configured vpn %s %s", leftpeer, rightpeer)
         CsHelper.execute("ipsec auto --rereadall")
         CsHelper.execute("ipsec auto --add vpn-%s" % rightpeer)
         if not obj['passive']:
             CsHelper.execute("ipsec auto --up vpn-%s" % rightpeer)
     os.chmod(vpnsecretsfile, 0o400)
开发者ID:HaiShengGu,项目名称:cloudstack,代码行数:45,代码来源:configure.py

示例4: configure_ipsec

# 需要导入模块: from cs.CsFile import CsFile [as 别名]
# 或者: from cs.CsFile.CsFile import addeq [as 别名]
    def configure_ipsec(self, obj):
        leftpeer = obj['local_public_ip']
        rightpeer = obj['peer_gateway_ip']
        peerlist = obj['peer_guest_cidr_list'].replace(' ', '')
        vpnconffile = "%s/ipsec.vpn-%s.conf" % (self.VPNCONFDIR, rightpeer)
        vpnsecretsfile = "%s/ipsec.vpn-%s.secrets" % (self.VPNCONFDIR, rightpeer)
        ikepolicy=obj['ike_policy'].replace(';','-')
        esppolicy=obj['esp_policy'].replace(';','-')

        pfs='no'
        if 'modp' in esppolicy:
            pfs='yes'

        if rightpeer in self.confips:
            self.confips.remove(rightpeer)
        file = CsFile(vpnconffile)
        file.add("#conn for vpn-%s" % rightpeer, 0)
        file.search("conn ", "conn vpn-%s" % rightpeer)
        file.addeq(" left=%s" % leftpeer)
        file.addeq(" leftsubnet=%s" % obj['local_guest_cidr'])
        file.addeq(" leftnexthop=%s" % obj['local_public_gateway'])
        file.addeq(" right=%s" % rightpeer)
        file.addeq(" rightsubnet=%s" % peerlist)
        file.addeq(" type=tunnel")
        file.addeq(" authby=secret")
        file.addeq(" keyexchange=ike")
        file.addeq(" ike=%s" % ikepolicy)
        file.addeq(" ikelifetime=%s" % self.convert_sec_to_h(obj['ike_lifetime']))
        file.addeq(" esp=%s" % esppolicy)
        file.addeq(" lifetime=%s" % self.convert_sec_to_h(obj['esp_lifetime']))
        file.addeq(" pfs=%s" % pfs)
        file.addeq(" keyingtries=2")
        file.addeq(" auto=start")
        if 'encap' not in obj:
            obj['encap']=False
        file.addeq(" forceencaps=%s" % CsHelper.bool_to_yn(obj['encap']))
        if obj['dpd']:
            file.addeq(" dpddelay=30")
            file.addeq(" dpdtimeout=120")
            file.addeq(" dpdaction=restart")
        secret = CsFile(vpnsecretsfile)
        secret.search("%s " % leftpeer, "%s %s : PSK \"%s\"" % (leftpeer, rightpeer, obj['ipsec_psk']))
        if secret.is_changed() or file.is_changed():
            secret.commit()
            file.commit()
            logging.info("Configured vpn %s %s", leftpeer, rightpeer)
            CsHelper.execute("ipsec rereadsecrets")

        # This will load the new config and start the connection when needed since auto=start in the config
        CsHelper.execute("ipsec reload")
        os.chmod(vpnsecretsfile, 0400)
开发者ID:krissterckx,项目名称:cloudstack,代码行数:53,代码来源:configure.py


注:本文中的cs.CsFile.CsFile.addeq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。