Exemplo n.º 1
0
    def render(self, cloud):

        self.cloud = cloud
        if app.current_controller is None:
            app.current_controller = petname.Name()

        if app.current_model is None:
            app.current_model = 'default'

        if self.cloud != 'localhost':
            if not common.try_get_creds(self.cloud):
                utils.warning("You attempted to do an install against a cloud "
                              "that requires credentials that could not be "
                              "found.  If you wish to supply those "
                              "credentials please run "
                              "`juju add-credential {}`.".format(self.cloud))
                sys.exit(1)

        if self.cloud == 'localhost':
            if not utils.check_bridge_exists():
                return controllers.use('lxdsetup').render()

            app.log.debug("Found an IPv4 address, "
                          "assuming LXD is configured.")

        utils.info("Bootstrapping Juju controller")
        juju.bootstrap(controller=app.current_controller,
                       cloud=self.cloud,
                       credential=common.try_get_creds(self.cloud))
        self.do_post_bootstrap()
        self.finish()
Exemplo n.º 2
0
def run():

    env_name = 'MountainCar-v0'
    run_name = petname.Name()
    print "Starting environment: {0}, run: {1}".format(env_name, run_name)
    agent_type = 'ContinuousSarsaLambda'
    env = gym.make(env_name)
    env.monitor.start('runs/{0}/{1}/{2}'.format(env_name, agent_type,
                                                run_name))
    if agent_type == 'SarsaLambda':
        sarsa_agent = SarsaLambdaAgent(env)
    elif agent_type == 'Sarsa':
        sarsa_agent = SarsaAgent(env)
    elif agent_type == 'QLearner':
        sarsa_agent = QLearner(env)
    elif agent_type == 'ContinuousSarsaLambda':
        sarsa_agent = ContinuousSarsaLambdaAgent(env)
    else:
        raise NotImplementedError

    fname = 'runs/{0}/{1}/{2}/q_values'.format(env_name, agent_type, run_name)
    if not os.path.exists(fname):
        os.makedirs(fname)
    save_every = 10
    np.save('{0}/init'.format(fname), sarsa_agent.q)

    run_episodes(sarsa_agent,
                 env,
                 episodes=3000,
                 max_steps=env.spec.timestep_limit,
                 save_every=save_every,
                 fname=fname)
Exemplo n.º 3
0
    def finish(self):
        if app.argv.cloud == "localhost":
            if not utils.check_bridge_exists():
                back = "{} to localhost".format(app.argv.config['spell'])
                os.execl("/usr/share/conjure-up/run-lxd-config",
                         "/usr/share/conjure-up/run-lxd-config",
                         back)
        if app.argv.controller:
            existing_controller = app.argv.controller
            if juju.get_controller(existing_controller) is None:
                utils.error("Specified controller '{}' "
                            "could not be found in cloud '{}'.".format(
                                existing_controller, app.argv.cloud))
                sys.exit(1)
        else:
            existing_controller = juju.get_controller_in_cloud(app.argv.cloud)

        if existing_controller is None:
            return controllers.use('newcloud').render(app.argv.cloud)

        utils.info("Using controller '{}'".format(existing_controller))

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        utils.info("Creating new juju model named '{}', "
                   "please wait.".format(app.current_model))
        juju.add_model(app.current_model, app.current_controller)

        return controllers.use('deploy').render()
Exemplo n.º 4
0
    def render(self, cloud):
        """ Render

        Arguments:
        cloud: The cloud to create credentials for
        """

        self.cloud = cloud
        if app.current_controller is None:
            app.current_controller = petname.Name()

        # LXD is a special case as we want to make sure a bridge
        # is configured. If not we'll bring up a new view to allow
        # a user to configure a LXD bridge with suggested network
        # information.

        if self.cloud == 'localhost':
            if not utils.check_bridge_exists():
                return controllers.use('lxdsetup').render()

            app.log.debug("Found an IPv4 address, "
                          "assuming LXD is configured.")

            self.__do_bootstrap()
            if app.fetcher != 'charmstore-search':
                return controllers.use('bundlereadme').render()
            else:
                return controllers.use('variants').render()

        # XXX: always prompt for maas information for now as there is no way to
        # logically store the maas server ip for future sessions.
        if common.try_get_creds(self.cloud) \
           is not None and self.cloud != 'maas':
            self.__do_bootstrap(credential=common.try_get_creds(self.cloud))
            if app.fetcher != 'charmstore-search':
                return controllers.use('bundlereadme').render()
            else:
                return controllers.use('variants').render()

        # show credentials editor otherwise
        try:
            creds = Schema[self.cloud]
        except KeyError as e:
            utils.pollinate(app.session_id, 'EC')
            return app.ui.show_exception_message(e)

        view = NewCloudView(app,
                            self.cloud,
                            creds,
                            self.finish)

        app.ui.set_header(
            title="New cloud setup",
        )
        app.ui.set_body(view)
Exemplo n.º 5
0
    def finish(self, controller):
        if controller is None:
            return controllers.use('clouds').render()

        app.current_controller = controller
        app.current_model = petname.Name()
        async.submit(self.__add_model,
                     self.__handle_exception,
                     queue_name=juju.JUJU_ASYNC_QUEUE)

        return controllers.use('deploy').render()
Exemplo n.º 6
0
    def finish(self, cloud):
        """ Load the Model controller passing along the selected cloud.

        Arguments:
        cloud: Cloud to create the controller/model on.
        """
        utils.pollinate(app.session_id, 'CS')
        existing_controller = juju.get_controller_in_cloud(cloud)

        if existing_controller is None:
            return controllers.use('newcloud').render(cloud)

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        async .submit(self.__add_model,
                      self.__handle_exception,
                      queue_name=juju.JUJU_ASYNC_QUEUE)

        return controllers.use('deploy').render()
Exemplo n.º 7
0
    def finish(self):
        if app.argv.cloud == "localhost":
            if not utils.check_bridge_exists():
                back = "{} to localhost".format(app.argv.config['spell'])
                os.execl("/usr/share/conjure-up/run-lxd-config",
                         "/usr/share/conjure-up/run-lxd-config", back)

        existing_controller = get_controller_in_cloud(app.argv.cloud)
        if existing_controller is None:
            return controllers.use('newcloud').render(app.argv.cloud)

        app.current_controller = existing_controller
        juju.switch_controller(app.current_controller)
        app.current_model = petname.Name()
        utils.info("Creating new juju model named '{}', "
                   "please wait.".format(app.current_model))
        juju.add_model(app.current_model)
        juju.switch_model(app.current_model)

        return controllers.use('deploy').render()
Exemplo n.º 8
0
    def render(self, cloud):

        self.cloud = cloud
        if app.current_controller is None:
            app.current_controller = petname.Name()

        if app.current_model is None:
            app.current_model = 'conjure-up'

        if self.cloud != 'localhost':
            if not common.try_get_creds(self.cloud):
                utils.warning("You attempted to do an install against a cloud "
                              "that requires credentials that could not be "
                              "found.  If you wish to supply those "
                              "credentials please run "
                              "`juju add-credential {}`.".format(self.cloud))
                sys.exit(1)

        if self.cloud == 'localhost':
            if not utils.check_bridge_exists():
                return controllers.use('lxdsetup').render()

            app.log.debug("Found an IPv4 address, "
                          "assuming LXD is configured.")

        utils.info("Bootstrapping Juju controller")
        p = juju.bootstrap(controller=app.current_controller,
                           cloud=self.cloud,
                           credential=common.try_get_creds(self.cloud))
        if p.returncode != 0:
            pathbase = os.path.join(app.config['spell-dir'],
                                    '{}-bootstrap').format(
                                        app.current_controller)
            with open(pathbase + ".err") as errf:
                utils.error("Error bootstrapping controller: "
                            "{}".format("".join(errf.readlines())))
            sys.exit(1)

        self.do_post_bootstrap()
        self.finish()
Exemplo n.º 9
0
    def finish(self, cloud):
        """ Load the Model controller passing along the selected cloud.

        Arguments:
        cloud: Cloud to create the controller/model on.
        """
        utils.pollinate(app.session_id, 'CS')
        existing_controller = get_controller_in_cloud(cloud)

        if existing_controller is None:
            return controllers.use('newcloud').render(cloud)

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        async .submit(self.__add_model,
                      self.__handle_exception,
                      queue_name=juju.JUJU_ASYNC_QUEUE)

        # Go through the rest of the gui since we already provide a direct
        # spell path
        if app.fetcher != 'charmstore-search':
            return controllers.use('bundlereadme').render()
        return controllers.use('variants').render()
Exemplo n.º 10
0
    def render(self, cloud):

        self.cloud = cloud
        if app.current_controller is None:
            app.current_controller = petname.Name()

        if app.current_model is None:
            app.current_model = 'default'

        if self.cloud != 'localhost':
            if not common.try_get_creds(self.cloud):
                utils.warning("You attempted to do an install against a cloud "
                              "that requires credentials that could not be "
                              "found.  If you wish to supply those "
                              "credentials please run "
                              "`juju add-credential {}`.".format(self.cloud))
                sys.exit(1)

        utils.info("Bootstrapping Juju controller")
        juju.bootstrap(controller=app.current_controller,
                       cloud=self.cloud,
                       credential=common.try_get_creds(self.cloud))
        self.do_post_bootstrap()
        self.finish()
Exemplo n.º 11
0
def run():

    env_name = 'MountainCar-v0'
    run_name = petname.Name()
    print "Starting environment: {0}, run: {1}".format(env_name, run_name)
    agent_type = 'DQNAgent'
    env = gym.make(env_name)
    env.monitor.start('runs/{0}/{1}/{2}'.format(env_name, agent_type,
                                                run_name))
    if agent_type == 'DQNAgent':
        sarsa_agent = DQNAgent(env)
    else:
        raise NotImplementedError

    fname = 'runs/{0}/{1}/{2}/q_values'.format(env_name, agent_type, run_name)
    if not os.path.exists(fname):
        os.makedirs(fname)
    save_every = 10
    run_episodes(sarsa_agent,
                 env,
                 episodes=3000,
                 max_steps=env.spec.timestep_limit,
                 save_every=save_every,
                 fname=fname)
Exemplo n.º 12
0
import random 
import petname 
import json

animals = {}
animals['animals'] = []
animalList = ['snake', 'bull' , 'lion', 'raven', 'bunny']

while (len(animals['animals']) < 20):
    arms = random.randrange(2,11,2) #Inclusive from 2 to 10
    legs = random.randrange(3,13,3)
    animals['animals'].append({'head':animalList[random.randint(0,4)], 'body':petname.Name() + '-' + petname.Name(), 'arms':arms, 'legs': legs, 'tail': arms+legs})

with open('animals.json', 'w') as out:
    json.dump(animals, out, indent=2)
Exemplo n.º 13
0
import json
import petname
import random

data = {}
heads = ['snake','bull','lion','raven','bunny']

data['animals'] = []

for x in range(0,20):
	data['animals'].append({'head':random.choice(heads),'body':petname.Name()+'-'+petname.Name(),'arms':random.randrange(2,11,2),'legs':random.randrange(3,13,3),'tail':0})
	data['animals'][x]['tail'] = data['animals'][x]['arms']+data['animals'][x]['legs']
with open('animals.json','w') as out:
	json.dump(data,out,indent=2) 
Exemplo n.º 14
0
def random_noun():
    """ Get a random noun from the petname library. """
    return petname.Name()
Exemplo n.º 15
0
import json
import random
import petname

head_options = ['snake', 'bull', 'lion', 'raven', 'bunny']

animals = []

for i in range(20):
    animals.append({})
    animals[i]['head'] = head_options[random.randrange(len(head_options))]
    animals[i]['body'] = petname.Name() + "-" + petname.Name()
    animals[i]['arms'] = random.randrange(2, 11, 2)
    animals[i]['legs'] = random.randrange(3, 13, 3)
    animals[i]['tail'] = animals[i]['arms'] + animals[i]['legs']

with open('animals.json', 'w') as out:
    json.dump(animals, out, indent=2)
Exemplo n.º 16
0
#!/usr/bin/env python3
import json
import petname
import random
import sys

data = {}
heads = ['snake', 'bull', 'lion', 'raven', 'bunny']

data['animals'] = []

for x in range(0, 20):
    data['animals'].append({
        'head': random.choice(heads),
        'body': petname.Name() + '-' + petname.Name(),
        'arms': random.randrange(2, 11, 2),
        'legs': random.randrange(3, 13, 3),
        'tail': 0
    })
    data['animals'][x][
        'tail'] = data['animals'][x]['arms'] + data['animals'][x]['legs']
with open(sys.argv[1], 'w') as out:
    json.dump(data, out, indent=2)