예제 #1
0
 def iqn_gen(self):
     log.info('Generating iscsi InitiatorName')
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     iqn = CO.generate_initiator_iqn()
     if iqn is None:
         return [False, 'Generate initiator iqn error']
     else:
         CO.write_initiator_iqn(iqn)
         return [True, iqn]
예제 #2
0
 def iqn_gen(self):
     log.info('Generating iscsi InitiatorName')
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     iqn = CO.generate_initiator_iqn()
     if iqn is None:
         return [False, 'Generate initiator iqn error']
     else:
         CO.write_initiator_iqn(iqn)
         return [True, iqn]
예제 #3
0
 def cloud_disk_unplug(self, iqn, ip, port, lun_name, last):
     log.info('Upluging cloud disk on target %s, ip %s:%d, lun_name:%s,\
              last: %s' % (iqn, ip, port, lun_name, last))
     if not CO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not CO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not CO.check_iscsi_session_existance(iqn):
         log.info('Session %s not exist, do not need to logout' % iqn)
         return [True, '']
     dev_name = CO.get_iscsi_dev_name(lun_name)
     if dev_name is None:
         return [False, 'Get dev name error']
     else:
         if CO.check_dev_mounted(dev_name):
             return [
                 False,
                 'Unplug failed, The device %s already mounted' % dev_name
             ]
     if last is True:
         if not CO.logout_iscsi_target(iqn, ip, port):
             return [False, 'Logout Target %s error' % iqn]
     else:
         if not CO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
     return [True, '']
예제 #4
0
 def cloud_disk_unplug(self, iqn, ip, port, lun_name, last):
     log.info('Upluging cloud disk on target %s, ip %s:%d, lun_name:%s,\
              last: %s' % (iqn, ip, port, lun_name, last))
     if not CO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not CO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not CO.check_iscsi_session_existance(iqn):
         log.info('Session %s not exist, do not need to logout' % iqn)
         return [True, '']
     dev_name = CO.get_iscsi_dev_name(lun_name)
     if dev_name is None:
         return [False, 'Get dev name error']
     else:
         if CO.check_dev_mounted(dev_name):
             return [False, 'Unplug failed, The device %s already mounted'
                     % dev_name]
     if last is True:
         if not CO.logout_iscsi_target(iqn, ip, port):
             return [False, 'Logout Target %s error' % iqn]
     else:
         if not CO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
     return [True, '']
예제 #5
0
 def ip_flush(self, mac):
     log.info('Deleting all IP address on %s' % mac)
     dev = CO.get_name_by_mac(mac)
     if dev is None:
         log.info('Device %s is invalid' % mac)
         return [True, '']
     if not CO.flush_ip(dev):
         log.error('Flush IP for %s error' % dev)
         return [False, 'Flush IP for %s error' % dev]
     CO.remove_ip_config(dev)
     Config.flush_ip(mac)
     return [True, '']
예제 #6
0
 def ip_flush(self, mac):
     log.info('Deleting all IP address on %s' % mac)
     dev = CO.get_name_by_mac(mac)
     if dev is None:
         log.info('Device %s is invalid' % mac)
         return [True, '']
     if not CO.flush_ip(dev):
         log.error('Flush IP for %s error' % dev)
         return [False, 'Flush IP for %s error' % dev]
     CO.remove_ip_config(dev)
     Config.flush_ip(mac)
     return [True, '']
예제 #7
0
 def route_add(self, node, nh, mac):
     log.info('Adding route for %s' % node)
     nh = nh if nh else None
     mac = mac if mac else None
     if nh is None and mac is None:
         log.error('No next hop or dev')
         return [False, 'No next hop or dev']
     if not node:
         log.error('Node is empty')
         return [False, 'Node is empty']
     if node == 'default':
         node = '0.0.0.0/0'
     if not CO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if CO.check_node_existance(node):
         log.error('Node %s is duplicated' % node)
         return [False, 'Node %s is duplicated' % node]
     if mac is not None:
         dev = CO.get_name_by_mac(mac)
         if dev is None:
             log.error('Device %s is invalid' % mac)
             return [False, 'Device %s is invalid' % mac]
     else:
         dev = None
     if nh is not None and not CO.validate_ip(nh + '/32'):
         log.error('Next hop %s is invalid' % nh)
         return [False, 'Next hop %s is invalid' % nh]
     if not CO.add_route(node, nh, mac):
         log.error('Add route for %s error' % node)
         return [False, 'Add route for %s error' % node]
     if node == '0.0.0.0/0':
         CO.write_default_route_config(nh)
     Config.add_route(node, nh, mac)
     return [True, '']
예제 #8
0
 def route_add(self, node, nh, mac):
     log.info('Adding route for %s' % node)
     nh = nh if nh else None
     mac = mac if mac else None
     if nh is None and mac is None:
         log.error('No next hop or dev')
         return [False, 'No next hop or dev']
     if not node:
         log.error('Node is empty')
         return [False, 'Node is empty']
     if node == 'default':
         node = '0.0.0.0/0'
     if not CO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if CO.check_node_existance(node):
         log.error('Node %s is duplicated' % node)
         return [False, 'Node %s is duplicated' % node]
     if mac is not None:
         dev = CO.get_name_by_mac(mac)
         if dev is None:
             log.error('Device %s is invalid' % mac)
             return [False, 'Device %s is invalid' % mac]
     else:
         dev = None
     if nh is not None and not CO.validate_ip(nh + '/32'):
         log.error('Next hop %s is invalid' % nh)
         return [False, 'Next hop %s is invalid' % nh]
     if not CO.add_route(node, nh, mac):
         log.error('Add route for %s error' % node)
         return [False, 'Add route for %s error' % node]
     if node == '0.0.0.0/0':
         CO.write_default_route_config(nh)
     Config.add_route(node, nh, mac)
     return [True, '']
예제 #9
0
 def route_del(self, node):
     log.info('Deleting route for %s' % node)
     if not node:
         log.error('Node is empty')
         return [False, 'Node is empty']
     if node == 'default':
         node = '0.0.0.0/0'
     if not CO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if not CO.check_node_existance(node):
         log.error('Node %s not exist' % node)
         return [False, 'Node %s not exist' % node]
     if not CO.del_route(node):
         log.error('Delete route error')
         return [False, 'Delete route error']
     if node == '0.0.0.0/0':
         CO.remove_default_route_config()
     Config.del_route(node)
     return [True, '']
예제 #10
0
 def route_del(self, node):
     log.info('Deleting route for %s' % node)
     if not node:
         log.error('Node is empty')
         return [False, 'Node is empty']
     if node == 'default':
         node = '0.0.0.0/0'
     if not CO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if not CO.check_node_existance(node):
         log.error('Node %s not exist' % node)
         return [False, 'Node %s not exist' % node]
     if not CO.del_route(node):
         log.error('Delete route error')
         return [False, 'Delete route error']
     if node == '0.0.0.0/0':
         CO.remove_default_route_config()
     Config.del_route(node)
     return [True, '']
예제 #11
0
 def cloud_disk_plug(self, iqn, ip, port):
     log.info('Pluging cloud disk on target %s, ip %s:%d' % (iqn, ip, port))
     if not CO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not CO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not CO.check_iscsi_session_existance(iqn):
         if not CO.discover_iscsi_target(ip, port):
             return [False, 'Discover target %s:%d error' % (ip, port)]
         if not CO.login_iscsi_target(iqn, ip, port):
             return [False, 'Login target %s error' % iqn]
         return [True, '']
     else:
         if not CO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
         return [True, '']
예제 #12
0
 def cloud_disk_plug(self, iqn, ip, port):
     log.info('Pluging cloud disk on target %s, ip %s:%d' %
              (iqn, ip, port))
     if not CO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not CO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not CO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not CO.check_iscsi_session_existance(iqn):
         if not CO.discover_iscsi_target(ip, port):
             return [False, 'Discover target %s:%d error' % (ip, port)]
         if not CO.login_iscsi_target(iqn, ip, port):
             return [False, 'Login target %s error' % iqn]
         return [True, '']
     else:
         if not CO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
         return [True, '']
예제 #13
0
 def ip_config(self, mac, ip):
     log.info('Setting %s IP address to %s' % (mac, ip))
     dev = CO.get_name_by_mac(mac)
     if dev is None:
         log.error('Device %s is invalid' % mac)
         return [False, 'Device %s is invalid' % mac]
     if not CO.validate_ip(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.disable_offload(dev):
         log.error('Disable offload for %s error' % dev)
         return [False, 'Disable offload for %s error' % dev]
     if not CO.config_ip(dev, ip):
         log.error('Config IP for %s error' % dev)
         return [False, 'Config IP for %s error' % dev]
     if not CO.write_ip_config(dev, ip):
         log.error('Write IP config for %s error' % dev)
         return [True, 'Write IP config for %s error' % dev]
     Config.config_ip(mac, ip)
     CO.apply_config()
     return [True, '']
예제 #14
0
 def ip_config(self, mac, ip):
     log.info('Setting %s IP address to %s' % (mac, ip))
     dev = CO.get_name_by_mac(mac)
     if dev is None:
         log.error('Device %s is invalid' % mac)
         return [False, 'Device %s is invalid' % mac]
     if not CO.validate_ip(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not CO.disable_offload(dev):
         log.error('Disable offload for %s error' % dev)
         return [False, 'Disable offload for %s error' % dev]
     if not CO.config_ip(dev, ip):
         log.error('Config IP for %s error' % dev)
         return [False, 'Config IP for %s error' % dev]
     if not CO.write_ip_config(dev, ip):
         log.error('Write IP config for %s error' % dev)
         return [True, 'Write IP config for %s error' % dev]
     Config.config_ip(mac, ip)
     CO.apply_config()
     return [True, '']
예제 #15
0
    signal.signal(signal.SIGTERM, sigterm_handler)

    if os.path.exists('/etc/arch-release'):
        dist = 'arch'

    if dist in ['centos', 'redhat']:
        try:
            from lb_operations import LBCentOSOperations
            from lb_functions import LBCentOSFunctions
            LBCentOSOperations.apply_config()
            server.register_instance(LBCentOSFunctions())
            dist = 'centos-lb'
        except:
            from operations import CentOSOperations
            from functions import CentOSFunctions
            CentOSOperations.apply_config()
            CentOSOperations.init_dns_config()
            server.register_instance(CentOSFunctions())
    elif dist == 'debian':
        from operations import DebianOperations
        from functions import DebianFunctions
        DebianOperations.apply_config()
        DebianOperations.init_dns_config()
        server.register_instance(DebianFunctions())
    elif dist == 'ubuntu':
        from operations import UbuntuOperations
        from functions import UbuntuFunctions
        UbuntuOperations.apply_config()
        UbuntuOperations.init_dns_config()
        server.register_instance(UbuntuFunctions())
    elif dist == 'suse':
예제 #16
0
 def block_device_unmounted(self, dev_name):
     return CO.check_block_device_unmounted(dev_name)
예제 #17
0
 signal.signal(signal.SIGTERM, sigterm_handler)
 
 if os.path.exists('/etc/arch-release'):
     dist = 'arch'
 
 if dist in ['centos', 'redhat']:
     try:
         from lb_operations import LBCentOSOperations
         from lb_functions import LBCentOSFunctions
         LBCentOSOperations.apply_config()
         server.register_instance(LBCentOSFunctions())
         dist = 'centos-lb'
     except:
         from operations import CentOSOperations
         from functions import CentOSFunctions
         CentOSOperations.apply_config()
         CentOSOperations.init_dns_config()
         server.register_instance(CentOSFunctions())
 elif dist == 'debian':
     from operations import DebianOperations
     from functions import DebianFunctions
     DebianOperations.apply_config()
     DebianOperations.init_dns_config()
     server.register_instance(DebianFunctions())
 elif dist == 'ubuntu':
     from operations import UbuntuOperations
     from functions import UbuntuFunctions
     UbuntuOperations.apply_config()
     UbuntuOperations.init_dns_config()
     server.register_instance(UbuntuFunctions())
 elif dist == 'suse':
예제 #18
0
 def block_device_unmounted(self, dev_name):
     return CO.check_block_device_unmounted(dev_name)