Пример #1
0
def train():

    env = Environment()
    player = Player()

    for episode in range(2):
        env.start()

        while True:
            actions = player.act(env.state)
            reverd = env.apply(actions)
            player.learn(reverd)
            if env.done:
                break
    return
Пример #2
0
 def __init__(self, size=0, mountpoint=False, logger=False, environ=False):
     """
     """
     #####
     # Version/timestamp is
     # <YYYY><MM><DD>.<HH><MM><SS>.<microseconds>
     # in UTC time
     self.module_version = '20160224.032043.009191'
     if not logger:
         self.logger = CyLogger()
     else:
         self.logger = logger
     if not environ:
         self.environ = Environment()
     else:
         self.environ = environ
     self.chkApp = CheckApplicable(self.environ, self.logger)
Пример #3
0
def deploy_bcf(config, fuel_cluster_id):
    # Deploy setup node
    Helper.safe_print("Start to prepare setup node\n")
    env = Environment(config, fuel_cluster_id)
    Helper.common_setup_node_preparation(env)

    # Generate detailed node information
    Helper.safe_print("Start to setup Big Cloud Fabric\n")
    nodes_config = None
    if 'nodes' in config:
        nodes_yaml_config = config['nodes']
    node_dic = Helper.load_nodes(nodes_yaml_config, env)

    # Generate scripts for each node
    for hostname, node in node_dic.iteritems():
        if node.os == const.CENTOS:
            Helper.generate_scripts_for_centos(node)
        elif node.os == const.UBUNTU:
            Helper.generate_scripts_for_ubuntu(node)
        with open(const.LOG_FILE, "a") as log_file:
            log_file.write(str(node))
        if node.skip:
            Helper.safe_print("skip node %(hostname)s due to %(error)s\n" % {
                'hostname': hostname,
                'error': node.error
            })
            continue
        node_q.put(node)

    # Use multiple threads to setup nodes
    for i in range(const.MAX_WORKERS):
        t = threading.Thread(target=worker_setup_node)
        t.daemon = True
        t.start()
    node_q.join()
    Helper.safe_print(
        "Big Cloud Fabric deployment finished! Check %(log)s on each node for details.\n"
        % {'log': const.LOG_FILE})
Пример #4
0
    def __init__(self, conf, parent=None):
        """
        Initialization method...

        @author: Roy Nielsen
        """
        super(ConfigureRepos, self).__init__(parent)

        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        #####
        # initialization of class variables.
        self.conf = conf
        self.environ = Environment()
        self.conf.loggerSelf()
        self.logger = self.conf.getLogger()
        #self.logger = self.conf.get_logger()
        self.logger.log(lp.DEBUG, str(self.logger))
        self.runWith = RunWith(self.logger)
        self.libc = getLibc(self.logger)
        self.chkApp = CheckApplicable(self.environ, self.logger)
        macOsWhiteListApplicable = {
            'type': 'white',
            'os': {
                'Mac OS X': ['10.0.0', 'r', '20.12.10']
            }
        }

        #####
        # Handle button box
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Cancel).clicked.connect(self.close)
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Ok).clicked.connect(self.okDone)

        #####
        # Handle other buttons
        self.ui.downloadReposButton.clicked.connect(self.downloadRepos)
        self.ui.prepareIsoButton.clicked.connect(self.prepareIso)
        self.ui.gitResetHardButton.clicked.connect(self.resetRepos)
        self.ui.gitPullButton.clicked.connect(self.updateRepos)

        if self.chkApp.isApplicable(macOsWhiteListApplicable):
            self.ui.prepareIsoButton.clicked.connect(self.prepareIso)
        else:
            self.ui.prepareIsoButton.hide()
            self.ui.macosCheckBox.hide()

        #####
        # default boxcutter repo path
        self.reposRoot = self.conf.getRepoRoot()

        #####
        # Future features
        self.ui.winCheckBox.hide()
        self.ui.label_2.hide()
        self.ui.leReposPath.hide()
        self.ui.proxyButton.hide()

        #####
        # Future features
        self.ui.winCheckBox.hide()
        self.ui.label_2.hide()
        self.ui.leReposPath.hide()
        self.ui.proxyButton.hide()

        self.git = "/usr/bin/git"

        #####
        # repos
        self.repos2process = []

        self.getSelected()
Пример #5
0
def deploy_bcf(config, mode, fuel_cluster_id, rhosp, tag, cleanup, verify,
               verify_only, skip_ivs_version_check, certificate_dir,
               certificate_only, generate_csr, support, upgrade_dir,
               offline_dir, sriov):
    # Deploy setup node
    safe_print("Start to prepare setup node\n")
    env = Environment(config, mode, fuel_cluster_id, rhosp, tag, cleanup,
                      skip_ivs_version_check, certificate_dir, upgrade_dir,
                      offline_dir, sriov)
    Helper.common_setup_node_preparation(env)
    controller_nodes = []

    # Generate detailed node information
    safe_print("Start to setup Big Cloud Fabric\n")
    nodes_yaml_config = config['nodes'] if 'nodes' in config else None
    node_dic = Helper.load_nodes(nodes_yaml_config, env)

    if upgrade_dir:
        return upgrade_bcf(node_dic)

    if sriov:
        return setup_sriov(node_dic)

    if generate_csr:
        safe_print("Start to generate csr for virtual switches.\n")
        # create ~/csr and ~/key directory
        Helper.run_command_on_local("mkdir -p %s" % const.CSR_DIR)
        Helper.run_command_on_local("mkdir -p %s" % const.KEY_DIR)
        for hostname, node in node_dic.iteritems():
            if node.skip:
                safe_print("skip node %(fqdn)s due to %(error)s\n" % {
                    'fqdn': node.fqdn,
                    'error': node.error
                })
                continue

            if node.tag != node.env_tag:
                safe_print("skip node %(fqdn)s due to mismatched tag\n" %
                           {'fqdn': node.fqdn})
                continue
            if node.deploy_mode == const.T6 and node.role == const.ROLE_COMPUTE:
                Helper.generate_csr(node)
        safe_print("Finish generating csr for virtual switches.\n")
        return

    # copy neutron config from neutron server to setup node
    for hostname, node in node_dic.iteritems():
        if node.role == const.ROLE_NEUTRON_SERVER:
            controller_nodes.append(node)
    Helper.copy_neutron_config_from_controllers(controller_nodes)

    # check if vlan is the tenant network type for fuel environment
    if not Helper.check_if_vlan_is_used(controller_nodes):
        safe_print("tenant network type is not vlan. Stop deploying.\n")
        return

    # prepare keystone client from /etc/neutron/api-paste.ini
    #Helper.prepare_keystone_client(controller_nodes)

    # Generate scripts for each node
    for hostname, node in node_dic.iteritems():
        if support:
            support_node_q.put(node)

        if node.skip:
            safe_print("skip node %(fqdn)s due to %(error)s\n" % {
                'fqdn': node.fqdn,
                'error': node.error
            })
            continue

        if node.tag != node.env_tag:
            safe_print("skip node %(fqdn)s due to mismatched tag\n" %
                       {'fqdn': node.fqdn})
            continue

        if node.os == const.CENTOS:
            Helper.generate_scripts_for_centos(node)
        elif node.os == const.UBUNTU:
            Helper.generate_scripts_for_ubuntu(node)
        elif node.os == const.REDHAT:
            Helper.generate_scripts_for_redhat(node)

        if node.role == const.ROLE_NEUTRON_SERVER:
            controller_node_q.put(node)
        else:
            # python doesn't have deep copy for Queue, hence add to all
            node_q.put(node)
            verify_node_q.put(node)
            if node.deploy_mode == const.T6 and node.role == const.ROLE_COMPUTE:
                certify_node_q.put(node)

        if node.rhosp:
            Helper.chmod_node(node)

    with open(const.LOG_FILE, "a") as log_file:
        version = Helper.run_command_on_local("pip show bosi")
        log_file.write(str(version))
        for hostname, node in node_dic.iteritems():
            log_file.write(str(node))

    if support:
        safe_print("Start to collect logs.\n")
        # copy installer logs to ~/support
        Helper.run_command_on_local("mkdir -p %s" % const.SUPPORT_DIR)
        Helper.run_command_on_local("cp -r %(src)s %(dst)s" % {
            "src": const.LOG_FILE,
            "dst": const.SUPPORT_DIR
        })
        Helper.run_command_on_local(
            "cp -r %(setup_node_dir)s/%(generated_script_dir)s %(dst)s" % {
                "setup_node_dir": env.setup_node_dir,
                "generated_script_dir": const.GENERATED_SCRIPT_DIR,
                "dst": const.SUPPORT_DIR
            })

        for i in range(const.MAX_WORKERS):
            t = threading.Thread(target=support_node_setup,
                                 args=(support_node_q, ))
            t.daemon = True
            t.start()
        support_node_q.join()
        # compress ~/support
        Helper.run_command_on_local("cd /tmp; tar -czf support.tar.gz support")
        safe_print(
            "Finish collecting logs. logs are at /tmp/support.tar.gz.\n")
        return

    # in case of verify_only or certificate_only, do not deploy
    if (not verify_only) and (not certificate_only):
        # Use single thread to setup controller nodes
        t = threading.Thread(target=worker_setup_node,
                             args=(controller_node_q, ))
        t.daemon = True
        t.start()
        controller_node_q.join()

        # Use multiple threads to setup compute nodes
        for i in range(const.MAX_WORKERS):
            t = threading.Thread(target=worker_setup_node, args=(node_q, ))
            t.daemon = True
            t.start()
        node_q.join()

        sorted_time_dict = OrderedDict(
            sorted(time_dict.items(), key=lambda x: x[1]))
        for fqdn, h_time in sorted_time_dict.items():
            safe_print("node: %(fqdn)s, time: %(time).2f\n" % {
                'fqdn': fqdn,
                'time': h_time
            })

        safe_print("Big Cloud Fabric deployment finished! "
                   "Check %(log)s on each node for details.\n" %
                   {'log': const.LOG_FILE})

    if certificate_dir or certificate_only:
        # certify each node
        safe_print("Start to certify virtual switches.\n")
        for i in range(const.MAX_WORKERS):
            t = threading.Thread(target=certify_node_setup,
                                 args=(certify_node_q, ))
            t.daemon = True
            t.start()
        certify_node_q.join()
        safe_print('Certifying virtual switches done.\n')

    if verify or verify_only:
        # verify each node and post results
        safe_print("Verifying deployment for all compute nodes.\n")
        for i in range(const.MAX_WORKERS):
            t = threading.Thread(target=verify_node_setup,
                                 args=(verify_node_q, ))
            t.daemon = True
            t.start()
        verify_node_q.join()
        # print status
        # success nodes
        safe_print('Deployed successfully to: \n')
        for node_element in node_pass:
            safe_print(node_element + '\n')
        # failed nodes
        safe_print('Deployment to following failed: \n')
        for node_element in node_fail:
            safe_print(
                str(node_element) + ' : ' + str(node_fail[node_element]) +
                '\n')
Пример #6
0
from lib.agent import Agent
from lib.environment import Environment

num_actions = 12
agent = Agent(num_actions)
environment = Environment()

done = 0
environment.start()

while done != 1:
    action = agent.choose_action()
    environment.sendAction(action)
    reward, done = environment.getState()

environment.exit()
    def __init__(self, conf, parent=None):
        """
        Initialization method...

        @author: Roy Nielsen
        """
        super(VirtualMachineBuilder, self).__init__(parent)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        #####
        # initialization of class variables.
        self.conf = conf
        self.conf.loggerSelf()
        self.logger = self.conf.getLogger()
        self.environ = Environment()
        #self.logger = self.conf.get_logger()
        self.logger.log(lp.DEBUG, str(self.logger))
        self.runWith = RunWith(self.logger)
        self.libc = getLibc(self.logger)

        #####
        # Set label states
        self.ui.packerLabel.setText(
            "( <a href='https://www.packer.io'>https://www.packer.io</a> - Download and install packer separately )"
        )
        self.ui.boxcutterLabel.setText(
            "( <a href='https://github.com/boxcutter'>https://github.com/boxcutter</a> - Clone repos separately )"
        )

        #####
        # Handle button box
        #
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Close).clicked.connect(
                self.closeApplication)
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Ok).clicked.connect(self.processVm)

        #####
        # Rename Save button
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Save).setText("Configure Repos")
        btn = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Save)
        btn.clicked.connect(self.configureRepos)

        #####
        # Rename Apply button
        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Apply).setText("Install packer")
        btnTwo = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Apply)
        btnTwo.clicked.connect(self.installPacker)
        btnTwo.hide()

        self.chkApp = CheckApplicable(self.environ, self.logger)
        self.macOsBlackListApplicable = {
            'type': 'black',
            'os': {
                'Mac OS X': ['10.0.0', 'r', '20.12.10']
            }
        }
        self.linuxWhitelistApplicable = {'type': 'white', 'family': 'linux'}
        self.freebsdWhitelistApplicable = {
            'type': 'white',
            'family': 'freebsd'
        }
        self.macosWhitelistApplicable = {'type': 'white', 'family': 'darwin'}
        #openbsdWhitelistApplicable = {}
        #windowsWhitelistApplicable = {}

        #####
        # Set up the configure dialog
        self.configRepos = ConfigureRepos(self.conf)
        self.configRepos.setWindowTitle("Configure Repos")

        #####
        # Connect the configure 'done' signal to the refreshFamilyComboBox slot
        self.configRepos.doneConfigure.connect(self.refreshFamilyComboBox)

        #####
        # Signal/slot to deal with osFamily combo box change
        self.ui.osFamily.currentIndexChanged.connect(self.osFamilySelected)

        self.refreshFamilyComboBox()
        self.osFamilySelected(0)

        self.logger.log(lp.DEBUG, "Done with VirtualMachineBuilder init...")
Пример #8
0
    def __init__(self, **kwargs):
        """
        Variables that can be passed in:
        logger
        userName
        userShell
        userComment
        userUid
        userPriGid
        userHomeDir
        """
        if 'logDispatcher' not in kwargs:
            raise ValueError(
                "Variable 'logDispatcher' a required parameter for " +
                str(self.__class__.__name__))
        else:
            self.logger = kwargs.get('logDispatcher')

        if 'userName' not in kwargs:
            self.userName = ""
        else:
            self.userName = kwargs.get('userName')

        if 'userShell' not in kwargs:
            self.userShell = "/bin/bash"
        else:
            userShell = kwargs.get('userShell')

        if 'userComment' not in kwargs:
            self.userComment = ""
        else:
            self.userComment = kwargs.get('userComment')

        if 'userUid' not in kwargs:
            self.userUid = 10000
        else:
            self.userUid = kwargs.get('userUid')

        if 'userPriGid' not in kwargs:
            self.userPriGid = 20
        else:
            self.userPriGid = kwargs.get('userPriGid')

        if 'userHomeDir' not in kwargs:
            self.userHomeDir = ""
        else:
            self.userHomeDir = kwargs.get('userHomeDir')

        self.module_version = '20160225.125554.540679'

        #####
        # Acqure the environment
        self.environ = Environment()

        #####
        # THIS IS A LIBRARY, SO LOGS SHOULD BE INITIALIZED ELSEWHERE...
        # self.logger.initializeLogs()
        self.logger.log(lp.INFO, "Logger: " + str(self.logger))

        #####
        # Initialize the RunWith helper for executing shelled out commands.
        self.runWith = RunWith(self.logger)
Пример #9
0
 def new_game(self):
     self.game_count += 1
     self.balls = self.new_balls()
     self.env = Environment(self.balls)
Пример #10
0
 def build_environment(self):
     """ Create the environment """
     self.environment = Environment(self.env, show_env=self.show_env)