OpenStack'ten OpenStack'e Göç - Proje Göçü


openstacksdk 1.4.0 ve 1.5.0 dahil olmak üzere aşağıda paylaşılan kodun sorunsuz çalışması için bu patchi kendiniz uygulamalısınız.

Newstack tarafında kullanıcımız oluştuğuna göre artık projemizi göç ettirebiliriz. Bu işlemi yaparken sadece proje göç ettirmek ile kalmayıp, proje üzerinde bulunan yetkileri de newstack tarafına aynı kullanıcılar ile eşleştirerek oluşturacağız.

Bu işlem için bir önceki scriptimiz yanında 2_project_migration_user_association.py adında bir script daha oluşturalım. Başlangıç olarak, kullanıcı göçünde yaptığımız gibi cloud_connection.py scriptinde importları gerçekleştireceğiz.

Bu işlemi gerçekleştirmek için proje üzerinde herhangi bir rolü olan bütün kullanıcıların bir önceki aşamada taşınmış olması gerekmektedir. Aynı şekilde eğer özel roller eklendi ise yazı dizimizde değinmememize rağmen bunları da taşımak gerekmektedir. Role taşıma işlemi içinde openstacksdk kolayca kullanılabilir.

Projelerimizi de kullanıcı göçünde gerçekleştirdiğimiz gibi filtreleyelim.

# --------------------------------------------------------------------------------- #
#   PROJECTS TO / NOT TO MIGRATE
#   If projects_to_migrate is empty, script migrates every project that is not in 
#   projects_to_filter list to destination  
projects_to_migrate = [
]

projects_to_filter = [
    'admin',
    'service'
]
#   PROJECTS TO / NOT TO MIGRATE
# --------------------------------------------------------------------------------- #

Filtreleme mantığımız bir önceki yazıdaki ile aynı. İşlemimiz yine bütün projeleri bir döngü içerisinde çevirecek ve filtreleyecek. Filtreleme sonrasında yapacağımız işlemler ise sırasıyla aşağıdaki gibi olacak.

  1. oldstack tarafında bulunan proje detaylarını alma
  2. newstack tarafında bu detaylar ile proje oluşturulacak
  3. oldstack tarafında proje üzerindeki yetkilendirmeler ve bu yetkiye sahip kullanıcıların newstack tarafındaki bilgileri bulunacak ve aynı yetkilendirmeler oluşturulacak
  4. oldstack tarafında projeye kotalar alınacak
  5. bu kotalar newstack tarafında uygulacak

Bu listede verilen her parça kendi numarası ile aşağıdaki kod içerisinde # [X] # şeklinde yorum satırı olarak belirtilmiştir.

for project in connold.identity.projects():

    project = project.to_dict()
    should_filter = False

    # Check If Project Should NOT Migrate
    if project['name'] in projects_to_filter:
        should_filter = True
    if projects_to_migrate:
        if project['name'] not in projects_to_migrate:
            should_filter = True

    # Continue Loop
    if should_filter:
        continue

    # Print Migrating Project Details
    print("----------------------------------------------------------")
    pp.pprint(project)
    print("----------------------------------------------------------")
    print("PROJECT: ", project['name'], " ID: ", project['id'], " will be migrated..." )
    print("----------------------------------------------------------")

    # [1] # Create New Project Details
    c_project_attrs = {
        "description":      project["description"],
        "is_domain":        project["is_domain"],
        "is_enabled":       project["is_enabled"],
        "name":             project["name"]
    }

    # [2] # Create New Project on Destination OpenStack 
    new_project = connnew.identity.create_project(**c_project_attrs)
    print("-----------------NEW Project DETAILS----------------------")
    pp.pprint(new_project.to_dict())
    print("----------------------------------------------------------")

    # [3] # Find User/Roles of This Project and Assing Corresponding on Destination OpenStack
    for role_assigns in connold.identity.role_assignments():
        role_assigns = role_assigns.to_dict()

        if 'project' in role_assigns['scope']:
            if role_assigns['scope']['project']['id'] == project['id']:

                old_user_id = role_assigns['user']['id']
                old_user = connold.identity.get_user(old_user_id)
                new_user = connold.identity.find_user(old_user.to_dict()['name'] )

                role = connold.identity.get_role(role_assigns['role']['id'])
                new_role = connnew.identity.find_role(role.to_dict()['name'])

                print("-------------------")
                print("Adding role: ", new_role['name'], " to ", "Project: " , new_project['name'], " ID: ", new_project['id'], " for ", new_user['name'])
                connnew.grant_role(new_role['id'],user=new_user['name'],project=new_project['id'],wait=True)
                print("-------------------")

    # [4] # Get Compute Volume and Network Quotas for Project 
    qutoas = connold.get_compute_quotas(project['id'])
    compute_qutoas = qutoas.to_dict()

    qutoas = connold.get_volume_quotas(project['id'])
    volume_qutoas = qutoas.to_dict()

    qutoas = connold.get_network_quotas(project['id'])
    network_qutoas = qutoas.to_dict()

    # Create Compute Volume and Network Quota Details
    c_compute_quotas = {
        "cores":                        compute_qutoas["cores"],
        "injected_file_content_bytes":  compute_qutoas["injected_file_content_bytes"],
        "injected_file_path_bytes":     compute_qutoas["injected_file_path_bytes"],
        "injected_files":               compute_qutoas["injected_files"],
        "instances":                    compute_qutoas["instances"],
        "key_pairs":                    compute_qutoas["key_pairs"],
        "metadata_items":               compute_qutoas["metadata_items"],
        "ram":                          compute_qutoas["ram"],
        "server_group_members":         compute_qutoas["server_group_members"],
        "server_groups":                compute_qutoas["server_groups"]
    }

    c_volume_quotas = {
        "gigabytes":        volume_qutoas["gigabytes"],
        "snapshots":        volume_qutoas["snapshots"],
        "volumes":          volume_qutoas["volumes"]    
    }

    c_network_quotas = {
        "floating_ips":         network_qutoas["floating_ips"],
        "networks":             network_qutoas["networks"],
        "ports":                network_qutoas["ports"],
        "rbac_policies":        network_qutoas["rbac_policies"],
        "routers":              network_qutoas["routers"],
        "security_group_rules": network_qutoas["security_group_rules"],
        "subnets":              network_qutoas["subnets"]
    }

    # [5] # Aplly Quotas to New Project on Destination OpenStack
    connnew.set_compute_quotas(new_project['id'],**c_compute_quotas)
    connnew.set_volume_quotas(new_project['id'],**c_volume_quotas)
    connnew.set_network_quotas(new_project['id'],**c_network_quotas)

Scriptimizi çalıştırdığımızda geri dönüşü aşağıdaki şekilde olmakta:

----------------------------------------------------------
{   'description': 'Deneme Project',
    'domain_id': 'default',
    'id': '5b656fc728104f97a0d6b8c1e0ac8ed2',
    'is_domain': False,
    'is_enabled': True,
    'links': {   'self': 'http://172.16.0.10:5000/v3/projects/5b656fc728104f97a0d6b8c1e0ac8ed2'},
    'location': Munch({'cloud': 'oldstack', 'region_name': 'RegionOne', 'zone': None, 'project': Munch({'id': '7525ce2c81a24e87a202dae3c99f3b56', 'name': 'admin', 'domain_id': None, 'domain_name': 'Default'})}),
    'name': 'deneme_proj',
    'options': {},
    'parent_id': 'default',
    'tags': []}
----------------------------------------------------------
PROJECT:  deneme_proj  ID:  5b656fc728104f97a0d6b8c1e0ac8ed2  will be migrated...
----------------------------------------------------------
-----------------NEW Project DETAILS----------------------
{   'description': 'Deneme Project',
    'domain_id': 'default',
    'id': '28683b546d9b4a2e9943810d71ec99cf',
    'is_domain': False,
    'is_enabled': True,
    'links': {   'self': 'http://172.16.0.11:5000/v3/projects/28683b546d9b4a2e9943810d71ec99cf'},
    'location': Munch({'cloud': 'newstack', 'region_name': 'RegionOne', 'zone': None, 'project': Munch({'id': '0a466901b0e14283af568085d07617ca', 'name': 'admin', 'domain_id': None, 'domain_name': 'Default'})}),
    'name': 'deneme_proj',
    'options': {},
    'parent_id': 'default',
    'tags': []}
----------------------------------------------------------
-------------------
Adding role:  _member_  to  Project:  deneme_proj  ID:  28683b546d9b4a2e9943810d71ec99cf  for  deneme_user
-------------------
-------------------
Adding role:  member  to  Project:  deneme_proj  ID:  28683b546d9b4a2e9943810d71ec99cf  for  deneme_user
-------------------

newstack tarafında "28683b546d9b4a2e9943810d71ec99cf" IDsi ile yeni projemiz oluştu, şeklinde oldu. Kotalarımız için arayüzden ufak bir kontrol gerçekleştirelim, rollerimizi ise cli üzerinden yeni proje IDmiz ile grepleyerek bakalım.

quotas

erdem@EWUL:~$ openstack --os-cloud newstack role assignment list | grep 28683b546d9b4a2e9943810d71ec99cf
+----------------------------------+----------------------------------+-------+----------------------------------+----------------------------------+--------+-----------+
| Role                             | User                             | Group | Project                          | Domain                           | System | Inherited |
+----------------------------------+----------------------------------+-------+----------------------------------+----------------------------------+--------+-----------+
| 0e39ed0129d443a9b530c09a5c6c1df9 | 415cbda201ff4f0db64d0ddbfb798b2f |       | 28683b546d9b4a2e9943810d71ec99cf |                                  |        | False     |
| 95906f72054b4b4f82449103830d111a | 415cbda201ff4f0db64d0ddbfb798b2f |       | 28683b546d9b4a2e9943810d71ec99cf |                                  |        | False     |

Teyitlerimizde de projemiz, kotalarımız ve rollerimizin taşındığını gördük. Bir basamak daha devrildi diyebiliriz.

Projemizi ve proje - kullanıcı yetkilendirmelerini aktardık, artık Nitelik Göçü aşamasına geçebiliriz.

OpenStack'ten OpenStack'e Göç:

  1. Yazı Dizisi
  2. Kurulum Bilgileri
  3. Hazırlık
  4. Kullanıcı Göçü
  5. Proje Göçü
  6. Nitelik Göçü
  7. Güvenlik Göçü
  8. Ağ Göçü
  9. Devam Edecek..

Referanslar:

Teşekkür:

Ana fotoğraf: John Rodenn Castillo orjinaline Unsplash üzerinden ulaşabilirsiniz.

Previous Next