コード例 #1
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
    def lsp_set_port_security(port, mac=None, ip=None):
        tem_mac = None
        tem_ip = None
        if isinstance(port, SwitchPort):
            port_name = port.name
            if port.mac is not None:
                tem_mac = port.mac
            if port.ip is not None:
                tem_ip = port.ip
        elif isinstance(port, str):
            port_name = port
            if ip is not None:
                tem_ip = ip
            if mac is not None:
                tem_mac = mac
        else:
            raise Exception("wrong type")

        if tem_mac is None:
            raise Exception("type")
        if tem_ip is not None:
            option = tem_mac + " " + tem_ip
        else:
            option = tem_mac
        cmd = ['ovn-nbctl', 'lsp-set-port-security', port_name, option]
        run_command(cmd, check_exit_code=True)
コード例 #2
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def add_port(self, port):
     if not isinstance(port, RoutePort):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lrp-add', self.name, port.name, port.mac, port.ip]
     if port.peer is not None:
         cmd.append("peer="+port.peer)
     run_command(cmd, check_exit_code=True)
     self._ports_list.append(port)
コード例 #3
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def lr_add(self, lr):
     if not isinstance(lr, RouterBase):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'create', 'Logical_Router', 'name='+lr.name]
     if lr.options:
         for key, val in lr.options.items():
             cmd.append("options:"+key+"="+val)
     run_command(cmd, check_exit_code=True)
     self.lr_dict.setdefault(lr.name, lr)
コード例 #4
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def lsp_set_options(port):
     if not isinstance(port, SwitchPort):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lsp-set-options', port.name]
     if port.options:
         for key, val in port.options.items():
             option = key + "=" + val
             cmd.append(option)
         #print(cmd)
     run_command(cmd, check_exit_code=True)
コード例 #5
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def add_nat(self, nat_type, external_ip, logical_ip, logical_port=None, external_mac=None):
     nat_type_tup = ("snat", "dnat", "dnat_and_snat")
     if nat_type not in nat_type_tup:
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lr-nat-add', self.name, nat_type, external_ip, logical_ip]
     if logical_port is not None:
         cmd.append(logical_port)
     if external_mac is not None:
         cmd.append(external_mac)
     run_command(cmd, check_exit_code=True)
コード例 #6
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def lsp_del(self, port):
     if isinstance(port, SwitchPort):
         port_name = port.name
     elif isinstance(port, str):
         port_name = port
     else:
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lsp-del', self.name, port_name]
     run_command(cmd, check_exit_code=True)
     self.ports.pop(port)
コード例 #7
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
    def lsp_add(self, port):
        if not isinstance(port, SwitchPort):
            raise Exception("wrong type")

        cmd = ['ovn-nbctl', 'lsp-add', self.name, port.name]
        run_command(cmd, check_exit_code=True)
        self._ports_list.append(port)

        self.lsp_set_addresses(port)
        self.lsp_set_type(port)
        self.lsp_set_options(port)
コード例 #8
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def _syn_dict(self):
     res = run_command(['ovn-nbctl', 'ls-list'], check_exit_code=True)
     lines = res.splitlines()
     for line in lines:
         ltemp = line.split()
         name = ltemp[1].strip('()')
         uuid = ltemp[0]
         s = Switch(name=name, uuid=uuid)
         self.ls_dict.setdefault(s.name, s)
     res = run_command(['ovn-nbctl', 'lr-list'], check_exit_code=True)
     lines = res.splitlines()
     for line in lines:
         ltemp = line.split()
         name = ltemp[1].strip('()')
         uuid = ltemp[0]
         s = Router(name=name, uuid=uuid)
         self.lr_dict.setdefault(s.name, s)
コード例 #9
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
    def dhcp_option_set_options(self, dhcp_option, server_id, server_mac, router, lease_time):

        cmd = ['ovn-nbctl', 'dhcp-options-set-options', dhcp_option,
               'server_id='+str(server_id),
               'server_mac='+server_mac,
               'router='+router,
               'lease_time='+str(lease_time)]
        re = run_command(cmd, check_exit_code=True)
        return re
コード例 #10
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def _syn_ports(self):
     cmd = ['ovn-nbctl', 'lsp-list', self.name]
     res = run_command(cmd, check_exit_code=True)
     lines = res.splitlines()
     for line in lines:
         ltemp = line.split()
         name = ltemp[1].strip('()')
         uuid = ltemp[0]
         s = SwitchPort(name=name, uuid=uuid)
         self._ports_list.append(s)
コード例 #11
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
    def ovn_nbctl_lsp_set_dhcpv4_options(port, dhcp):
        if isinstance(port, SwitchPort):
            tem_port = port
        elif isinstance(port, str):
            tem_port = SwitchPort(port)
        else:
            raise Exception("wrong type")

        if not isinstance(dhcp, DHCP):
            raise Exception("wrong type")

        cmd = ['ovn-nbctl', 'lsp-set-dhcpv4-options', tem_port.name, dhcp.uuid]
        re = run_command(cmd, check_exit_code=True)
        return re
コード例 #12
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def _create_DHCP_Options(self, cidr):
     cmd = ['ovn-nbctl', 'create', 'DHCP_Options', 'cidr='+str(cidr)]
     re = run_command(cmd, check_exit_code=True)
     self.uuid = re.strip('\n')
     return re
コード例 #13
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def lr_del(self, lr):
     if not isinstance(lr, RouterBase):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lr-del', lr.name]
     run_command(cmd, check_exit_code=True)
     self.lr_dict.pop(lr.name)
コード例 #14
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def ls_del(self, ls):
     cmd = ['ovn-nbctl', 'ls-del', ls.name]
     run_command(cmd, check_exit_code=True)
     self.ls_dict.pop(ls.name)
コード例 #15
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def ls_add(self, ls):
     if not isinstance(ls, SwitchBase):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'ls-add', ls.name]
     run_command(cmd, check_exit_code=True)
     self.ls_dict.setdefault(ls.name, ls)
コード例 #16
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def lsp_set_type(port):
     if not isinstance(port, SwitchPort):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lsp-set-type', port.name, port.type]
     if port.type is not None:
         run_command(cmd, check_exit_code=True)
コード例 #17
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def del_route(self, prefix=None):
     cmd = ['ovn-nbctl', 'lr-route-add', self.name]
     if prefix is not None:
         cmd.append(prefix)
     run_command(cmd, check_exit_code=True)
コード例 #18
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def add_route(self, prefix, nexthop):
     cmd = ['ovn-nbctl', 'lr-route-add', self.name, prefix, nexthop]
     run_command(cmd, check_exit_code=True)
コード例 #19
0
ファイル: ovn.py プロジェクト: MrCocoaCat/MyPython
 def del_port(self, port):
     if not isinstance(port, RoutePort):
         raise Exception("wrong type")
     cmd = ['ovn-nbctl', 'lrp-del', self.name, port.name]
     run_command(cmd, check_exit_code=True)
     self._ports_list.pop(port)