示例#1
0
 def _row_to_db_project_model(row):
     return db_models.Project(user_id=row.user_id,
                              project_id=row.project_id,
                              domain_id=row.domain_id,
                              consumption=row.consumption,
                              created_at=row.created_at,
                              updated_at=row.updated_at)
def synchronize_database():
    ctx = context.make_admin_context(all_tenants=True)
    context.set_ctx(ctx)

    def _generate_group(_set, _type):
        ids_set = []
        for subset in _set:
            ids_set.append(subset[_type])
        return ids_set

    rate_projects_id = _generate_group(dbapi.get_projects(ctx), 'project_id')
    rate_accounts_id = _generate_group(dbapi.get_accounts(ctx), 'user_id')
    ks_projects = keystone_client.get_project_list()
    ks_users = keystone_client.get_user_list()

    billing_admin = keystone_client.get_user_list(name='billing_admin')[0]
    billing_admin_id = billing_admin.id
    domain_id = billing_admin.domain_id

    for ks_project in ks_projects:
        if ks_project.id not in rate_projects_id:
            dbapi.create_project(ctx,
                                 db_models.Project(
                                     user_id=billing_admin_id,
                                     project_id=ks_project.id,
                                     domain_id=domain_id,
                                     consumption=0))
    for ks_user in ks_users:
        if ks_user.id not in rate_accounts_id:
            dbapi.create_account(ctx,
                                 db_models.Account(
                                     user_id=ks_user.id,
                                     domain_id=domain_id,
                                     balance=0,
                                     consumption=0,
                                     level=4))
            dbapi.charge_account(ctx, user_id=ks_user.id, value=10,
                                 type='bonus', come_from='system')
    context.set_ctx(None)
示例#3
0
def _create_temp_project(**kwargs):
    db_project = db_utils.get_test_project(**kwargs)
    project = db_models.Project(**db_project)
    return project
示例#4
0
 def get(self):
     """Return this project."""
     return db_models.Project(**self._project())
 def create_project(cls, context, **kwargs):
     LOG.debug('Conductor Function: create_project.')
     project = db_models.Project(**kwargs)
     return cls.dbapi.create_project(context, project)