Exemple #1
0
 def iqn_gen(self):
     log.info('Generating iscsi InitiatorName')
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     iqn = UO.generate_initiator_iqn()
     if iqn is None:
         return [False, 'Generate initiator iqn error']
     else:
         UO.write_initiator_iqn(iqn)
         return [True, iqn]
 def iqn_gen(self):
     log.info('Generating iscsi InitiatorName')
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     iqn = UO.generate_initiator_iqn()
     if iqn is None:
         return [False, 'Generate initiator iqn error']
     else:
         UO.write_initiator_iqn(iqn)
         return [True, iqn]
Exemple #3
0
 def ip_flush(self, mac):
     log.info('Deleting all IP address on %s' % mac)
     dev = UO.get_name_by_mac(mac)
     if dev is None:
         log.info('Device %s is invalid' % mac)
         return [True, '']
     if not UO.flush_ip(dev):
         log.error('Flush IP for %s error' % dev)
         return [False, 'Flush IP for %s error' % dev]
     UO.remove_ip_config(dev)
     Config.flush_ip(mac)
     return [True, '']
 def cloud_disk_plug(self, iqn, ip, port):
     log.info('Pluging cloud disk on target %s, ip %s:%d' % (iqn, ip, port))
     if not UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     return [True, '']
 def ip_flush(self, mac):
     log.info('Deleting all IP address on %s' % mac)
     dev = UO.get_name_by_mac(mac)
     if dev is None:
         log.info('Device %s is invalid' % mac)
         return [True, '']
     if not UO.flush_ip(dev):
         log.error('Flush IP for %s error' % dev)
         return [False, 'Flush IP for %s error' % dev]
     UO.remove_ip_config(dev)
     Config.flush_ip(mac)
     return [True, '']
Exemple #6
0
 def cloud_disk_unplug(self, iqn, ip, port, last):
     log.info('Upluging cloud disk on target %s, ip %s:%d, last: %s' %
              (iqn, ip, port, last))
     if not UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     return [True, '']
 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 UO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if UO.check_node_existance(node):
         log.error('Node %s is duplicated' % node)
         return [False, 'Node %s is duplicated' % node]
     if mac is not None:
         dev = UO.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 UO.validate_ip(nh + '/32'):
         log.error('Next hop %s is invalid' % nh)
         return [False, 'Next hop %s is invalid' % nh]
     if not UO.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':
         UO.write_default_route_config(nh)
     Config.add_route(node, nh, mac)
     return [True, '']
Exemple #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 UO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if UO.check_node_existance(node):
         log.error('Node %s is duplicated' % node)
         return [False, 'Node %s is duplicated' % node]
     if mac is not None:
         dev = UO.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 UO.validate_ip(nh + '/32'):
         log.error('Next hop %s is invalid' % nh)
         return [False, 'Next hop %s is invalid' % nh]
     if not UO.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':
         UO.write_default_route_config(nh)
     Config.add_route(node, nh, mac)
     return [True, '']
 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 UO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if not UO.check_node_existance(node):
         log.error('Node %s not exist' % node)
         return [False, 'Node %s not exist' % node]
     if not UO.del_route(node):
         log.error('Delete route error')
         return [False, 'Delete route error']
     if node == '0.0.0.0/0':
         UO.remove_default_route_config()
     Config.del_route(node)
     return [True, '']
Exemple #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 UO.validate_node(node):
         log.error('Node %s is invalid' % node)
         return [False, 'Node %s is invalid' % node]
     if not UO.check_node_existance(node):
         log.error('Node %s not exist' % node)
         return [False, 'Node %s not exist' % node]
     if not UO.del_route(node):
         log.error('Delete route error')
         return [False, 'Delete route error']
     if node == '0.0.0.0/0':
         UO.remove_default_route_config()
     Config.del_route(node)
     return [True, '']
Exemple #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 UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not UO.check_iscsi_session_existance(iqn):
         if not UO.discover_iscsi_target(ip, port):
             return [False, 'Discover target %s:%d error' % (ip, port)]
         if not UO.login_iscsi_target(iqn, ip, port):
             return [False, 'Login target %s error' % iqn]
         return [True, '']
     else:
         if not UO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
         return [True, '']
Exemple #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 UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not UO.check_iscsi_session_existance(iqn):
         if not UO.discover_iscsi_target(ip, port):
             return [False, 'Discover target %s:%d error' % (ip, port)]
         if not UO.login_iscsi_target(iqn, ip, port):
             return [False, 'Login target %s error' % iqn]
         return [True, '']
     else:
         if not UO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
         return [True, '']
Exemple #13
0
 def ip_config(self, mac, ip):
     log.info('Setting %s IP address to %s' % (mac, ip))
     dev = UO.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 UO.validate_ip(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.disable_offload(dev):
         log.error('Disable offload for %s error' % dev)
         return [False, 'Disable offload for %s error' % dev]
     if not UO.config_ip(dev, ip):
         log.error('Config IP for %s error' % dev)
         return [False, 'Config IP for %s error' % dev]
     if not UO.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)
     UO.apply_config()
     return [True, '']
Exemple #14
0
 def ip_config(self, mac, ip):
     log.info('Setting %s IP address to %s' % (mac, ip))
     dev = UO.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 UO.validate_ip(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.disable_offload(dev):
         log.error('Disable offload for %s error' % dev)
         return [False, 'Disable offload for %s error' % dev]
     if not UO.config_ip(dev, ip):
         log.error('Config IP for %s error' % dev)
         return [False, 'Config IP for %s error' % dev]
     if not UO.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)
     UO.apply_config()
     return [True, '']
Exemple #15
0
 def cloud_disk_unplug(self, iqn, ip, port, last):
     log.info('Upluging cloud disk on target %s, ip %s:%d, last: %s' %
              (iqn, ip, port, last))
     if not UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not UO.check_iscsi_session_existance(iqn):
         log.info('Session %s not exist, do not need to logout' % iqn)
         return [True, '']
     if last is True:
         if not UO.logout_iscsi_target(iqn, ip, port):
             return [False, 'Logout Target %s error' % iqn]
     else:
         if not UO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
     return [True, '']
Exemple #16
0
 def cloud_disk_unplug(self, iqn, ip, port, last):
     log.info('Upluging cloud disk on target %s, ip %s:%d, last: %s' %
              (iqn, ip, port, last))
     if not UO.validate_iqn(iqn):
         log.error('Iqn %s is invalid' % iqn)
         return [False, 'Iqn %s is invalid' % iqn]
     if not UO.validate_ip_without_mask(ip):
         log.error('IP %s is invalid' % ip)
         return [False, 'IP %s is invalid' % ip]
     if not UO.validate_port(port):
         log.error('Port %d is invalid' % port)
         return [False, 'Port %d is invalid' % port]
     if not UO.check_iscsi_service_existance():
         return [False, 'Iscsi service not exist']
     if not UO.check_iscsi_session_existance(iqn):
         log.info('Session %s not exist, do not need to logout' % iqn)
         return [True, '']
     if last is True:
         if not UO.logout_iscsi_target(iqn, ip, port):
             return [False, 'Logout Target %s error' % iqn]
     else:
         if not UO.update_iscsi_target(iqn, ip, port):
             return [False, 'Update target %s error' % iqn]
     return [True, '']
Exemple #17
0
     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':
     from operations import SuseOperations
     from functions import SuseFunctions
     SuseOperations.apply_config()
     SuseOperations.init_dns_config()
     server.register_instance(SuseFunctions())
 elif dist == 'arch':
     from operations import ArchOperations
     from functions import ArchFunctions
     ArchOperations.apply_config()
     ArchOperations.init_dns_config()
     server.register_instance(ArchFunctions())
 else:
Exemple #18
0
     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':
     from operations import SuseOperations
     from functions import SuseFunctions
     SuseOperations.apply_config()
     SuseOperations.init_dns_config()
     server.register_instance(SuseFunctions())
 elif dist == 'arch':
     from operations import ArchOperations
     from functions import ArchFunctions
     ArchOperations.apply_config()
     ArchOperations.init_dns_config()
     server.register_instance(ArchFunctions())
 else:
Exemple #19
0
 def block_device_unmounted(self, dev_name):
     return UO.check_block_device_unmounted(dev_name)
Exemple #20
0
 def block_device_unmounted(self, dev_name):
     return UO.check_block_device_unmounted(dev_name)