Skip to content
29 changes: 6 additions & 23 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</InterpreterId>
<InterpreterId>{1dd9c42b-5980-42ce-a2c3-46d3bf0eede4}</InterpreterId>
<InterpreterVersion>3.5</InterpreterVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
Expand All @@ -25,7 +25,12 @@
<Compile Include="azure\cli\commands\account.py" />
<Compile Include="azure\cli\commands\login.py" />
<Compile Include="azure\cli\commands\logout.py" />
<Compile Include="azure\cli\commands\network.py" />
<Compile Include="azure\cli\commands\resourcegroup.py" />
<Compile Include="azure\cli\commands\storage.py" />
<Compile Include="azure\cli\commands\vm.py" />
<Compile Include="azure\cli\commands\_auto_command.py" />
<Compile Include="azure\cli\commands\_command_creation.py" />
<Compile Include="azure\cli\commands\__init__.py" />
<Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\test_argparse.py">
Expand Down Expand Up @@ -54,28 +59,6 @@
<Folder Include="azure\cli\tests\" />
</ItemGroup>
<ItemGroup>
<Interpreter Include="..\..\Temp\burt\env27b\">
<Id>{83c20e12-84e3-4c10-a1ba-466d2b57483d}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>2.7</Version>
<Description>env27b (Python 2.7)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\..\Temp\burt\env35d\">
<Id>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>3.5</Version>
<Description>env35d (Python 3.5)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\env\">
<Id>{1dd9c42b-5980-42ce-a2c3-46d3bf0eede4}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
Expand Down
3 changes: 2 additions & 1 deletion src/azure/cli/commands/_auto_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __call__(self, poller):
try:
while not poller.done():
if self.progress_file:
print('.', end='', flush=True, file=self.progress_file)
print('.', end='', file=self.progress_file)
self.progress_file.flush()
time.sleep(self.poll_interval_ms / 1000.0)
result = poller.result()
succeeded = True
Expand Down
73 changes: 73 additions & 0 deletions src/azure/cli/commands/network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from msrest import Serializer
from .._locale import L
from azure.mgmt.network import NetworkManagementClient, NetworkManagementClientConfiguration
from azure.mgmt.network.operations import (ApplicationGatewaysOperations,
Expand All @@ -21,6 +22,7 @@

from ._command_creation import get_service_client
from ..commands._auto_command import build_operation, LongRunningOperation
from ..commands import command, description, option

def _network_client_factory():
return get_service_client(NetworkManagementClient, NetworkManagementClientConfiguration)
Expand Down Expand Up @@ -240,3 +242,74 @@ def _network_client_factory():
(VirtualNetworksOperations.list, '[VirtualNetwork]'),
(VirtualNetworksOperations.list_all, '[VirtualNetwork]'),
])

@command('network vnet create')
@description(L('Create or update a virtual network (VNet)'))
@option('--resource-group -g <resourceGroup>', L('the resource group name'), required=True)
@option('--name -n <vnetName>', L('the VNet name'), required=True)
@option('--location -l <location>', L('the VNet location'), required=True)
@option('--address-space -a <vnetAddressSpace>', L('the VNet address-space in CIDR notation or multiple address-spaces, quoted and space-seperated'), required=True)
@option('--dns-servers -d <dnsServers>', L('the VNet DNS servers, quoted and space-seperated'))
def create_update_vnet(args, unexpected): #pylint: disable=unused-argument
from azure.mgmt.network.models import AddressSpace, DhcpOptions, VirtualNetwork

resource_group = args.get('resource-group')
name = args.get('name')
location = args.get('location')
address_space = AddressSpace(address_prefixes=args.get('address-space').split())
dhcp_options = DhcpOptions(dns_servers=args.get('dns-servers').split())

vnet_settings = VirtualNetwork(location=location,
address_space=address_space,
dhcp_options=dhcp_options)

op = LongRunningOperation('Creating virtual network', 'Virtual network created')
smc = _network_client_factory()
poller = smc.virtual_networks.create_or_update(resource_group, name, vnet_settings)
return Serializer().serialize_data(op(poller), 'VirtualNetwork')

@command('network subnet create')
@description(L('Create or update a virtual network (VNet) subnet'))
@option('--resource-group -g <resourceGroup>', L('the the resource group name'), required=True)
@option('--name -n <subnetName>', L('the the subnet name'), required=True)
@option('--vnet -v <vnetName>', L('the name of the subnet vnet'), required=True)
@option('--address-prefix -a <addressPrefix>', L('the the address prefix in CIDR format'), required=True)
# TODO: setting the IPConfiguration fails, will contact owning team
#@option('--ip-name -ipn <name>', L('the IP address configuration name'))
#@option('--ip-private-address -ippa <ipAddress>', L('the private IP address'))
#@option('--ip-allocation-method -ipam <allocationMethod>', L('the IP address allocation method'))
#@option('--ip-public-address -ipa <ipAddress>', L('the public IP address'))
def create_update_subnet(args, unexpected): #pylint: disable=unused-argument
from azure.mgmt.network.models import (Subnet,
# TODO: setting the IPConfiguration fails
#IPConfiguration,
)

resource_group = args.get('resource-group')
vnet = args.get('vnet')
name = args.get('name')
address_prefix = args.get('address-prefix')
# TODO: setting the IPConfiguration fails, will contact owning team
#ip_name = args.get('ip-name')
#ip_private_address = args.get('ip-private-address')
#ip_allocation_method = args.get('ip-allocation-method')
#ip_public_address = args.get('ip-public-address')

# TODO: setting the IPConfiguration fails, will contact owning team
#ip_configuration = IPConfiguration(subnet = name,
# name = ip_name,
# private_ip_address = ip_private_address,
# private_ip_allocation_method = ip_allocation_method,
# public_ip_address = ip_public_address)

subnet_settings = Subnet(name=name,
address_prefix=address_prefix)
# TODO: setting the IPConfiguration fails, will contact owning team
#ip_configurations = [ip_configuration])

op = LongRunningOperation('Creating subnet', 'Subnet created')
smc = _network_client_factory()
poller = smc.subnets.create_or_update(resource_group, vnet, name, subnet_settings)
return Serializer().serialize_data(op(poller), 'Subnet')