def attach_ip_configuration(**_): '''Generates a usable UUID for the NIC's IP Configuration''' # Generate the IPConfiguration's name utils.generate_resource_name(FrontendIPConfiguration( load_balancer_name=utils.get_resource_name(_ctx=ctx.source), _ctx=ctx.target), _ctx=ctx.target)
def attach_ip_configuration(**_): '''Generates a usable UUID for the NIC's IP Configuration''' # Generate the IPConfiguration's name utils.generate_resource_name(IPConfiguration( network_interface_card=utils.get_resource_name(_ctx=ctx.source), _ctx=ctx.target), _ctx=ctx.target)
def attach_ip_configuration(**_): '''Generates a usable UUID for the NIC's IP Configuration''' # Generate the IPConfiguration's name utils.generate_resource_name(IPConfiguration( network_interface_card=utils.get_resource_name(_ctx=ctx.source), _ctx=ctx.target ), _ctx=ctx.target)
def attach_ip_configuration(**_): '''Generates a usable UUID for the NIC's IP Configuration''' # Generate the IPConfiguration's name utils.generate_resource_name(FrontendIPConfiguration( load_balancer_name=utils.get_resource_name(_ctx=ctx.source), _ctx=ctx.target ), _ctx=ctx.target)
def create_backend_pool(**_): '''Uses an existing, or creates a new, Load Balancer Backend Pool''' # 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(BackendAddressPool()) # 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 existing pools lb_data = lb_iface.get(lb_name) lb_pools = lb_data.get('properties', dict()).get( 'backendAddressPools', list()) lb_pools.append({'name': utils.get_resource_name()}) # Update the Load Balancer with the new pool utils.task_resource_update( lb_iface, { 'properties': { 'backendAddressPools': lb_pools } }, name=lb_name)
def create_probe(**_): '''Uses an existing, or creates a new, Load Balancer Probe''' # 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(Probe(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_NETWORK))) # 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)) # Get the existing probes lb_data = lb_iface.get(lb_name) lb_probes = lb_data.get('properties', dict()).get( 'probes', list()) lb_probes.append({ 'name': utils.get_resource_name(), 'properties': utils.get_resource_config() }) # Update the Load Balancer with the new probe utils.task_resource_update( lb_iface, { 'properties': { 'probes': lb_probes } }, name=lb_name)
def create_probe(**_): '''Uses an existing, or creates a new, Load Balancer Probe''' # 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( Probe(api_version=ctx.node.properties.get('api_version', constants.API_VER_NETWORK))) # 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)) # Get the existing probes lb_data = lb_iface.get(lb_name) lb_probes = lb_data.get('properties', dict()).get('probes', list()) lb_probes.append({ 'name': utils.get_resource_name(), 'properties': utils.get_resource_config() }) # Update the Load Balancer with the new probe utils.task_resource_update(lb_iface, {'properties': { 'probes': lb_probes }}, name=lb_name)
def create(**_): '''Uses an existing, or creates a new, Storage Account''' # Generate a resource name (if needed) utils.generate_resource_name(StorageAccount(), generator=sa_name_generator) # Create a resource (if necessary) utils.task_resource_create( StorageAccount(), { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'properties': utils.get_resource_config() })
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)
def create(**_): '''Uses an existing, or creates a new, Storage Account''' # Generate a resource name (if needed) utils.generate_resource_name( StorageAccount(), generator=sa_name_generator) # Create a resource (if necessary) utils.task_resource_create( StorageAccount(), { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'properties': utils.get_resource_config() })
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)
def create(**_): '''Uses an existing, or creates a new, Storage Account''' # Generate a resource name (if needed) utils.generate_resource_name( StorageAccount(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_STORAGE)), generator=sa_name_generator) sa_sku = ctx.node.properties.get('sku') sa_params = { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'properties': utils.get_resource_config() } if sa_sku: sa_params['sku'] = sa_sku # Create a resource (if necessary) utils.task_resource_create( StorageAccount(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_STORAGE)), sa_params)
def create(**_): '''Uses an existing, or creates a new, Storage Account''' # Generate a resource name (if needed) utils.generate_resource_name( StorageAccount(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_STORAGE)), generator=sa_name_generator) sa_sku = ctx.node.properties.get('sku') sa_params = { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'properties': utils.get_resource_config() } if sa_sku: sa_params['sku'] = sa_sku # Create a resource (if necessary) utils.task_resource_create( StorageAccount(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_STORAGE)), sa_params)
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 create(**_): '''Uses an existing, or creates a new, Virtual Machine''' # Generate a resource name (if needed) utils.generate_resource_name( VirtualMachine(), generator=vm_name_generator) res_cfg = utils.get_resource_config() or dict() # Build storage profile osdisk = build_osdisk_profile( res_cfg.get('storageProfile', dict()).get('osDisk', dict())) datadisks = build_datadisks_profile( res_cfg.get('storageProfile', dict()).get('dataDisks', list())) storage_profile = { 'osDisk': osdisk, 'dataDisks': datadisks } # Build the network profile network_profile = build_network_profile() # Build the OS profile os_family = ctx.node.properties.get('os_family', '').lower() os_profile = dict() # Set defaults for Windows installs to enable WinRM listener if os_family == 'windows' and \ not res_cfg.get('osProfile', dict()).get('windowsConfiguration'): os_profile = { 'windowsConfiguration': { # This is required for extension scripts to work 'provisionVMAgent': True, 'winRM': { 'listeners': [{ 'protocol': 'Http', 'certificateUrl': None }] } }, 'linuxConfiguration': None } elif not res_cfg.get('osProfile', dict()).get('linuxConfiguration'): os_profile = { 'linuxConfiguration': { 'disablePasswordAuthentication': False }, 'windowsConfiguration': None } # Set the computerName if it's not set already os_profile['computerName'] = \ res_cfg.get( 'osProfile', dict() ).get('computerName', utils.get_resource_name()) # Create a resource (if necessary) utils.task_resource_create( VirtualMachine(), { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'plan': ctx.node.properties.get('plan'), 'properties': utils.dict_update( utils.get_resource_config(), { 'availabilitySet': utils.get_rel_id_reference( AvailabilitySet, constants.REL_CONNECTED_TO_AS), 'networkProfile': network_profile, 'storageProfile': storage_profile, 'osProfile': os_profile } ) })
def create(args=None, **_): '''Uses an existing, or creates a new, Virtual Machine''' # Generate a resource name (if needed) utils.generate_resource_name( VirtualMachine(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_COMPUTE)), generator=vm_name_generator) res_cfg = utils.get_resource_config(args=args) or dict() # Build storage profile osdisk = build_osdisk_profile( res_cfg.get('storageProfile', dict()).get('osDisk', dict())) datadisks = build_datadisks_profile( res_cfg.get('storageProfile', dict()).get('dataDisks', list())) storage_profile = {'osDisk': osdisk, 'dataDisks': datadisks} # Build the network profile network_profile = build_network_profile() # Build the OS profile os_family = ctx.node.properties.get('os_family', '').lower() os_profile = dict() # Set defaults for Windows installs to enable WinRM listener if os_family == 'windows' and \ not res_cfg.get('osProfile', dict()).get('windowsConfiguration'): os_profile = { 'windowsConfiguration': { # This is required for extension scripts to work 'provisionVMAgent': True, 'winRM': { 'listeners': [{ 'protocol': 'Http', 'certificateUrl': None }] } }, 'linuxConfiguration': None } elif not res_cfg.get('osProfile', dict()).get('linuxConfiguration'): os_profile = { 'linuxConfiguration': { 'disablePasswordAuthentication': False }, 'windowsConfiguration': None } # Set the computerName if it's not set already os_profile['computerName'] = \ res_cfg.get( 'osProfile', dict() ).get('computerName', utils.get_resource_name()) resource_create_payload = \ { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'plan': ctx.node.properties.get('plan'), 'properties': utils.dict_update( utils.get_resource_config(args=args), { 'availabilitySet': utils.get_rel_id_reference( AvailabilitySet, constants.REL_CONNECTED_TO_AS), 'networkProfile': network_profile, 'storageProfile': storage_profile, 'osProfile': os_profile } ) } # support userdata from args. os_profile = resource_create_payload['properties']['osProfile'] userdata = _handle_userdata(os_profile.get('customData')) if userdata: ctx.logger.warn('Azure customData implementation is dependent on ' 'Virtual Machine image support.') os_profile['customData'] = base64.b64encode(userdata.encode()) # Remove customData from osProfile if empty to avoid 400 Error. elif 'customData' in resource_create_payload['properties']['osProfile']: del resource_create_payload['properties']['osProfile']['customData'] # Create a resource (if necessary) utils.task_resource_create( VirtualMachine(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_COMPUTE)), resource_create_payload)
def create(args=None, **_): '''Uses an existing, or creates a new, Virtual Machine''' # Generate a resource name (if needed) utils.generate_resource_name( VirtualMachine(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_COMPUTE)), generator=vm_name_generator) res_cfg = utils.get_resource_config(args=args) or dict() # Build storage profile osdisk = build_osdisk_profile( res_cfg.get('storageProfile', dict()).get('osDisk', dict())) datadisks = build_datadisks_profile( res_cfg.get('storageProfile', dict()).get('dataDisks', list())) storage_profile = { 'osDisk': osdisk, 'dataDisks': datadisks } # Build the network profile network_profile = build_network_profile() # Build the OS profile os_family = ctx.node.properties.get('os_family', '').lower() os_profile = dict() # Set defaults for Windows installs to enable WinRM listener if os_family == 'windows' and \ not res_cfg.get('osProfile', dict()).get('windowsConfiguration'): os_profile = { 'windowsConfiguration': { # This is required for extension scripts to work 'provisionVMAgent': True, 'winRM': { 'listeners': [{ 'protocol': 'Http', 'certificateUrl': None }] } }, 'linuxConfiguration': None } elif not res_cfg.get('osProfile', dict()).get('linuxConfiguration'): os_profile = { 'linuxConfiguration': { 'disablePasswordAuthentication': False }, 'windowsConfiguration': None } # Set the computerName if it's not set already os_profile['computerName'] = \ res_cfg.get( 'osProfile', dict() ).get('computerName', utils.get_resource_name()) resource_create_payload = \ { 'location': ctx.node.properties.get('location'), 'tags': ctx.node.properties.get('tags'), 'plan': ctx.node.properties.get('plan'), 'properties': utils.dict_update( utils.get_resource_config(args=args), { 'availabilitySet': utils.get_rel_id_reference( AvailabilitySet, constants.REL_CONNECTED_TO_AS), 'networkProfile': network_profile, 'storageProfile': storage_profile, 'osProfile': os_profile } ) } # support userdata from args. os_profile = resource_create_payload['properties']['osProfile'] userdata = _handle_userdata(os_profile.get('customData')) if userdata: ctx.logger.warn( 'Azure customData implementation is dependent on ' 'Virtual Machine image support.') os_profile['customData'] = base64.b64encode(userdata.encode()) # Remove customData from osProfile if empty to avoid 400 Error. elif 'customData' in resource_create_payload['properties']['osProfile']: del resource_create_payload['properties']['osProfile']['customData'] # Create a resource (if necessary) utils.task_resource_create(VirtualMachine( api_version=ctx.node.properties.get( 'api_version', constants.API_VER_COMPUTE)), resource_create_payload)
def create(**_): '''Uses an existing, or creates a new, Network Interface Card''' utils.generate_resource_name(NetworkInterfaceCard())
def create(**_): '''Uses an existing, or creates a new, Load Balancer''' utils.generate_resource_name(LoadBalancer())
def create(**_): '''Uses an existing, or creates a new, Load Balancer''' utils.generate_resource_name(LoadBalancer( api_version=ctx.node.properties.get('api_version', constants.API_VER_NETWORK)))
def create(**_): '''Uses an existing, or creates a new, Network Interface Card''' utils.generate_resource_name( NetworkInterfaceCard(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_NETWORK)))
def create(**_): '''Uses an existing, or creates a new, Network Interface Card''' utils.generate_resource_name(NetworkInterfaceCard( api_version=ctx.node.properties.get('api_version', constants.API_VER_NETWORK)))
def create(**_): '''Uses an existing, or creates a new, Load Balancer''' utils.generate_resource_name( LoadBalancer(api_version=ctx.node.properties.get( 'api_version', constants.API_VER_NETWORK)))
def create(**_): '''Uses an existing, or creates a new, Network Interface Card''' utils.generate_resource_name(NetworkInterfaceCard())