def build_datadisks_profile(usr_datadisks):
    '''
        Creates a list of storageProfile::dataDisk objects for use when
        creating a Virtual Machine

    :param dict usr_datadisks: User data
    :returns: List of storageProfile::dataDisk objects
    :rtype: list
    '''
    datadisks = list()
    if not usr_datadisks:
        return list()
    for idx, usr_datadisk in enumerate(usr_datadisks):
        datadisk = deepcopy(usr_datadisk)
        # Generate disk name if one wasn't provided
        datadisk['name'] = datadisk.get('name') or \
            '{0}-{1}'.format(utils.get_resource_name(), idx)
        # If no disk URI was specified, generate one
        if not datadisk.get('vhd', dict()).get('uri'):
            datadisk['vhd'] = {
                'uri': 'http://{0}.{1}/vhds/{2}.vhd'.format(
                    utils.get_rel_node_name(constants.REL_CONNECTED_TO_SA),
                    'blob.core.windows.net',
                    datadisk.get('name'))
            }
        # Fill in the blanks if the user didn't specify
        datadisk['lun'] = datadisk.get('lun', idx)
        datadisk['createOption'] = datadisk.get('createOption', 'Empty')
        datadisks.append(datadisk)
    return datadisks
def build_osdisk_profile(usr_osdisk=None):
    '''
        Creates a storageProfile::osDisk object for use when
        creating a Virtual Machine

    :param dict usr_osdisk: User-override data
    :returns: storageProfile::osDisk object
    :rtype: dict
    '''
    osdisk = dict()
    if isinstance(usr_osdisk, dict):
        osdisk = deepcopy(usr_osdisk)
    # Generate disk name if one wasn't provided
    osdisk['name'] = osdisk.get('name') or utils.get_resource_name()
    # If no disk URI was specified, generate one
    if not osdisk.get('vhd', dict()).get('uri'):
        osdisk['vhd'] = {
            'uri': 'http://{0}.{1}/vhds/{2}.vhd'.format(
                utils.get_rel_node_name(constants.REL_CONNECTED_TO_SA),
                'blob.core.windows.net',
                osdisk.get('name'))
        }
    # Fill in the blanks if the user didn't specify
    osdisk['caching'] = osdisk.get('caching', 'ReadWrite')
    osdisk['createOption'] = osdisk.get('createOption', 'FromImage')
    return osdisk
def build_datadisks_profile(usr_datadisks):
    '''
        Creates a list of storageProfile::dataDisk objects for use when
        creating a Virtual Machine

    :param dict usr_datadisks: User data
    :returns: List of storageProfile::dataDisk objects
    :rtype: list
    '''
    datadisks = list()
    if not usr_datadisks:
        return list()
    for idx, usr_datadisk in enumerate(usr_datadisks):
        datadisk = deepcopy(usr_datadisk)
        # Generate disk name if one wasn't provided
        datadisk['name'] = datadisk.get('name') or \
            '{0}-{1}'.format(utils.get_resource_name(), idx)
        # If no disk URI was specified, generate one
        if not datadisk.get('vhd', dict()).get('uri'):
            datadisk['vhd'] = {
                'uri':
                'http://{0}.{1}/vhds/{2}.vhd'.format(
                    utils.get_rel_node_name(constants.REL_CONNECTED_TO_SA),
                    'blob.' + ctx.node.properties['storage_endpoint'],
                    datadisk.get('name'))
            }
        # Fill in the blanks if the user didn't specify
        datadisk['lun'] = datadisk.get('lun', idx)
        datadisk['createOption'] = datadisk.get('createOption', 'Empty')
        datadisks.append(datadisk)
    return datadisks
def build_osdisk_profile(usr_osdisk=None):
    '''
        Creates a storageProfile::osDisk object for use when
        creating a Virtual Machine

    :param dict usr_osdisk: User-override data
    :returns: storageProfile::osDisk object
    :rtype: dict
    '''
    osdisk = dict()
    if isinstance(usr_osdisk, dict):
        osdisk = deepcopy(usr_osdisk)
    # Generate disk name if one wasn't provided
    osdisk['name'] = osdisk.get('name') or utils.get_resource_name()
    # If no disk URI was specified, generate one
    # Unless this is a managedDisk.
    if not osdisk.get('vhd', dict()).get('uri') and \
            'managedDisk' not in osdisk:
        osdisk['vhd'] = {
            'uri':
            'http://{0}.{1}/vhds/{2}.vhd'.format(
                utils.get_rel_node_name(constants.REL_CONNECTED_TO_SA),
                'blob.' + ctx.node.properties['storage_endpoint'],
                osdisk.get('name'))
        }
    # Fill in the blanks if the user didn't specify
    osdisk['caching'] = osdisk.get('caching', 'ReadWrite')
    osdisk['createOption'] = osdisk.get('createOption', 'FromImage')
    return osdisk
def create_rule(**_):
    '''Uses an existing, or creates a new, Load Balancer Rule'''
    # Check if invalid external resource
    if ctx.node.properties.get('use_external_resource', False) and \
       not ctx.node.properties.get('name'):
        raise NonRecoverableError(
            '"use_external_resource" specified without a resource "name"')
    # Generate a name if it doesn't exist
    utils.generate_resource_name(LoadBalancerRule(
        api_version=ctx.node.properties.get('api_version',
                                            constants.API_VER_NETWORK)))
    # Get the resource config
    res_cfg = utils.get_resource_config()
    # Get an interface to the Load Balancer
    lb_rel = utils.get_relationship_by_type(
        ctx.instance.relationships,
        constants.REL_CONTAINED_IN_LB)
    lb_name = utils.get_resource_name(lb_rel.target)
    lb_iface = LoadBalancer(api_version=ctx.node.properties.get(
            'api_version', constants.API_VER_NETWORK))
    lb_data = lb_iface.get(lb_name)
    # Get the Load Balancer Backend Pool
    lb_be_pool_id = utils.get_rel_id_reference(
        BackendAddressPool, constants.REL_CONNECTED_TO_LB_BE_POOL)
    # Get the Load Balancer Probe
    lb_probe_id = utils.get_rel_id_reference(
        Probe, constants.REL_CONNECTED_TO_LB_PROBE)
    # Get the Load Balancer Frontend IP Configuration
    lb_fe_ipc_name = utils.get_rel_node_name(constants.REL_CONNECTED_TO_IPC)
    lb_fe_ipc_id = utils.get_full_resource_id(
        FrontendIPConfiguration(api_version=ctx.node.properties.get(
            'api_version', constants.API_VER_NETWORK)
        ), lb_fe_ipc_name)
    # Get the existing Load Balancer Rules
    lb_rules = lb_data.get('properties', dict()).get(
        'loadBalancingRules', list())
    # Update the resource config
    res_cfg['backendAddressPool'] = lb_be_pool_id
    res_cfg['frontendIPConfiguration'] = lb_fe_ipc_id
    res_cfg['probe'] = lb_probe_id
    lb_rules.append({
        'name': utils.get_resource_name(),
        'properties': res_cfg
    })
    # Update the Load Balancer with the new rule
    utils.task_resource_update(
        lb_iface,
        {
            'properties': {
                'loadBalancingRules': lb_rules
            }
        },
        name=lb_name)
Ejemplo n.º 6
0
def create_rule(**_):
    '''Uses an existing, or creates a new, Load Balancer Rule'''
    # Check if invalid external resource
    if ctx.node.properties.get('use_external_resource', False) and \
       not ctx.node.properties.get('name'):
        raise NonRecoverableError(
            '"use_external_resource" specified without a resource "name"')
    # Generate a name if it doesn't exist
    utils.generate_resource_name(LoadBalancerRule())
    # Get the resource config
    res_cfg = utils.get_resource_config()
    # Get an interface to the Load Balancer
    lb_rel = utils.get_relationship_by_type(
        ctx.instance.relationships,
        constants.REL_CONTAINED_IN_LB)
    lb_name = utils.get_resource_name(lb_rel.target)
    lb_iface = LoadBalancer()
    lb_data = lb_iface.get(lb_name)
    # Get the Load Balancer Backend Pool
    lb_be_pool_id = utils.get_rel_id_reference(
        BackendAddressPool, constants.REL_CONNECTED_TO_LB_BE_POOL)
    # Get the Load Balancer Probe
    lb_probe_id = utils.get_rel_id_reference(
        Probe, constants.REL_CONNECTED_TO_LB_PROBE)
    # Get the Load Balancer Frontend IP Configuration
    lb_fe_ipc_name = utils.get_rel_node_name(constants.REL_CONNECTED_TO_IPC)
    lb_fe_ipc_id = utils.get_full_resource_id(
        FrontendIPConfiguration(), lb_fe_ipc_name)
    # Get the existing Load Balancer Rules
    lb_rules = lb_data.get('properties', dict()).get(
        'loadBalancingRules', list())
    # Update the resource config
    res_cfg['backendAddressPool'] = lb_be_pool_id
    res_cfg['frontendIPConfiguration'] = lb_fe_ipc_id
    res_cfg['probe'] = lb_probe_id
    lb_rules.append({
        'name': utils.get_resource_name(),
        'properties': res_cfg
    })
    # Update the Load Balancer with the new rule
    utils.task_resource_update(
        lb_iface,
        {
            'properties': {
                'loadBalancingRules': lb_rules
            }
        },
        name=lb_name)
Ejemplo n.º 7
0
 def __init__(self,
              resource_group=None,
              virtual_machine=None,
              api_version=constants.API_VER_COMPUTE,
              logger=None,
              _ctx=ctx):
     resource_group = resource_group or \
         utils.get_resource_group(_ctx=_ctx)
     virtual_machine = virtual_machine or \
         utils.get_rel_node_name(constants.REL_VMX_CONTAINED_IN_VM)
     Resource.__init__(self,
                       'Virtual Machine Extension',
                       '/{0}/{1}/{2}/{3}'.format(
                           'resourceGroups/{0}'.format(resource_group),
                           'providers/Microsoft.Compute',
                           'virtualMachines/{0}'.format(virtual_machine),
                           'extensions'),
                       api_version=api_version,
                       logger=logger,
                       _ctx=_ctx)
Ejemplo n.º 8
0
def create_incoming_nat_rule(**_):
    '''Uses an existing, or creates a new, Load Balancer Incoming NAT Rule'''
    # Check if invalid external resource
    if ctx.node.properties.get('use_external_resource', False) and \
       not ctx.node.properties.get('name'):
        raise NonRecoverableError(
            '"use_external_resource" specified without a resource "name"')
    # Generate a name if it doesn't exist
    utils.generate_resource_name(InboundNATRule())
    # Get an interface to the Load Balancer
    lb_rel = utils.get_relationship_by_type(
        ctx.instance.relationships,
        constants.REL_CONTAINED_IN_LB)
    lb_name = utils.get_resource_name(lb_rel.target)
    lb_iface = LoadBalancer()
    # Get the resource config
    res_cfg = utils.get_resource_config()
    # Get the existing rules
    lb_data = lb_iface.get(lb_name)
    lb_rules = lb_data.get('properties', dict()).get(
        'inboundNatRules', list())
    # Get the Load Balancer Frontend IP Configuration
    lb_fe_ipc_name = utils.get_rel_node_name(constants.REL_CONNECTED_TO_IPC)
    lb_fe_ipc_id = utils.get_full_resource_id(
        FrontendIPConfiguration(), lb_fe_ipc_name)
    # Update the resource config
    res_cfg['frontendIPConfiguration'] = lb_fe_ipc_id
    lb_rules.append({
        'name': utils.get_resource_name(),
        'properties': res_cfg
    })
    # Update the Load Balancer with the new NAT rule
    utils.task_resource_update(
        lb_iface,
        {
            'properties': {
                'inboundNatRules': lb_rules
            }
        },
        name=lb_name)
 def __init__(self,
              resource_group=None,
              virtual_machine=None,
              api_version=constants.API_VER_COMPUTE,
              logger=None,
              _ctx=ctx):
     resource_group = resource_group or \
         utils.get_resource_group(_ctx=_ctx)
     virtual_machine = virtual_machine or \
         utils.get_rel_node_name(constants.REL_VMX_CONTAINED_IN_VM)
     Resource.__init__(
         self,
         'Virtual Machine Extension',
         '/{0}/{1}/{2}/{3}'.format(
             'resourceGroups/{0}'.format(resource_group),
             'providers/Microsoft.Compute',
             'virtualMachines/{0}'.format(virtual_machine),
             'extensions'
         ),
         api_version=api_version,
         logger=logger,
         _ctx=_ctx)