Пример #1
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        metric_info = client.get_metrics(parsed_args.bundle_type, parsed_args.instance)
        columns = ("Metric",)
        data = [(v,) for v in metric_info["Metric"]]
        return (columns, data)
Пример #2
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        values = client.get_metric_values(parsed_args.bundle_type, parsed_args.instance, parsed_args.metric)
        columns = ("Timestamp", "Value")
        data = [(datetime.datetime.fromtimestamp(v["T"]), v["V"]) for v in values["Points"]]
        return (columns, data)
Пример #3
0
    def take_action(self, parsed_args):
        options = {}
        options[parsed_args.option_key] = parsed_args.option_value

        client = utils.get_jxaas_client(self)
        units = None
        client.ensure_instance(parsed_args.bundle_type, parsed_args.instance, options=options, units=units)
Пример #4
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        instances = client.list_instances(parsed_args.bundle_type)
        columns = ("Id", "Status", "NumberUnits")
        data = [(i.get("Id"), i.get("Status"), i.get("NumberUnits")) for i in instances]
        return (columns, data)
Пример #5
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        bundletypes = client.list_bundle_types()
        columns = ('Id', 'Name')
        data = [(b.get('Id'),b.get('Name')) for b in bundletypes.get('Bundles', [])]
        return (columns, data)
Пример #6
0
Файл: logs.py Проект: jxaas/cli
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        log = client.get_log(parsed_args.bundle_type, parsed_args.instance)
        columns = ('Line',)
        data = [(v,) for v in log]
        return (columns, data)
Пример #7
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        info = client.get_instance_state(parsed_args.bundle_type, parsed_args.instance)
        columns = ('Option Key','Option Value')
        self.log.debug("Instance state: %s", info)
        data = [(k, v,) for k, v in info['Options'].iteritems()]
        return (columns, data)
Пример #8
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        health_info = client.get_health(parsed_args.bundle_type, parsed_args.instance)

        columns = ("Unit", "Healthy")
        data = [(k, v) for k, v in health_info["Units"].iteritems()]
        return (columns, data)
Пример #9
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        relation_properties = client.get_relation_properties(
            parsed_args.bundle_type, parsed_args.instance, parsed_args.relation
        )

        relation_properties = relation_properties["Properties"]
        columns = ("Key", "Value")
        data = [(k, v) for k, v in relation_properties.iteritems()]
        return (columns, data)
Пример #10
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)
        options = {}
        options_args = parsed_args.options
        for options_arg in options_args:
            tokens = options_arg.split("=", 2)
            if len(tokens) != 2:
                raise Exception("Expected options format 'key=value', got '" + options_args + "'")
            options[tokens[0]] = tokens[1]

        units = None
        client.ensure_instance(parsed_args.bundle_type, parsed_args.instance, options=options, units=units)
Пример #11
0
    def take_action(self, parsed_args):
        args = vars(parsed_args)
        print args
        policy = {}
        if args['scale_min'] is not None:
          policy['ScaleMin'] = int(args['scale_min'])
        if args['scale_max'] is not None:
          policy['ScaleMax'] = int(args['scale_max'])
        if args['metric_min'] is not None:
          policy['MetricMin'] = float(args['metric_min'])
        if args['metric_max'] is not None:
          policy['MetricMax'] = float(args['metric_max'])
        if args['metric_name'] is not None:
          policy['MetricName'] = args['metric_name']

        client = utils.get_jxaas_client(self)
        client.set_scaling(parsed_args.bundle_type, parsed_args.instance, policy=policy)
Пример #12
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        utils.wait_jxaas_started(client, parsed_args.bundle_type, parsed_args.instance)
Пример #13
0
 def take_action(self, parsed_args):
     client = utils.get_jxaas_client(self)
     client.repair_instance(parsed_args.bundle_type, parsed_args.instance)
Пример #14
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        relation = None
        bundle_type = parsed_args.bundle_type
        if bundle_type in ["mysql", "multimysql"]:
            relation = "mysql"
        if bundle_type in ["mongodb"]:
            relation = "mongodb"
        if bundle_type in ["pg"]:
            relation = "pgsql"
        if bundle_type in ["cassandra"]:
            relation = "cassandra"
        if not relation:
            raise Exception("Unhandled bundle_type")

        relation_properties = client.get_relation_properties(bundle_type, parsed_args.instance, relation)
        properties = relation_properties.get("Properties", {})
        addresses = relation_properties.get("PublicAddresses", [])

        host = None
        if addresses:
            host = addresses[0]

        protocol = properties.get("protocol", "")

        use_tls_proxy = protocol == "tls"

        if relation == "mysql":
            if not "user" in properties:
                raise Exception("Service not ready")
            if not host:
                host = properties["host"]
            port = properties["port"] or "3306"

        if relation == "cassandra":
            if not "private-address" in properties:
                raise Exception("Service not ready")
            if not host:
                host = properties["private-address"]
            port = properties["port"] or "9160"

        if relation == "mongodb":
            if not "port" in properties or not "replset" in properties:
                raise Exception("Service not ready")
            if not host:
                host = properties["hostname"]
            port = properties["port"] or "27017"

        if relation == "pgsql":
            if not "user" in properties:
                raise Exception("Service not ready")
            if not host:
                host = properties["host"]
            port = properties["port"] or "5432"

        # Start the tls proxy if we need one
        if use_tls_proxy:
            # TODO: Assign random port
            listen_address = ("127.0.0.1", 10000)
            forward_address = (host, int(port))
            # TODO: Use real security options here
            ssl_context = {}
            tls_proxy = jujuxaas.tls_proxy.TlsProxy(ssl_context, listen_address, forward_address)
            tls_proxy.start()
            host = listen_address[0]
            port = listen_address[1]

        env = os.environ.copy()
        if relation == "mysql":
            command = ["mysql"]
            command = command + ["--user="******"user"]]
            command = command + ["--host=" + host]
            command = command + ["--password="******"password"]]
            command = command + ["--database=" + properties["database"]]
            command = command + ["--port=" + str(port)]

        if relation == "cassandra":
            command = ["cqlsh", host, port]

        if relation == "mongodb":
            command = ["mongo"]
            command = command + ["%s:%s/%s" % (host, port, properties["replset"])]

        if relation == "pgsql":
            command = ["psql"]
            command = command + ["--username="******"user"]]
            command = command + ["--host=" + host]
            command = command + ["--port=" + port]
            command = command + ["--dbname=" + properties["database"]]
            # command = command + [ '--password']
            env["PGPASSWORD"] = properties["password"]

        self.log.debug("Running command: %s", " ".join(command))
        p = subprocess.Popen(command, env=env)
        p.wait()
Пример #15
0
    def take_action(self, parsed_args):
        client = utils.get_jxaas_client(self)

        scaling = client.get_scaling(parsed_args.bundle_type, parsed_args.instance)
        #print scaling
        return _format(scaling)