def create_public_ip(**_): public_ip_name = utils.set_resource_name(_get_public_ip_name, 'Public IP', constants.PUBLIC_IP_KEY, constants.EXISTING_PUBLIC_IP_NAME, constants.PUBLIC_IP_PREFIX) if public_ip_name is None: # Using an existing public ip, so don't create anything return headers, location, subscription_id = auth.get_credentials() resource_group_name = ctx.instance.runtime_properties[constants.RESOURCE_GROUP_KEY] ctx.instance.runtime_properties[constants.PUBLIC_IP_KEY] = public_ip_name check_public_ip_url = constants.azure_url+'/subscriptions/'+subscription_id+'/resourceGroups/'+resource_group_name+'/providers/microsoft.network/publicIPAddresses/'+public_ip_name+'?api-version='+constants.api_version create_public_ip_url = constants.azure_url+'/subscriptions/'+subscription_id+'/resourceGroups/'+resource_group_name+'/providers/microsoft.network/publicIPAddresses/'+public_ip_name+'?api-version='+constants.api_version public_ip_params = _get_public_ip_params(location, public_ip_name) utils.check_or_create_resource(headers, public_ip_name, public_ip_params, check_public_ip_url, create_public_ip_url, 'public_ip') ctx.logger.info("{0} is {1}".format(constants.PUBLIC_IP_KEY, public_ip_name))
def create_vnet(**_): vnet_name = utils.set_resource_name(_get_vnet_name, 'VNET', constants.VNET_KEY, constants.EXISTING_VNET_KEY, constants.VNET_PREFIX) if vnet_name is None: # Using an existing VNET, so don't create anything return headers, location, subscription_id = auth.get_credentials() resource_group_name = ctx.instance.runtime_properties[constants.RESOURCE_GROUP_KEY] if constants.VNET_KEY in ctx.instance.runtime_properties: current_subnet_name = ctx.instance.runtime_properties[constants.SUBNET_KEY] else: ctx.instance.runtime_properties[constants.VNET_KEY] = vnet_name current_subnet_name = constants.SUBNET_PREFIX+utils.random_suffix_generator() ctx.instance.runtime_properties[constants.SUBNET_KEY] = current_subnet_name check_vnet_url = constants.azure_url+'/subscriptions/'+subscription_id+'/resourceGroups/'+resource_group_name+'/providers/microsoft.network/virtualNetworks/'+vnet_name+'?api-version='+constants.api_version create_vnet_url = constants.azure_url+'/subscriptions/'+subscription_id+'/resourceGroups/'+resource_group_name+'/providers/microsoft.network/virtualNetworks/'+vnet_name+'?api-version='+constants.api_version vnet_params = json.dumps({"name": vnet_name, "location": location, "properties": {"addressSpace": {"addressPrefixes": constants.vnet_address_prefixes},"subnets": [{"name": current_subnet_name, "properties": {"addressPrefix": constants.address_prefix}}]}}) utils.check_or_create_resource(headers, vnet_name, vnet_params, check_vnet_url, create_vnet_url, 'VNET') ctx.logger.info("{0} is {1}".format(constants.VNET_KEY, vnet_name))
def create_nic(**_): if constants.USE_EXTERNAL_RESOURCE in ctx.node.properties and ctx.node.properties[constants.USE_EXTERNAL_RESOURCE]: if constants.EXISTING_NIC_KEY in ctx.node.properties: existing_nic_name = ctx.node.properties[constants.EXISTING_NIC_KEY] if existing_nic_name: nic_exists = _get_nic_name(existing_nic_name) if not nic_exists: raise NonRecoverableError("NIC {0} doesn't exist your Azure account".format(existing_nic_name)) else: raise NonRecoverableError("The value of '{0}' in the input, is empty".format(constants.EXISTING_NIC_KEY)) else: raise NonRecoverableError("'{0}' was specified, but '{1}' doesn't exist in the input".format(constants.USE_EXTERNAL_RESOURCE, constants.EXISTING_NIC_KEY)) curr_nic_key = _get_nic_key() ctx.instance.runtime_properties[curr_nic_key] = ctx.node.properties[constants.EXISTING_NIC_KEY] return headers, location, subscription_id = auth.get_credentials() resource_group_name = ctx.instance.runtime_properties[constants.RESOURCE_GROUP_KEY] vnet_name = ctx.instance.runtime_properties[constants.VNET_KEY] current_subnet_name = ctx.instance.runtime_properties[constants.SUBNET_KEY] if constants.NIC_KEY in ctx.instance.runtime_properties: nic_name = ctx.instance.runtime_properties[constants.NIC_KEY] else: random_suffix_value = utils.random_suffix_generator() nic_name = constants.NIC_PREFIX+random_suffix_value curr_nic_key = _get_nic_key() ctx.instance.runtime_properties[curr_nic_key] = nic_name ctx.logger.info("Creating new network interface card: {0}".format(nic_name)) network_str, nic_params = _get_nic_params(current_subnet_name, location, resource_group_name, subscription_id, vnet_name) check_nic_url = constants.azure_url+network_str+"/networkInterfaces/"+nic_name+"?api-version="+constants.api_version create_nic_url = constants.azure_url+network_str+"/networkInterfaces/"+nic_name+"?api-version="+constants.api_version utils.check_or_create_resource(headers, vnet_name, nic_params, check_nic_url, create_nic_url, 'NIC', True) set_nic_private_ip()