예제 #1
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def create_dhg(access_token, subscription_id, resource_group, dhg_name,
              az_name, location):
    '''Create dedicated host group.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        dhg_name (str): Name of the new dedicated host group.
        az_name (str): Availability zone name.
        location (str): Azure data center location. E.g. west us.

    Returns:
        HTTP response. JSON body of the dedicated host group properties.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/hostgroups/', dhg_name,
                        '?api-version=', COMP_API])
    dhg_body = {'location': location}
    if az_name is not None:
        dhg_body['zones'] = [az_name]    
    body = json.dumps(dhg_body)
    return do_put(endpoint, body, access_token)
예제 #2
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def list_vms_sub(access_token, subscription_id):
    '''List VMs in a subscription.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.

    Returns:
        HTTP response. JSON body of a list of VM model views.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Compute/virtualMachines',
                        '?api-version=', COMP_API])
    return do_get_next(endpoint, access_token)
예제 #3
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def list_dhg_sub(access_token, subscription_id):
    '''List dedicated host groups in a subscription.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.

    Returns:
        HTTP response. JSON body of the list of dedicated hostsproperties.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Compute/hostgroups',
                        '?api-version=', COMP_API])
    return do_get_next(endpoint, access_token)
예제 #4
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def get_compute_usage(access_token, subscription_id, location):
    '''List compute usage and limits for a location.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        location (str): Azure data center location. E.g. westus.

    Returns:
        HTTP response. JSON body of Compute usage and limits data.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.compute/locations/', location,
                        '/usages?api-version=', COMP_API])
    return do_get(endpoint, access_token)
예제 #5
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def list_dhg(access_token, subscription_id, resource_group):
    '''List availability sets in a resource_group.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.

    Returns:
        HTTP response. JSON body of the list of availability set properties.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/hostgroups',
                        '?api-version=', COMP_API])
    return do_get_next(endpoint, access_token)
예제 #6
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def get_vm_instance_view(access_token, subscription_id, resource_group, vm_name):
    '''Get operational details about the state of a VM.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        vm_name (str): Name of the virtual machine.

    Returns:
        HTTP response. JSON body of VM instance view details.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachines/', vm_name,
                        '/InstanceView?api-version=', COMP_API])
    return do_get(endpoint, access_token)
예제 #7
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def deallocate_vm(access_token, subscription_id, resource_group, vm_name):
    '''Stop-deallocate a virtual machine.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        vm_name (str): Name of the virtual machine.

    Returns:
        HTTP response.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachines/', vm_name,
                        '/deallocate',
                        '?api-version=', COMP_API])
    return do_post(endpoint, '', access_token)
예제 #8
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def update_vm(access_token, subscription_id, resource_group, vm_name, body):
    '''Update a virtual machine with a new JSON body. E.g. do a GET, change something, call this.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        vm_name (str): Name of the virtual machine.
        body (dict): JSON body of the VM.

    Returns:
        HTTP response.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachines/', vm_name,
                        '?api-version=', COMP_API])
    return do_put(endpoint, body, access_token)
예제 #9
0
파일: adh_crp.py 프로젝트: zivraf/ADH-Mng
def get_dh(access_token, subscription_id, resource_group,dhg_name, dh_name):
    '''Get a dedicated host and its instance view.

    Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        dhg_name (str): Dedicated host group name.

    Returns:
        HTTP response. JSON body of the list of dedicated hosts properties.
    '''
    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/hostgroups/', dhg_name,
                        '/hosts/',dh_name,
                        '?$expand=instanceView&api-version=', COMP_API])
    return do_get_next(endpoint, access_token)