コード例 #1
0
ファイル: obligate.py プロジェクト: roaet/obligate
 def migrate_interfaces(self):
     env = 'ordpreprod'
     creds = get_connection_creds(env)
     nova = query.Nova(creds['nova_url'], creds['nova_username'],
                       creds['nova_password'])
     melanged = query.Melange(creds['melange_url'], creds['melange_username'],
                             creds['melange_password'])
     # grab all instances from nova
     instances = nova.get_instances_hashed_by_id()
     # grab all interfaces from melange
     interfaces_good = melanged.get_interfaces_hashed_by_device_id()
     interfaces_all = self.melange_session.query(melange.Interfaces).all()
     no_network_count = 0
     good_device_ids = []
     for k, v in interfaces_good.iteritems():
         if k not in instances:
             # this is not a garbage interface
             # print 'interface device_id |%s| found in nova!!' % k
             # self.log.critical("NVP_TEMP_KEY needs to be updated.")
             good_device_ids.append(k)
     for interface in interfaces_all:
         if interface.device_id in good_device_ids:
             init_id(self.json_data, "interfaces", interface.id)
             if interface.id not in self.interface_network:
                 set_reason(self.json_data, "interfaces",
                            interface.id, "no network")
                 no_network_count += 1
                 continue
             network_id = self.interface_network[interface.id]
             self.interface_tenant[interface.id] = interface.tenant_id
             q_port = quarkmodels.Port(id=interface.id,
                                       device_id=interface.device_id,
                                       tenant_id=interface.tenant_id,
                                       created_at=interface.created_at,
                                       backend_key=
                                       interface.vif_id_on_device,
                                       network_id=network_id)
             lswitch_id = str(uuid4())
             q_nvp_switch = optdriver.LSwitch(id=lswitch_id,
                                              nvp_id=network_id,
                                              network_id=network_id,
                                              display_name=network_id)
             port_id = interface.vif_id_on_device
             if not port_id:
                 port_id = "NVP_TEMP_KEY"
             q_nvp_port = optdriver.LSwitchPort(port_id=port_id,
                                                switch_id=lswitch_id)
             self.port_cache[interface.id] = q_port
             self.add_to_session(q_port, "interfaces", q_port.id)
             self.add_to_session(q_nvp_switch, "switch",
                                 q_nvp_switch.id)
             self.add_to_session(q_nvp_port, "nvp_port", q_nvp_port.id)
     self.log.info("Found {0} interfaces without a network."
                   .format(str(no_network_count)))
コード例 #2
0
ファイル: play.py プロジェクト: tr3buchet/nvpanacea
 def __init__(self, env):
     creds = utils.get_connection_creds(env)
     self.nvp = querylib.NVP(creds['nvp_url'], creds['nvp_username'],
                             creds['nvp_password'])
     self.nova = querylib.Nova(creds['nova_url'], creds['nova_username'],
                               creds['nova_password'])
     self.melange = querylib.Melange(creds['melange_url'],
                                     creds['melange_username'],
                                     creds['melange_password'])
     self.neutron = querylib.Neutron(creds['neutron_url'],
                                     creds['neutron_username'],
                                     creds['neutron_password'])
コード例 #3
0
ファイル: nvpanacea.py プロジェクト: tr3buchet/nvpanacea
def main():
    desc = 'view and modify ports using nvp/melange/nova'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('-l', '--list', action=_ListAction,
                        dest='listenvs',
                        help='list all configured environments')
    parser.add_argument('--loglevel', action='store',
                        help='set stdout log level: DEBUG, INFO, WARN, '
                             'ACTION, OUTPUT, ERROR..',
                        default='OUTPUT')
    parser.add_argument('-e', '--environment', action='store',
                        help='Environment to run against, for options use -l')
    parser.add_argument('-a', '--action', action='store',
                        help='fix or noop',
                        default='fixnoop')
    parser.add_argument('-t', '--type', action='store',
                        help='orphan_ports, repair_queues, add_vmids, '
                        'orphan_queues, orphan_interfaces, migrate_quark, '
                        'kill_cell_queues, delete_queue_list')
    parser.add_argument('-c', '--cell', action='store',
                        help='required by kill_cell_queues')
    args = parser.parse_args()

    ff = logging.Formatter('%(asctime)s|%(name)s|'
                           '%(levelname)s -> %(message)s')
    logger = logging.getLogger()
    # NOTE(tr3buchet): action log to file
    ah = logging.FileHandler(utils.get_log_name('~/nvpanacea_logs', 'action'))
    ah.setLevel(logging.ACTION)
    ah.setFormatter(ff)
    logger.addHandler(ah)

    # NOTE(tr3buchet): info log to file
    ih = logging.FileHandler(utils.get_log_name('~/nvpanacea_logs', 'info'))
    ih.setLevel(logging.INFO)
    ih.setFormatter(ff)
    logger.addHandler(ih)

    # NOTE(tr3buchet): standard out
    of = logging.Formatter('%(message)s')
    oh = logging.StreamHandler(sys.stdout)
    oh.setLevel(getattr(logging, args.loglevel))
    oh.setFormatter(of)
    logger.addHandler(oh)

    if args.type == 'kill_cell_queues' and args.cell is None:
        parser.print_help()
        utils.raiselog('ERROR: cell is required by kill_cell_queues:')

    hk_machine = {
        'orphan_ports': hunter_killer.OrphanPorts,
        #'repair_queues': hunter_killer.RepairQueues,
        #'no_vmids': hunter_killer.NoVMIDPorts,
        'orphan_queues': hunter_killer.OrphanQueues,
        'kill_cell_queues': functools.partial(hunter_killer.KillCellQueues,
                                              args.cell),
        'delete_queue_list': functools.partial(hunter_killer.DeleteQueueList,
                                               sys.stdin),
        'vif_id_on_device': hunter_killer.VifIDOnDevice,
        'remove_queue_ref': hunter_killer.RemoveQueueRef,
        'sg_ports': hunter_killer.SGPorts,
        'ip_info': hunter_killer.IPInfo,
    }

    if args.type not in hk_machine:
        utils.raiselog('type not supported, choose in %s' % hk_machine.keys())

    creds = utils.get_connection_creds(args.environment)
    LOG.output('iz in yur controller iteratin yur business (%s)' % args.action)
#    sys.stdout.flush()
    hk = hk_machine[args.type](action=args.action, **creds)
    hk.execute()