Exemple #1
0
 def _get_project(project_id):
     project = projects.get(project_id)
     if project:
         return project
     project = keystone.get_project(project_id)
     project_name = project.name if project else None
     projects[project_id] = models.SimpleProject(
         project_id=project_id, project_name=project_name)
     return projects[project_id]
Exemple #2
0
 def _get_project(project_id):
     project = projects.get(project_id)
     if project:
         return project
     project = keystone.get_project(project_id)
     project_name = project.name if project else None
     projects[project_id] = models.SimpleProject(
         project_id=project_id,
         project_name=project_name
     )
     return projects[project_id]
Exemple #3
0
 def _get_project(project_id):
     project = projects.get(project_id)
     if project:
         return project
     try:
         project = keystone.get_project(project_id)
         project_name = project.name if project else None
         projects[project_id] = models.SimpleProject(
             project_id=project_id, project_name=project_name)
         return projects[project_id]
     except Exception as e:
         # Note(chengkun): some project was deleted from keystone,
         # But the project's order still in the gringotts. so when
         # we get the order it will raise 404 project not found error
         LOG.error('error to get project: %s' % e)
         return None
Exemple #4
0
 def _get_project(project_id):
     project = projects.get(project_id)
     if project:
         return project
     try:
         project = keystone.get_project(project_id)
         project_name = project.name if project else None
         projects[project_id] = models.SimpleProject(
             project_id=project_id,
             project_name=project_name)
         return projects[project_id]
     except Exception as e:
         # Note(chengkun): some project was deleted from keystone,
         # But the project's order still in the gringotts. so when
         # we get the order it will raise 404 project not found error
         LOG.error('error to get project: %s' % e)
         return None
def upgrade():

    # ensure the service is avaliable
    from gringotts.services import keystone

    op.create_table(
        'project',

        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('user_id', sa.String(255), index=True),
        sa.Column('project_id', sa.String(255), index=True),
        sa.Column('consumption', sa.DECIMAL(20,4)),

        sa.Column('domain_id', sa.String(255)),

        sa.Column('created_at', sa.DateTime),
        sa.Column('updated_at', sa.DateTime),

        mysql_engine='InnoDB',
        mysql_charset='utf8',
    )


    op.create_table(
        'user_project',

        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('user_id', sa.String(255), index=True),
        sa.Column('project_id', sa.String(255), index=True),
        sa.Column('consumption', sa.DECIMAL(20,4)),

        sa.Column('domain_id', sa.String(255)),

        sa.Column('created_at', sa.DateTime),
        sa.Column('updated_at', sa.DateTime),

        mysql_engine='InnoDB',
        mysql_charset='utf8',
    )

    op.create_unique_constraint('uq_user_project_id', 'user_project', ['user_id', 'project_id'])
    op.create_unique_constraint('uq_order_resource_id', 'order', ['resource_id'])

    op.add_column('account', sa.Column('domain_id', sa.String(255)))
    op.add_column('order', sa.Column('domain_id', sa.String(255)))
    op.add_column('subscription', sa.Column('domain_id', sa.String(255)))
    op.add_column('bill', sa.Column('domain_id', sa.String(255)))
    op.add_column('charge', sa.Column('domain_id', sa.String(255)))
    op.add_column('precharge', sa.Column('domain_id', sa.String(255)))

    op.create_index('ix_order_user_id_project_id', 'order', ['user_id', 'project_id'])

    conn = op.get_bind()
    accounts = conn.execute("select user_id, project_id, consumption, created_at from account").fetchall()

    for account in accounts:
        try:
            project = keystone.get_project(account['project_id'])

            now = datetime.datetime.utcnow().strftime(TIMESTAMP_TIME_FORMAT)
            op.execute("INSERT INTO project VALUES(0, '%s', '%s', '%s', '%s', '%s', '%s')" % \
                       (account[0], account[1], account[2], project.domain_id,
                        account[3], now))
            op.execute("INSERT INTO user_project VALUES(0, '%s', '%s', '%s', '%s', '%s', '%s')" % \
                       (account[0], account[1], account[2], project.domain_id,
                        account[3], now))
            op.execute("UPDATE account set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
            op.execute("UPDATE `order` set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
            op.execute("UPDATE `order` set user_id='%s' where project_id='%s' and user_id is NULL" % \
                       (account['user_id'], account[1]))
            op.execute("UPDATE subscription set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
            op.execute("UPDATE bill set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
            op.execute("UPDATE charge set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
            op.execute("UPDATE precharge set domain_id='%s' where project_id='%s'" % \
                       (project.domain_id, account[1]))
        except Exception as e:
            pass