Пример #1
0
    def main(self, argv):
        parsed = self.parse_args(argv)
        if parsed == 0:
            return 0
        api_version, args = parsed

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not ((self.auth_plugin.opts.get('token')
                 or self.auth_plugin.opts.get('auth_token'))
                and self.auth_plugin.opts['endpoint']):
            if not self.auth_plugin.opts['username']:
                raise exc.CommandError("You must provide a username via "
                                       "either --os-username or via "
                                       "env[OS_USERNAME]")

            if not self.auth_plugin.opts['password']:
                raise exc.CommandError("You must provide a password via "
                                       "either --os-password or via "
                                       "env[OS_PASSWORD]")

            if self.no_project_and_domain_set(args):
                # steer users towards Keystone V3 API
                raise exc.CommandError("You must provide a project_id via "
                                       "either --os-project-id or via "
                                       "env[OS_PROJECT_ID] and "
                                       "a domain_name via either "
                                       "--os-user-domain-name or via "
                                       "env[OS_USER_DOMAIN_NAME] or "
                                       "a domain_id via either "
                                       "--os-user-domain-id or via "
                                       "env[OS_USER_DOMAIN_ID]")

            if not (self.auth_plugin.opts['tenant_id']
                    or self.auth_plugin.opts['tenant_name']):
                raise exc.CommandError("You must provide a tenant_id via "
                                       "either --os-tenant-id or via "
                                       "env[OS_TENANT_ID]")

            if not self.auth_plugin.opts['auth_url']:
                raise exc.CommandError("You must provide an auth url via "
                                       "either --os-auth-url or via "
                                       "env[OS_AUTH_URL]")

        client_kwargs = vars(args)
        client_kwargs.update(self.auth_plugin.opts)
        client_kwargs['auth_plugin'] = self.auth_plugin
        client = ckclient.get_client(api_version, **client_kwargs)
        # call whatever callback was selected
        try:
            args.func(client, args)
        except exc.HTTPUnauthorized:
            raise exc.CommandError("Invalid OpenStack Identity credentials.")
Пример #2
0
 def test_client_v1_with_session(self):
     resp = mock.Mock(status_code=200, text=b'')
     resp.json.return_value = {"modules": []}
     session = mock.Mock()
     session.request.return_value = resp
     c = client.get_client(1, session=session)
     c.modules.list()
     self.assertTrue(session.request.called)
     self.assertTrue(resp.json.called)
Пример #3
0
    def create_client(env, api_version=1, endpoint=None, exclude=[]):
        env = dict((k, v) for k, v in env.items() if k not in exclude)

        return client.get_client(api_version, **env)
config.read('cloudkitty_pricing.config')

# Fetch details from config file
# For connection part
connection = dict(config.items("connection"))

# Initializing the connection
kwargs = {
    "tenant_name":connection['tenant_name'],
    "auth_url":connection['auth_url'],
    "username":connection['username'],
    "password":connection['password'],
}

# Establish the connection
ck = client.get_client("1", **kwargs)                                                                                                                                                                      

# module enable args
module_args = {
    "module_id": "hashmap",
}

# Enable Hashmap module
module = ck.modules.get(**module_args)
module.enable()

# creation of service args
service_args = {
    "name": "compute",
}
                                                                                                                                                                                                           
Пример #5
0
config.read('cloudkitty_pricing.config')

# Fetch details from config file
# For connection part
connection = dict(config.items("connection"))

# Initializing the connection
kwargs = {
    "tenant_name": connection['tenant_name'],
    "auth_url": connection['auth_url'],
    "username": connection['username'],
    "password": connection['password'],
}

# Establish the connection
ck = client.get_client("1", **kwargs)

# module enable args
module_args = {
    "module_id": "hashmap",
}

# Enable Hashmap module
module = ck.modules.get(**module_args)
module.enable()

# creation of service args
service_args = {
    "name": "compute",
}
Пример #6
0
kwargs_conn = {
    "tenant_name": connection['username'],
    "auth_url": connection['auth_url'],
    "username": connection['username'],
    "password": connection['password'],
    "nova_version": extra_config['nova_version'],
    "cloudkitty_version": extra_config['cloudkitty_version'],
    "log_file": extra_config['log_file'],
    "region_name": connection['region']
}

# keystone client establish connection
keystone = kclient.Client(**kwargs_conn)

# Establish the connection Cloudkitty
ck = client.get_client(kwargs_conn.get('cloudkitty_version'), **kwargs_conn)

# Establish the connection NOVA
nt = nova_client.Client(kwargs_conn.get('nova_version'),
                        kwargs_conn.get('username'),
                        kwargs_conn.get('password'),
                        kwargs_conn.get('tenant_name'),
                        kwargs_conn.get('auth_url'))

# Logging the items
# Log Definition
logging.basicConfig(filename=kwargs_conn.get('log_file'),
                    level=logging.INFO,
                    format='%(asctime)s %(levelname)s %(message)s',
                    datefmt='%m-%d %H:%M:%S')
Пример #7
0
# kwargs for connection
kwargs = {
    "tenant_name": "admin",
    "auth_url": 'http://127.0.0.1:5000/v2.0',
    "username": "******",
    "password": connection['password'],
    "cloudkitty_version": extra_config['cloudkitty_version'],
}

# create cipher instance
CIPHER_KEY = "749dd86f607fa53a5890bb8a0f790474"
cipher = AESCipher(CIPHER_KEY)

#Calling the cloud kitty client
cloud_kitty = client.get_client(kwargs.get('cloudkitty_version'), **kwargs)
invoice = cloud_kitty.reports.list_invoice(all_tenants='1')
invoice_details_full = json.loads(invoice,
                                  object_hook=json_util.object_hook,
                                  use_decimal=True)
tenant_list = []

#Iterating through the invoice and setting the dictionary
for tenant in invoice_details_full:

    try:

        #Getting the tenant data using the tenant id
        tenants_list = admin_client.projects.get(tenant)
        ccno = cipher.decrypt(getattr(tenants_list, "ccno", None))
        cc_sec_code = cipher.decrypt(
Пример #8
0
def make_client(instance):
    """Returns a rating service client."""
    version = instance._api_version[API_NAME]
    version = int(version)
    auth_config = instance.get_configuration()['auth']
    return ckclient.get_client(version, **auth_config)
    def create_client(env, api_version=1, endpoint=None, exclude=[]):
        env = dict((k, v) for k, v in env.items()
                   if k not in exclude)

        return client.get_client(api_version, **env)
Пример #10
0
extra_config = dict(config.items("extra_conf"))

# kwargs for connection
kwargs = {"tenant_name":"admin",
          "auth_url":'http://127.0.0.1:5000/v2.0',
          "username":"******",
          "password":connection['password'],
          "cloudkitty_version": extra_config['cloudkitty_version'],
        }

# create cipher instance
CIPHER_KEY = "749dd86f607fa53a5890bb8a0f790474"
cipher = AESCipher(CIPHER_KEY)
 
#Calling the cloud kitty client
cloud_kitty = client.get_client(kwargs.get('cloudkitty_version'), **kwargs)
invoice = cloud_kitty.reports.list_invoice(all_tenants='1')
invoice_details_full = json.loads(invoice, object_hook=json_util.object_hook, use_decimal=True)
tenant_list = []

#Iterating through the invoice and setting the dictionary 
for tenant in invoice_details_full:

    try:

        #Getting the tenant data using the tenant id 
        tenants_list = admin_client.projects.get(tenant)
        ccno = cipher.decrypt(getattr(tenants_list, "ccno", None))
        cc_sec_code = cipher.decrypt(getattr(project, "billing_cc_sec_code", None))

        for tenant_data in invoice_details_full[tenant]: